we TDD now?
This commit is contained in:
parent
1033d2977d
commit
9f69150202
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -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
6
.vscode/tasks.json
vendored
@ -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"
|
||||||
}
|
}
|
||||||
|
@ -39,43 +39,99 @@ 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;
|
||||||
|
Console.WriteLine("config is not null");
|
||||||
|
|
||||||
|
Console.WriteLine($"fromfile null: {fromFile == null}");
|
||||||
if (fromFile == null)
|
if (fromFile == null)
|
||||||
{
|
{
|
||||||
var expandoPopulated = new ExpandoObject();
|
var expandoPopulated = new ExpandoObject();
|
||||||
var dictionaryFromExpandoPopulated = (IDictionary<string, object?>)expandoPopulated;
|
var dictionaryFromExpandoPopulated = (IDictionary<string, object?>)expandoPopulated;
|
||||||
foreach (var property in config.GetType().GetProperties())
|
foreach (var memberInfo in config.GetType().GetMembers())
|
||||||
dictionaryFromExpandoPopulated.Add(property.Name, property.GetValue(config));
|
{
|
||||||
|
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;
|
expandoPopulated = (ExpandoObject)dictionaryFromExpandoPopulated;
|
||||||
fromFile = expandoPopulated;
|
fromFile = expandoPopulated;
|
||||||
return;
|
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(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);
|
case MemberTypes.Field:
|
||||||
populateExpando(property.GetValue(config), ref childProperty);
|
var asField = (FieldInfo)memberInfo;
|
||||||
property.SetValue(fromFile, childProperty);
|
|
||||||
|
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
|
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
|
//TODO: read from Expando
|
||||||
}
|
}
|
||||||
|
@ -140,6 +140,7 @@ 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();
|
||||||
@ -350,6 +351,7 @@ public class ConfigTests
|
|||||||
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;
|
var casted = (IDictionary<string, object?>)actualConfig;
|
||||||
|
Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
|
||||||
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
var subtypeCasted = (IDictionary<string, object?>)casted["subtyped"];
|
||||||
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
|
Console.WriteLine(subtypeCasted["aValueTypeButNotAField"]);
|
||||||
Assert.Pass();
|
Assert.Pass();
|
||||||
|
Loading…
Reference in New Issue
Block a user