Beispiel #1
0
        public void Test_TypeTypeParser_SwitchValueList_FriendName_Bad()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <Type>("PersonType", "PersonType", true, -1, "Employee", "Customer")
                                     .FinishBuilding("/PersonType:Boss");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj, "PersonType parsing failed", true);
        }
Beispiel #2
0
        public void Test_FlagsEnumParsing_Good()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <MyPets>("Pets")
                                     .FinishBuilding("/Pets:Dog,Turtle");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj);
            Assert.IsTrue(_paramObj.GetPropertyValue <MyPets>("Pets") == (MyPets.Dog | MyPets.Turtle));
        }
Beispiel #3
0
        public void Test_BasicEnumParsing_Good()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <MyColors>("Color")
                                     .FinishBuilding("/Color:Yellow");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj);
            Assert.IsTrue(_paramObj.GetPropertyValue <MyColors>("Color") == MyColors.Yellow);
        }
Beispiel #4
0
        public void Test_TypeTypeParser_SwitchValueList_ClassName_Good()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <Type>("PersonType", "PersonType", true, -1, "Employee", "Customer")
                                     .FinishBuilding("/PersonType:EmployeePersonType");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj, "PersonType parsing failed");
            Assert.IsTrue(_paramObj.GetPropertyValue <Type>("PersonType") == typeof(EmployeePersonType));
        }
Beispiel #5
0
        public void TestEnumArray_Good()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <MyColors[]>("Colors")
                                     .FinishBuilding("/Colors:Orange,Yellow");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj);
            MyColors[] _colors = _paramObj.GetPropertyValue <MyColors[]>("Colors");
            Assert.IsNotNull(_colors);
            Assert.IsTrue(_colors.Length == 2);
            Assert.IsTrue(_colors[0] == MyColors.Orange);
            Assert.IsTrue(_colors[1] == MyColors.Yellow);
        }
Beispiel #6
0
        public void TestKeyValueArray_Good()
        {
            ParamsObject _paramObj = DynamicParamsCreator
                                     .Create()
                                     .AddSwitch <KeyValuePair <string, int>[]>("NameAges")
                                     .FinishBuilding("/NameAges:Yisrael:30,Srully:10,Yitschak:40");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj);
            KeyValuePair <string, int>[] _nameAges = _paramObj.GetPropertyValue <KeyValuePair <string, int>[]>("NameAges");
            Assert.IsNotNull(_nameAges);
            Assert.IsTrue(_nameAges.Length == 3);
            Assert.IsTrue(_nameAges[1].Key == "Srully");
            Assert.IsTrue(_nameAges[1].Value == 10);
        }
        public void Test_Override_DateTimeParsing_Good()
        {
            ParamsObject _paramObj =
                DynamicParamsCreator
                .Create()
                .AddSwitch <DateTime>("Bday")
                .AddSwitch <int>("Age")
                .AddSwitch <string>("Name")
                .OverrideTypeParsers(() => new TypeParserContainer(true, new DefaultTypeContainer(), new DayFirstDashOnlyDateTimeParser()))
                .FinishBuilding("/Bday:28-11-1987", "/Age:30", "/Name:Yisrael Lax");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj);
            Assert.IsTrue(_paramObj.GetPropertyValue <DateTime>("Bday") == new DateTime(1987, 11, 28));
            Assert.IsTrue(_paramObj.GetPropertyValue <int>("Age") == 30);
            Assert.IsTrue(_paramObj.GetPropertyValue <string>("Name") == "Yisrael Lax");
        }
        public void Test_Override_DateTimeParsing_Bad()
        {
            ParamsObject _paramObj =
                DynamicParamsCreator
                .Create()
                .AddSwitch <DateTime>("Bday")
                .AddSwitch <int>("Age")
                .AddSwitch <string>("Name")
                .FinishBuilding("/Bday:28/11/1987", "/Age:30", "/Name:Yisrael Lax");

            ParamsObjectTestHelpers.AssertCheckParams(_paramObj,
                                                      "Parsing should have failed b/c incorrect DateTime format",
                                                      true,
                                                      "string was not recognized as a valid datetime");
            Assert.IsTrue(_paramObj.GetPropertyValue <DateTime>("Bday") == default(DateTime));
            Assert.IsTrue(_paramObj.GetPropertyValue <int>("Age") == 30);
            Assert.IsTrue(_paramObj.GetPropertyValue <string>("Name") == "Yisrael Lax");
        }