public void Test() { const string @string = "My String foo"; const string present = "World"; var nested = new Nested { Foo = "Foo1", Bar = -15 }; var prefix = "Hello"; var array = new[] { " Mickey", "Mouse " }; var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string> { { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.String)), @string }, { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalPresent)), present }, { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Foo)), nested.Foo }, { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalNestedPresent), nameof(Nested.Bar)), nested.Bar.ToString() }, { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "1"), array[0] }, { SettingsLoader.GetSettingKey(prefix, nameof(OptionalSettings.OptionalArrayPresent), "2"), array[1] } })); var setting = settingsLoader.Create <OptionalSettings>(prefix); Assert.That(setting, Is.Not.Null); Assert.That(setting.String, Is.EqualTo(@string)); Assert.That(setting.OptionalMissing, Is.Null); Assert.That(setting.OptionalPresent, Is.EqualTo(present)); Assert.That(setting.OptionalNestedMissing, Is.Null); Assert.That(setting.OptionalNestedPresent, Is.DeepEqualTo(nested)); Assert.That(setting.OptionalArrayMissing, Is.Null); Assert.That(setting.OptionalArrayPresent, Is.DeepEqualTo(array)); }
public void ShouldHandleQuotedStrings(string text) { var udmf = $"namespace = \"{text}\";"; var mapData = Parse(udmf); Assert.That(mapData.NameSpace, Is.EqualTo(text)); }
public void ListLoadTest() { var settings = SettingsLoader.Create <ListSettings>(); // List Assert.That(settings.MySimpleListProperty, Is.DeepEqualTo( new List <string> { "Foo 1", "Foo 2" })); Assert.That(settings.MyListProperty, Is.DeepEqualTo( new List <Nested> { new Nested { Foo = "Foo 1", Bar = 421 }, new Nested { Foo = "Foo 2", Bar = 422 }, })); Assert.That(settings.LostNumbersList, Is.EqualTo( new[] { 4, 8, 15, 16, 23, 42 })); }
public void ShouldReadCreatedWadFile() { var fileInfo = new FileInfo(Path.GetTempFileName()); try { var map = DemoMap.Create(); var wadWriter = new WadWriter(); wadWriter.Append("MAP01", map); wadWriter.SaveTo(fileInfo.FullName); using (var wadReader = WadReader.Read(fileInfo.FullName)) { Assert.That(wadReader.Directory.Length, Is.EqualTo(3), "Did not return correct count."); Assert.That( wadReader.Directory.Select(l => l.Name).ToArray(), Is.EquivalentTo(new[] { new LumpName("MAP01"), new LumpName("TEXTMAP"), new LumpName("ENDMAP"), }), "Did not return correct lump names."); var roundTripped = MapData.LoadFrom(wadReader.GetTextmapStream("MAP01")); Assert.That(roundTripped, Is.DeepEqualTo(map)); } } finally { if (fileInfo.Exists) { fileInfo.Delete(); } } }
public void DirectSplitListArrayLoadTest() { var numbers = SettingsLoader.CreateList <int>("LostNumbers", new[] { ',' }); Assert.That(numbers, Is.EqualTo( new List <int> { 4, 8, 15, 16, 23, 42 })); }
public void SettingNameLoadTest() { var settings = SettingsLoader.Create <SimpleSettingsWithSettingName>(); //Simple Assert.That(settings.Enum2, Is.EqualTo(BindingFlags.NonPublic | BindingFlags.Static)); Assert.That(settings.String1, Is.EqualTo("Hello world")); Assert.That(settings.DateTime3, Is.EqualTo(new DateTime(2004, 07, 17, 9, 0, 0, DateTimeKind.Local))); Assert.That(settings.TimeSpan4, Is.EqualTo(new TimeSpan(11, 22, 33, 44, 560))); Assert.That(settings.Uri5, Is.EqualTo(new Uri("Http://hello.eu"))); Assert.That(settings.Guid6, Is.EqualTo(Guid.Parse("DCFA0942-0BEC-43E4-8D77-57BA63C7BF7B"))); }
public void SimpleLoadTest() { var settings = SettingsLoader.Create <SimpleSettings>(); //Simple Assert.That(settings.Enum, Is.EqualTo(BindingFlags.NonPublic | BindingFlags.Static)); Assert.That(settings.String, Is.EqualTo("Hello world")); Assert.That(settings.DateTime, Is.EqualTo(new DateTime(2004, 07, 17, 9, 0, 0, DateTimeKind.Local))); Assert.That(settings.TimeSpan, Is.EqualTo(new TimeSpan(11, 22, 33, 44, 560))); Assert.That(settings.Type, Is.EqualTo(typeof(System.Data.IDbConnection))); Assert.That(settings.Uri, Is.EqualTo(new Uri("Http://hello.eu"))); Assert.That(settings.Guid, Is.EqualTo(Guid.Parse("DCFA0942-0BEC-43E4-8D77-57BA63C7BF7B"))); Assert.That(settings.IPAddress, Is.EqualTo(IPAddress.Parse("192.168.0.42"))); }
public void DefaultLoadTest() { var settings = SettingsLoader.Create <DefaultSettings>(); // Defaults Assert.That(settings.DefaultString, Is.EqualTo("Default Hello World")); Assert.That(settings.DefaultEnum, Is.EqualTo(BindingFlags.Instance | BindingFlags.Public)); Assert.That(settings.DefaultDateTime, Is.EqualTo(new DateTime(1966, 6, 11, 13, 34, 56, DateTimeKind.Local).AddMilliseconds(789))); Assert.That(settings.DefaultTimeSpan, Is.EqualTo(new TimeSpan(1, 2, 3, 4))); Assert.That(settings.DefaultType, Is.EqualTo(typeof(AccessViolationException))); Assert.That(settings.DefaultUri, Is.EqualTo(new Uri("https://foo.bar"))); Assert.That(settings.DefaultGuid, Is.EqualTo(Guid.Parse("EE58EE2B-4CE6-44A4-8773-EC4E283146EB"))); Assert.That(settings.DefaultIp, Is.EqualTo(IPAddress.Parse("10.42.42.42"))); Assert.That(settings.DefaultArray, Is.EqualTo(new[] { "foo", "bar" })); }
public void Test() { const string @string = "My String"; var prefix = "Hello"; var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string> { { SettingsLoader.GetSettingKey(prefix, nameof(IgnoreSettings.String)), @string }, })); var setting = settingsLoader.Create <IgnoreSettings>(prefix); Assert.That(setting, Is.Not.Null); Assert.That(setting.String, Is.EqualTo(@string)); Assert.That(setting.Ignored, Is.Null); Assert.That(setting.NestedIgnored, Is.Null); Assert.That(setting.TimeSpanIgnored, Is.Null); }
public void CustomDateTimeTest() { var key = "Christmas"; // Pick any type to use as test type var date = new DateTime(2017, 12, 24); var value = date.ToString("dd/MM/yyyy"); // Setup dictionary value provider var settingsLoader = new SettingsLoader(new DictionaryValueProvider(new Dictionary <string, string> { { key, value } })); settingsLoader.AddTypeConverter <DateTime>(x => DateTime.Parse(x, System.Globalization.CultureInfo.GetCultureInfo("da-DK"))); var result = settingsLoader.Create <DateTime>(key); Assert.That(result, Is.Not.Null); Assert.That(result, Is.EqualTo(date)); }
public void ArrayLoadTest() { var settings = SettingsLoader.Create <ArraySettings>(); // Array Assert.That(settings.MySimpleArrayProperty, Is.EquivalentTo( new[] { "Foo Primary", "Foo 1", "Foo 2" })); Assert.That(settings.MyNumericArrayProperty, Is.EqualTo( new decimal[] { 1, 2, 3, 4 })); Assert.That(settings.MyArrayProperty, Is.DeepEqualTo( new[] { new Nested { Foo = "Foo Primary", Bar = 420 }, new Nested { Foo = "Foo 1", Bar = 421 }, new Nested { Foo = "Foo 2", Bar = 422 }, }) .WithComparisonConfig(new ComparisonConfig() { IgnoreCollectionOrder = true })); Assert.That(settings.LostNumbersArray, Is.EqualTo( new[] { 4, 8, 15, 16, 23, 42 })); }
public void GetValueTest() { var result = SettingsLoader.Create <string>("Foo"); Assert.That(result, Is.EqualTo("Foo from database")); }