public void CreateValidObject(string value) { var collection = new NameValueCollection { {"TestConfigWithAnnotations.Int", value}, }; collection.CreateObject<TestConfigWithAnnotations>(); }
public void CreateComplexObject() { var collection = new NameValueCollection { {"TestConfig.Test.Int", "3"}, {"TestConfig.ListOfInt[0]", "4"}, {"TestConfig.ListOfInt[1]", "5"}, {"TestConfig.ListOfTestConfig[2].Int", "6"}, {"TestConfig.ListOfTestConfig[2].String", "Arg"}, {"TestConfig.ListOfTestConfig[1].Int", "7"}, {"TestConfig.MapOfInt[Hello]", "8"}, {"TestConfig.MapOfInt[World]", "9"}, }; var result = collection.CreateObject<TestConfig>(); Assert.NotNull(result); Assert.NotNull(result.Test); Assert.Equal(3, result.Test.Int); Assert.NotNull(result.ListOfInt); Assert.Equal(2, result.ListOfInt.Count); Assert.Equal(4, result.ListOfInt[0]); Assert.Equal(5, result.ListOfInt[1]); Assert.NotNull(result.ListOfTestConfig); Assert.Equal(2, result.ListOfTestConfig.Count); Assert.NotNull(result.ListOfTestConfig[0]); Assert.Equal(7, result.ListOfTestConfig[0].Int); Assert.NotNull(result.ListOfTestConfig[1]); Assert.Equal(6, result.ListOfTestConfig[1].Int); Assert.Equal("Arg", result.ListOfTestConfig[1].String); Assert.NotNull(result.MapOfInt); Assert.Equal(2, result.MapOfInt.Count); Assert.Equal(8, result.MapOfInt["Hello"]); Assert.Equal(9, result.MapOfInt["World"]); }
public void CreateObjectDictionary() { var collection = new NameValueCollection { {"A[A].Int", "1"}, {"Something", "Else"}, {"A[BB].String", "Hello"}, {"A[CCC].Enum", "Goodnight"}, }; var result = collection.CreateObject<Dictionary<string, TestConfig>>("A"); Assert.NotNull(result); Assert.Equal(3, result.Count); Assert.Equal(1, result["A"].Int); Assert.Equal("Hello", result["BB"].String); Assert.Equal(TestEnum.Goodnight, result["CCC"].Enum); }
public void CreateObjectList() { var collection = new NameValueCollection { {"Something", "Else"}, {"TestConfig.ListOfTestConfig[2].Int", "6"}, {"TestConfig.ListOfTestConfig[2].String", "Arg"}, {"TestConfig.ListOfTestConfig[1].Int", "7"}, }; var result = collection.CreateObject<TestConfig>(); Assert.NotNull(result); Assert.NotNull(result.ListOfTestConfig); Assert.Equal(2, result.ListOfTestConfig.Count); Assert.NotNull(result.ListOfTestConfig[0]); Assert.Equal(7, result.ListOfTestConfig[0].Int); Assert.NotNull(result.ListOfTestConfig[1]); Assert.Equal(6, result.ListOfTestConfig[1].Int); Assert.Equal("Arg", result.ListOfTestConfig[1].String); }
public void CreateInvalidObjectWithoutValidation() { var collection = new NameValueCollection { {"TestConfigWithAnnotations.Int", "42"}, {"TestConfigWithAnnotations.IsEnabled", "false"}, }; collection.CreateObject<TestConfigWithAnnotations>(); }
public void CreateInvalidObject(string value) { var collection = new NameValueCollection { {"TestConfigWithAnnotations.Int", value}, }; Assert.Throws<ValidationException>( () => { collection.CreateObject<TestConfigWithAnnotations>(); }); }
public void CreateIntList() { var collection = new NameValueCollection { {"A[1]", "1"}, {"A[2]", "2"}, {"Something", "Else"}, {"A[4]", "4"}, }; var result = collection.CreateObject<List<int>>("A"); Assert.NotNull(result); Assert.Equal(3, result.Count); Assert.Equal(1, result[0]); Assert.Equal(2, result[1]); Assert.Equal(4, result[2]); }
public void CreateIntDictionary() { var collection = new NameValueCollection { {"A[A]", "1"}, {"Something", "Else"}, {"A[BB]", "22"}, {"A[CCC]", "333"}, }; var result = collection.CreateObject<Dictionary<string, int>>("A"); Assert.NotNull(result); Assert.Equal(3, result.Count); Assert.Equal(1, result["A"]); Assert.Equal(22, result["BB"]); Assert.Equal(333, result["CCC"]); }
public void CreateInt() { var collection = new NameValueCollection { {"A", "1"}, }; var result = collection.CreateObject<int>("A"); Assert.Equal(1, result); }