Compare commits

..

No commits in common. "fc56ddda340bf325a3e4b204173f6938fdd55c91" and "1033d2977d0ea1a6bf8aac49b52fb6d1644eb4e5" have entirely different histories.

6 changed files with 546 additions and 325 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}/deployment.tests/bin/Debug/net8.0/deployment.tests.dll", "program": "${workspaceFolder}/deploy-test/bin/Debug/net8.0/deploy-test.dll",
"args": [], "args": [],
"cwd": "${workspaceFolder}/deployment.tests", "cwd": "${workspaceFolder}/deploy-test",
// 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}/deployment.tests/deployment.tests.csproj", "${workspaceFolder}/deploy-test/deploy-test.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}/deployment.tests/deployment.tests.csproj", "${workspaceFolder}/deploy-test/deploy-test.csproj",
"/property:GenerateFullPaths=true", "/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary;ForceNoAlign" "/consoleloggerparameters:NoSummary;ForceNoAlign"
], ],
@ -33,7 +33,7 @@
"watch", "watch",
"run", "run",
"--project", "--project",
"${workspaceFolder}/deployment.tests/deployment.tests.csproj" "${workspaceFolder}/deploy-test/deploy-test.csproj"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
} }

View File

@ -0,0 +1,134 @@
using System;
using System.Dynamic;
using System.Reflection;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
[assembly: InternalsVisibleTo("deployment.tests")]
namespace greyn.Deployment
{
public static class ConfigurationBootstrapper
{
private const string confpath = "appsettings.json";
public static T Load<T>() where T : new()
{
if (File.Exists("appsettings.json"))
{
/* "aaaahhh this is the most abstract and reflective thing in the goddamn world aaaahhhhh next you'll make an ECS on a dynamic aaaahhh"
* Ok, yes. I share these fears. but.
* this way we can read a *very* arbitrary configuration file.
* some random external file's configuration values is a good reason to aim for very high flexibility, imo
* if the configuration expects new values we write them in,
* if you left other junk for whatever reason, we don't delete them.
*/
var actualConfig = JsonConvert.DeserializeObject<ExpandoObject>(File.ReadAllText(confpath)) ?? new ExpandoObject();
var toReturn = new T();
populateExpando(toReturn, ref actualConfig);
File.WriteAllText(confpath, JsonConvert.SerializeObject(actualConfig, Formatting.Indented));
readFromExpando(ref toReturn, actualConfig);
return toReturn;
}
else
{
var toReturn = new T();
File.WriteAllText(confpath, JsonConvert.SerializeObject(toReturn));
return toReturn;
}
}
//TODO: make private but get tests to cooperate
public 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;
}
var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)fromFile;
foreach (var property in config.GetType().GetProperties())
{
if (dictionaryFromExpandoFromFile.TryGetValue(property.Name, out object? value))
{
if (value != null)
{
if (property.PropertyType.GetMembers() == null)
{
var childProperty = (ExpandoObject)property.GetValue(fromFile);
populateExpando(property.GetValue(config), ref childProperty);
property.SetValue(fromFile, childProperty);
}
}
}
else
{
fromFile.TryAdd(property.Name, property.GetValue(config));
}
}
}
public static void readFromExpando<T>(ref T config, ExpandoObject readFromFile)
{
//TODO: read from Expando
}
// private static T sync<T>(ref T config, ref ExpandoObject readFromFile)
// {
// var fieldsFoundThisLevel = new List<string>();
// if(config == null)
// {
// //TODO: it's entirely possible this is null.
// throw new ArgumentNullException();
// }
// if(readFromFile == null)
// {
// //TODO: it's entirely possible this is null.
// throw new ArgumentNullException();
// }
// var readUnExpandoed = (IDictionary<string, object?>)readFromFile;
// //if it's present on what was read
// //set it on Config
// //if it's not found on what was read, or type is different
// foreach (var prop in config.GetType().GetProperties())
// {
// fieldsFoundThisLevel.Add(prop.Name);
// if(readUnExpandoed.TryGetValue(prop.Name, out object? valueFromFile)) //so a configuration file can *set* a value *to null*
// {
// if(valueFromFile != null)
// {
// var defaultConfigValue = prop.GetValue(config);
// if (defaultConfigValue != null)
// {
// //expandofy, since we objectified it.
// var expandoFromFile = new ExpandoObject();
// var dictionaryFromExpandoFromFile = (IDictionary<string, object?>)expandoFromFile;
// foreach (var property in valueFromFile.GetType().GetProperties())
// dictionaryFromExpandoFromFile.Add(property.Name, property.GetValue(valueFromFile));
// expandoFromFile = (ExpandoObject)dictionaryFromExpandoFromFile;
// //dive in, repeat
// sync(ref defaultConfigValue, ref expandoFromFile);
// //we've now Sync'd expandoFromFile and defaultConfigValue
// prop.SetValue(readFromFile, expandoFromFile);
// prop.SetValue(config, expandoFromFile);
// }
// }
// }
// else
// {
// readFromFile.TryAdd(prop.Name, prop.GetValue(config));
// }
// }
// }
}
}

View File

@ -1,71 +0,0 @@
using System;
using System.Dynamic;
using System.Reflection;
using System.Runtime.CompilerServices;
using Newtonsoft.Json;
[assembly: InternalsVisibleTo("deployment.tests")]
namespace greyn.Deployment
{
public static class Configurator<T> where T : new()
{
private const string confpath = "appsettings.json";
private static FileSystemWatcher appsettingsWatcher = new FileSystemWatcher(".");
public static event EventHandler Changed;
public static event System.IO.ErrorEventHandler Error;
private static T config;
public static T Load()
{
if (File.Exists(confpath))
{
/*
* if the configuration expects new values we write them in.
* if you left other junk for whatever reason, get rekt
*/
config = JsonConvert.DeserializeObject<T>(File.ReadAllText(confpath)) ?? new T();
}
else
{
config = new T();
}
File.WriteAllText(confpath, JsonConvert.SerializeObject(config, Formatting.Indented));
appsettingsWatcher.Filter = confpath;
appsettingsWatcher.NotifyFilter = NotifyFilters.LastWrite
| NotifyFilters.Security
| NotifyFilters.Size;
appsettingsWatcher.Changed += internalOnChanged;
appsettingsWatcher.Created += internalOnChanged;
appsettingsWatcher.Deleted += internalOnChanged;
appsettingsWatcher.Renamed += internalOnChanged;
appsettingsWatcher.Error += Error;
appsettingsWatcher.EnableRaisingEvents = true;
return config;
}
internal static void internalOnChanged(object sender, FileSystemEventArgs e)
{
appsettingsWatcher.EnableRaisingEvents = false;
Load();
Changed(sender, new ConfigChangedEventArgs(){NewConfig = config});
}
//I would like to just pudate the values on our held reference, but we'd have to update each value by reflection.
//2lazy.
public class ConfigChangedEventArgs : EventArgs
{
public T NewConfig;
}
}
}

View File

@ -4,8 +4,6 @@
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>
<IsPackable>true</IsPackable>
<Version>0.0.1</Version>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
@ -15,4 +13,5 @@
<InternalsVisibleTo Include="deployment.tests" /> <InternalsVisibleTo Include="deployment.tests" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -5,7 +5,6 @@ using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Globalization; using System.Globalization;
using Newtonsoft.Json.Converters;
namespace deployment.tests; namespace deployment.tests;
@ -34,20 +33,20 @@ public class ConfigTests
aValueType: 94.298, aValueType: 94.298,
aValueTypeButNotAField: 9241, aValueTypeButNotAField: 9241,
anEnumerableType: anEnumerableType:
{ [
""test3"": 420.71, {""test3"": 420.71},
""test4"": 420.72 {""test4"": 420.72}
} ]
}, },
subtyped2: subtyped2:
{ {
aValueType: 95.298, aValueType: 95.298,
aValueTypeButNotAField: 9242, aValueTypeButNotAField: 9242,
anEnumerableType: anEnumerableType:
{ [
""test5"": 420.73, {""test5"": 420.73},
""test6"": 420.74 {""test6"": 420.74}
} ]
} }
}"; }";
private const string EmptyConfiguration = "{}"; private const string EmptyConfiguration = "{}";
@ -57,261 +56,421 @@ public class ConfigTests
}"; }";
#endregion #endregion
[TearDown] private ExpandoObject parse(string confstr)
public void TearDown()
{ {
if(File.Exists("appsettings.json")) return JsonConvert.DeserializeObject<ExpandoObject>(confstr) ?? new ExpandoObject();
File.Delete("appsettings.json");
} }
/*
[Test] [Test]
public void load_doesnt_explode() public void parseworks()
{ {
File.WriteAllText("appsettings.json", PerfectConfiguration); Assert.IsNotNull(parse(PerfectConfiguration));
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load(); }
[Test]
public void parseworksasexpected()
{
var expandoed = parse(PerfectConfiguration);
Assert.IsNotNull(expandoed);
var casted = (IDictionary<string, object?>)expandoed;
Assert.IsNotNull(casted);
//Console.WriteLine(JsonConvert.SerializeObject(casted, Formatting.Indented));
}
#region jokes
[Test]
public void fuckit_werealreadytestingthetest_letstestthattest()
{
parseworks();
Assert.Pass(); Assert.Pass();
} }
*/
[Test] [Test]
public void load_loads() public void more_tests_more_good()
{ {
File.WriteAllText("appsettings.json", PerfectConfiguration); fuckit_werealreadytestingthetest_letstestthattest();
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load(); Assert.Pass();
Assert.AreEqual(796.651f, conf.aValueTypeButNotAField);
Assert.AreEqual("I've decided", conf.aField);
Assert.AreEqual(94.298, conf.subtyped.aValueType);
Assert.AreEqual(9241, conf.subtyped.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual( 420.71, conf.subtyped.anEnumerableType["test3"]);
Assert.AreEqual( 420.72, conf.subtyped.anEnumerableType["test4"]);
Assert.IsNotNull(conf.subtyped2);
}
/*
[Test]
public void load_acceptsnullasvalue()
{
File.WriteAllText("appsettings.json", @"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType: null
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load();
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(796.651f, conf.aValueTypeButNotAField);
Assert.AreEqual("I've decided", conf.aField);
Assert.AreEqual(94.298, conf.subtyped.aValueType);
Assert.AreEqual(9241, conf.subtyped.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped);
Assert.IsNull(conf.subtyped.anEnumerableType);
Assert.IsNotNull(conf.subtyped2);
Assert.AreEqual(95.298, conf.subtyped2.aValueType);
Assert.AreEqual(9242, conf.subtyped2.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped2.anEnumerableType);
Assert.AreEqual( 420.73, conf.subtyped2.anEnumerableType["test5"]);
Assert.AreEqual( 420.74, conf.subtyped2.anEnumerableType["test6"]);
} }
[Test] [Test]
public void load_acceptsnull_forparenttype() public void what_do_you_mean_a_bug_escaped_tests()
{ {
File.WriteAllText("appsettings.json", @"{ more_tests_more_good();
aValueTypeButNotAField: 796.651, Assert.Pass();
aField: ""I've decided"",
subtyped: null,
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load();
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(796.651f, conf.aValueTypeButNotAField);
Assert.AreEqual("I've decided", conf.aField);
Assert.IsNull(conf.subtyped);
Assert.IsNotNull(conf.subtyped2);
Assert.AreEqual(95.298, conf.subtyped2.aValueType);
Assert.AreEqual(9242, conf.subtyped2.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped2.anEnumerableType);
Assert.AreEqual( 420.73, conf.subtyped2.anEnumerableType["test5"]);
Assert.AreEqual( 420.74, conf.subtyped2.anEnumerableType["test6"]);
} }
[Test]
public void load_usesdefaultfornullablemissing()
{
File.WriteAllText("appsettings.json", @"{
aValueTypeButNotAField: 796.651,
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
{
""test3"": 420.71,
""test4"": 420.72
}
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load();
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(796.651f, conf.aValueTypeButNotAField);
Assert.AreEqual("hi there, hello", conf.aField);
Assert.AreEqual(94.298, conf.subtyped.aValueType);
Assert.AreEqual(9241, conf.subtyped.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual( 420.71, conf.subtyped.anEnumerableType["test3"]);
Assert.AreEqual( 420.72, conf.subtyped.anEnumerableType["test4"]);
Assert.IsNotNull(conf.subtyped2);
}
[Test]
public void load_usesdefaultfornonnullablemissing()
{
File.WriteAllText("appsettings.json", @"{
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
{
""test3"": 420.71,
""test4"": 420.72
}
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load();
System.Threading.Thread.Sleep(1000);
Assert.AreEqual(156.697f, conf.aValueTypeButNotAField);
Assert.AreEqual("I've decided", conf.aField);
Assert.AreEqual(94.298, conf.subtyped.aValueType);
Assert.AreEqual(9241, conf.subtyped.aValueTypeButNotAField);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual( 420.71, conf.subtyped.anEnumerableType["test3"]);
Assert.AreEqual( 420.72, conf.subtyped.anEnumerableType["test4"]);
Assert.IsNotNull(conf.subtyped2);
}
*/
[Test] [Test]
public void live_reload() public void vibecheck()
{ {
File.WriteAllText("appsettings.json", @"{ Assert.NotZero(new Random().Next(0, 2));
aField: ""I've decided"", }
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
{
""test3"": 420.71,
""test4"": 420.72
}
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
var conf = greyn.Deployment.Configurator<AConfigurationType>.Load(); [Test]
System.Threading.Thread.Sleep(1000); public void populateExpando_doesnt_explode()
{
var toReturn = new AConfigurationType();
var actualConfig = parse(PerfectConfiguration);
greyn.Deployment.ConfigurationBootstrapper.populateExpando(toReturn, ref actualConfig);
Assert.Pass();
}
#endregion
Assert.AreEqual(94.298, conf.subtyped.aValueType); [Test]
public void populateExpando_getsmissing_property()
var wait= true; {
greyn.Deployment.Configurator<AConfigurationType>.Changed += (sender, e) => { var actualConfig = parse(@"{
conf = (e as Configurator<AConfigurationType>.ConfigChangedEventArgs).NewConfig; aField: ""I've decided"",
wait = false; subtyped:
};
File.WriteAllText("appsettings.json", @"{
aField: ""I've decided"",
subtyped:
{
aValueType: 94.301,
aValueTypeButNotAField: 9241,
anEnumerableType:
{
""test3"": 420.71,
""test4"": 420.72
}
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
{
""test5"": 420.73,
""test6"": 420.74
}
}
}");
while(wait)
{ {
System.Threading.Thread.Sleep(1000); aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
} }
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aValueTypeButNotAField"]);
Assert.Pass();
}
Assert.AreEqual(94.301, conf.subtyped.aValueType); [Test]
public void populateExpando_getsmissing_field()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["aField"]);
Assert.Pass();
}
[Test]
public void populateExpando_getsmissing_subobject()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Console.WriteLine(casted["subtyped"]);
Assert.Pass();
}
[Test]
public void populateExpando_getsmissing_subobject_field()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped:
{
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
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"]);
Assert.Pass();
}
[Test]
public void populateExpando_getsmissing_subobject_property()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
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"]);
Assert.Pass();
}
[Test]
public void populateExpando_getsmissing_subobject_enumerable()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
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"]);
Assert.Pass();
}
[Test]
public void populateExpando_doesntoverridenullednullable()
{
var actualConfig = parse(@"{
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped: null,
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNull(casted["subtyped"]);
}
[Test]
public void populateExpando_doesntremoveextras()
{
var actualConfig = parse(@"{
hiImHereToo: ""sup"",
aValueTypeButNotAField: 796.651,
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
greyn.Deployment.ConfigurationBootstrapper.populateExpando(new AConfigurationType(), ref actualConfig);
var casted = (IDictionary<string, object?>)actualConfig;
Assert.IsNotNull(casted["hiImHereToo"]);
}
[Test]
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"]);
Assert.Pass();
}
[Test]
public void readfromExpando_doesnt_explode()
{
var toReturn = new AConfigurationType();
var actualConfig = parse(PerfectConfiguration);
greyn.Deployment.ConfigurationBootstrapper.readFromExpando(ref toReturn, actualConfig);
Assert.Pass();
}
[Test]
public void readfromExpando_does()
{
var readConfig = parse(PerfectConfiguration);
var conf = new AConfigurationType();
greyn.Deployment.ConfigurationBootstrapper.readFromExpando(ref conf, readConfig);
Assert.AreEqual(conf.aValueTypeButNotAField, 796.651);
Assert.AreEqual(conf.aField, "I've decided");
Assert.AreEqual(conf.subtyped.aValueType, 94.298);
Assert.AreEqual(conf.subtyped.aValueTypeButNotAField, 9241);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual(conf.subtyped.anEnumerableType["test3"], 420.71);
Assert.AreEqual(conf.subtyped.anEnumerableType["test4"], 420.72);
Assert.IsNotNull(conf.subtyped2);
}
[Test]
public void readfromExpando_acceptsnull()
{
var readConfig = parse(PerfectConfiguration);
var conf = new AConfigurationType();
greyn.Deployment.ConfigurationBootstrapper.readFromExpando(ref conf, readConfig);
Assert.AreEqual(conf.aValueTypeButNotAField, 796.651);
Assert.AreEqual(conf.aField, "I've decided");
Assert.AreEqual(conf.subtyped.aValueType, 94.298);
Assert.AreEqual(conf.subtyped.aValueTypeButNotAField, 9241);
Assert.IsNotNull(conf.subtyped);
Assert.IsNull(conf.subtyped.anEnumerableType);
Assert.IsNotNull(conf.subtyped2);
Assert.AreEqual(conf.subtyped2.aValueType, 95.298);
Assert.AreEqual(conf.subtyped2.aValueTypeButNotAField, 9242);
Assert.IsNotNull(conf.subtyped2.anEnumerableType);
Assert.AreEqual(conf.subtyped2.anEnumerableType["test5"], 420.73);
Assert.AreEqual(conf.subtyped2.anEnumerableType["test6"], 420.74);
}
[Test]
public void readfromExpando_usesdefaultfornullablemissing()
{
var readConfig = parse(@"{
aValueTypeButNotAField: 796.651,
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
var conf = new AConfigurationType();
greyn.Deployment.ConfigurationBootstrapper.readFromExpando(ref conf, readConfig);
Assert.AreEqual(conf.aValueTypeButNotAField, 796.651);
Assert.AreEqual(conf.aField, "hi there, hello");
Assert.AreEqual(conf.subtyped.aValueType, 94.298);
Assert.AreEqual(conf.subtyped.aValueTypeButNotAField, 9241);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual(conf.subtyped.anEnumerableType["test3"], 420.71);
Assert.AreEqual(conf.subtyped.anEnumerableType["test4"], 420.72);
Assert.IsNotNull(conf.subtyped2);
}
[Test]
public void readfromExpando_usesdefaultfornonnullablemissing()
{
var readConfig = parse(@"{
aField: ""I've decided"",
subtyped:
{
aValueType: 94.298,
aValueTypeButNotAField: 9241,
anEnumerableType:
[
{""test3"": 420.71},
{""test4"": 420.72}
]
},
subtyped2:
{
aValueType: 95.298,
aValueTypeButNotAField: 9242,
anEnumerableType:
[
{""test5"": 420.73},
{""test6"": 420.74}
]
}
}");
var conf = new AConfigurationType();
greyn.Deployment.ConfigurationBootstrapper.readFromExpando(ref conf, readConfig);
Assert.AreEqual(conf.aValueTypeButNotAField, 156.697f);
Assert.AreEqual(conf.aField, "I've decided");
Assert.AreEqual(conf.subtyped.aValueType, 94.298);
Assert.AreEqual(conf.subtyped.aValueTypeButNotAField, 9241);
Assert.IsNotNull(conf.subtyped.anEnumerableType);
Assert.AreEqual(conf.subtyped.anEnumerableType["test3"], 420.71);
Assert.AreEqual(conf.subtyped.anEnumerableType["test4"], 420.72);
Assert.IsNotNull(conf.subtyped2);
} }
} }