Compare commits

..

5 Commits

Author SHA1 Message Date
dad0f9b376 fix name as requested 2024-10-30 17:43:40 -04:00
675bb9824f strip out debugging lines
because dotnet test doesn't give me a good way to hit a breakpoint grumble grumble.
or maybe it does but idk it.
2024-10-30 17:42:52 -04:00
85c58cafc0 populate expando seems to 2024-10-30 17:35:00 -04:00
77af5e4f2b you don't have to fuck around with cast-back nonsense; expandoobject *is* a dictionary. 2024-10-30 17:21:00 -04:00
9f69150202 we TDD now? 2024-10-30 16:46:57 -04:00
4 changed files with 69 additions and 39 deletions

4
.vscode/launch.json vendored
View File

@ -10,9 +10,9 @@
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/deploy-test/bin/Debug/net8.0/deploy-test.dll",
"program": "${workspaceFolder}/deployment.tests/bin/Debug/net8.0/deployment.tests.dll",
"args": [],
"cwd": "${workspaceFolder}/deploy-test",
"cwd": "${workspaceFolder}/deployment.tests",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
"stopAtEntry": false

6
.vscode/tasks.json vendored
View File

@ -7,7 +7,7 @@
"type": "process",
"args": [
"build",
"${workspaceFolder}/deploy-test/deploy-test.csproj",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
@ -19,7 +19,7 @@
"type": "process",
"args": [
"publish",
"${workspaceFolder}/deploy-test/deploy-test.csproj",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj",
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign"
],
@ -33,7 +33,7 @@
"watch",
"run",
"--project",
"${workspaceFolder}/deploy-test/deploy-test.csproj"
"${workspaceFolder}/deployment.tests/deployment.tests.csproj"
],
"problemMatcher": "$msCompile"
}

View File

@ -24,7 +24,7 @@ namespace greyn.Deployment
*/
var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject();
var toReturn = new T();
populateExpando(toReturn, ref actualConfig);
PopulateExpando(toReturn, ref actualConfig);
File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented));
readFromExpando(ref toReturn, actualConfig);
@ -39,43 +39,71 @@ namespace greyn.Deployment
}
}
//TODO: make private but get tests to cooperate
public static void populateExpando<T>(T config, ref ExpandoObject fromFile)
//TODO: make private but get tests to cooperate... I think that's a c# limitation
internal static void PopulateExpando<T>(T config, ref ExpandoObject fromFile)
{
if (config == null) return;
if (fromFile == null)
{
var expandoPopulated = new ExpandoObject();
var dictionaryFromExpandoPopulated = (IDictionary<string, object?>)expandoPopulated;
foreach (var property in config.GetType().GetProperties())
dictionaryFromExpandoPopulated.Add(property.Name, property.GetValue(config));
expandoPopulated = (ExpandoObject)dictionaryFromExpandoPopulated;
fromFile = expandoPopulated;
return;
fromFile = new ExpandoObject();
}
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile;
foreach (var property in config.GetType().GetProperties())
foreach (var memberInfo in config.GetType().GetMembers())
{
if (dictionaryFromExpandoFromFile.TryGetValue(property.Name, out object? value))
if(memberInfo.DeclaringType == typeof(System.Object))
{
if (value != null)
{
if (property.PropertyType.GetMembers() == null)
{
var childProperty = (ExpandoObject)property.GetValue(fromFile);
populateExpando(property.GetValue(config), ref childProperty);
property.SetValue(fromFile, childProperty);
continue;
}
if(memberInfo.MemberType != MemberTypes.Field && memberInfo.MemberType != MemberTypes.Property)
{
continue;
}
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
{
if (valueFromDict != null)
{
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
var asField = (FieldInfo)memberInfo;
if (dictionaryFromExpandoFromFile[asField.Name] is ExpandoObject childMemberField)
{
PopulateExpando(asField.GetValue(config), ref childMemberField);
}
break;
case MemberTypes.Property:
var asProperty = (PropertyInfo)memberInfo;
if (dictionaryFromExpandoFromFile[asProperty.Name] is ExpandoObject childMemberProperty)
{
PopulateExpando(asProperty.GetValue(config), ref childMemberProperty);
}
break;
default:
break;
}
}
}
else
{
fromFile.TryAdd(property.Name, property.GetValue(config));
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
fromFile.TryAdd(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
break;
case MemberTypes.Property:
fromFile.TryAdd(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
break;
default:
break;
}
}
}
}
public static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
internal static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
{
//TODO: read from Expando
}

View File

@ -108,7 +108,7 @@ public class ConfigTests
{
var toReturn = new AConfigurationType();
var actualConfig = parse(PerfectConfiguration);
greyn.Deployment.ConfigurationBootstrapper.populateExpando(toReturn, ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(toReturn, ref actualConfig);
Assert.Pass();
}
#endregion
@ -139,7 +139,8 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
Console.WriteLine("survived populate expando");
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aValueTypeButNotAField"]);
Assert.Pass();
@ -171,7 +172,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aField"]);
Assert.Pass();
@ -193,7 +194,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["subtyped"]);
Assert.Pass();
@ -224,7 +225,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueType"]);
@ -256,7 +257,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
@ -284,7 +285,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["anEnumerableType"]);
@ -308,7 +309,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNull(casted["subtyped"]);
}
@ -340,7 +341,7 @@ public class ConfigTests
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNotNull(casted["hiImHereToo"]);
}
@ -348,10 +349,11 @@ public class ConfigTests
public void populateExpando_populatesblank()
{
var actualConfig = parse("{}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
dynamic casted = actualConfig;
Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
Console.WriteLine(casted.subtyped.aValueTypeButNotAField);
Assert.Pass();
}
[Test]