we TDD now?

This commit is contained in:
adam 2024-10-30 16:46:57 -04:00
parent 1033d2977d
commit 9f69150202
4 changed files with 76 additions and 18 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

@ -39,43 +39,99 @@ 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;
Console.WriteLine("config is not null");
Console.WriteLine($"fromfile null: {fromFile == null}");
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));
foreach (var memberInfo in config.GetType().GetMembers())
{
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
dictionaryFromExpandoPopulated.Add(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
break;
case MemberTypes.Property:
dictionaryFromExpandoPopulated.Add(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
break;
default:
break;
}
}
expandoPopulated = (ExpandoObject)dictionaryFromExpandoPopulated;
fromFile = expandoPopulated;
return;
}
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile;
foreach (var property in config.GetType().GetProperties())
foreach (var memberInfo in config.GetType().GetMembers(BindingFlags.DeclaredOnly))
{
if (dictionaryFromExpandoFromFile.TryGetValue(property.Name, out object? value))
Console.WriteLine($"checking property: {memberInfo.Name}");
if (dictionaryFromExpandoFromFile.TryGetValue(memberInfo.Name, out object? valueFromDict))
{
if (value != null)
Console.WriteLine($"dictionary has it - {valueFromDict}");
if (valueFromDict != null)
{
if (property.PropertyType.GetMembers() == null)
Console.WriteLine($"value from configuration value is not null");
switch (memberInfo.MemberType)
{
var childProperty = (ExpandoObject)property.GetValue(fromFile);
populateExpando(property.GetValue(config), ref childProperty);
property.SetValue(fromFile, childProperty);
case MemberTypes.Field:
var asField = (FieldInfo)memberInfo;
if ((asField.FieldType.GetMembers(BindingFlags.DeclaredOnly)?.Count() ?? 0) > 0)
{
Console.WriteLine($"{asField.Name} (as field) has {asField.FieldType.GetMembers(BindingFlags.DeclaredOnly) .Count()} members.");
var childMember = (ExpandoObject)dictionaryFromExpandoFromFile[asField.Name]; // (ExpandoObject)asField.GetValue(fromFile);
populateExpando(asField.GetValue(config), ref childMember);
asField.SetValue(fromFile, childMember);
}
break;
case MemberTypes.Property:
var asProperty = (PropertyInfo)memberInfo;
if ((asProperty.PropertyType.GetMembers(BindingFlags.DeclaredOnly)?.Count() ?? 0) > 0)
{
Console.WriteLine($"{asProperty.Name} (as property) has {asProperty.PropertyType.GetMembers(BindingFlags.DeclaredOnly) .Count()} members.");
var childMember = (ExpandoObject)dictionaryFromExpandoFromFile[asProperty.Name]; // (ExpandoObject)asProperty.GetValue(fromFile);
populateExpando(asProperty.GetValue(config), ref childMember);
asProperty.SetValue(fromFile, childMember);
}
break;
default:
Console.WriteLine($"membertype unhanlded. {memberInfo.MemberType}");
break;
}
}
}
else
{
fromFile.TryAdd(property.Name, property.GetValue(config));
Console.WriteLine($"dictionary didn't have it. so let's add to fromFile");
switch (memberInfo.MemberType)
{
case MemberTypes.Field:
var addTry = fromFile.TryAdd(memberInfo.Name, ((FieldInfo)memberInfo).GetValue(config));
Console.WriteLine($"ostensibly, succeeded? {addTry}");
break;
case MemberTypes.Property:
var addTry2 = fromFile.TryAdd(memberInfo.Name, ((PropertyInfo)memberInfo).GetValue(config));
Console.WriteLine($"ostensibly, succeeded? {addTry2}");
break;
default:
break;
}
}
Console.WriteLine($"{memberInfo.Name} handled");
}
}
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

@ -140,6 +140,7 @@ public class ConfigTests
}
}");
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();
@ -350,6 +351,7 @@ public class ConfigTests
var actualConfig = parse("{}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
Assert.Pass();