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", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path. // 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": [], "args": [],
"cwd": "${workspaceFolder}/deploy-test", "cwd": "${workspaceFolder}/deployment.tests",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole", "console": "internalConsole",
"stopAtEntry": false "stopAtEntry": false

6
.vscode/tasks.json vendored
View File

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

View File

@ -24,7 +24,7 @@ namespace greyn.Deployment
*/ */
var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject(); var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject();
var toReturn = new T(); var toReturn = new T();
populateExpando(toReturn, ref actualConfig); PopulateExpando(toReturn, ref actualConfig);
File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented)); File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented));
readFromExpando(ref toReturn, actualConfig); readFromExpando(ref toReturn, actualConfig);
@ -39,43 +39,71 @@ namespace greyn.Deployment
} }
} }
//TODO: make private but get tests to cooperate //TODO: make private but get tests to cooperate... I think that's a c# limitation
public static void populateExpando<T>(T config, ref ExpandoObject fromFile) internal static void PopulateExpando<T>(T config, ref ExpandoObject fromFile)
{ {
if (config == null) return; if (config == null) return;
if (fromFile == null) if (fromFile == null)
{ {
var expandoPopulated = new ExpandoObject(); fromFile = 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;
} }
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile; 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) continue;
}
if(memberInfo.MemberType != MemberTypes.Field && memberInfo.MemberType != MemberTypes.Property)
{
continue;
}
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
{
if (valueFromDict != null)
{ {
if (property.PropertyType.GetMembers() == null) switch (memberInfo.MemberType)
{ {
var childProperty = (ExpandoObject)property.GetValue(fromFile); case MemberTypes.Field:
populateExpando(property.GetValue(config), ref childProperty); var asField = (FieldInfo)memberInfo;
property.SetValue(fromFile, childProperty); 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 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 //TODO: read from Expando
} }

View File

@ -108,7 +108,7 @@ public class ConfigTests
{ {
var toReturn = new AConfigurationType(); var toReturn = new AConfigurationType();
var actualConfig = parse(PerfectConfiguration); var actualConfig = parse(PerfectConfiguration);
greyn.Deployment.ConfigurationBootstrapper.populateExpando(toReturn, ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(toReturn, ref actualConfig);
Assert.Pass(); Assert.Pass();
} }
#endregion #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; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aValueTypeButNotAField"]); Console.WriteLine(casted["aValueTypeButNotAField"]);
Assert.Pass(); 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; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aField"]); Console.WriteLine(casted["aField"]);
Assert.Pass(); 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; var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["subtyped"]); Console.WriteLine(casted["subtyped"]);
Assert.Pass(); 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 casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueType"]); 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 casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]); 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 casted = (IDictionary<string, object?>)actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["anEnumerableType"]); 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; var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNull(casted["subtyped"]); 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; var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNotNull(casted["hiImHereToo"]); Assert.IsNotNull(casted["hiImHereToo"]);
} }
@ -348,10 +349,11 @@ public class ConfigTests
public void populateExpando_populatesblank() public void populateExpando_populatesblank()
{ {
var actualConfig = parse("{}"); var actualConfig = parse("{}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig); greyn.Deployment.ConfigurationBootstrapper.PopulateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig; dynamic casted = actualConfig;
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"]; Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
Console.WriteLine(casted.subtyped.aValueTypeButNotAField);
Assert.Pass(); Assert.Pass();
} }
[Test] [Test]