Esempio n. 1
0
        public void TestKeyValueOnlyParsing_Good()
        {
            ParamsObject _paramObj =
                DynamicParamsCreator
                .Create()
                .OverrideTypeParsers(() => new TypeParserContainer(false, new KeyValueParser(), new ObjectParser()))
                .AddSwitch <KeyValuePair <string, int> >("NameAge")
                .AddSwitch <string>("FirstName")
                .FinishBuilding("/NameAge:Yizzy:30");

            TypeParserContainer _container = _paramObj.GetPropertyValue <TypeParserContainer>("TypeParser");

            Assert.IsTrue(_container.TypeParsers.Count() == 2, "Only 2 type parsers should have existed");

            bool _parseErr = false;

            try
            {
                _paramObj.CheckParams();
            }
            catch { _parseErr = true; }
            Assert.IsFalse(_parseErr, "String and int parsers were explicated, so this should NOT have failed");

            KeyValuePair <string, int>?_namgeAge = _paramObj.GetPropertyValue <KeyValuePair <string, int> >("NameAge");

            Assert.IsNotNull(_namgeAge);
            Assert.IsTrue(_namgeAge.Value.Key == "Yizzy");
            Assert.IsTrue(_namgeAge.Value.Value == 30);
        }
Esempio n. 2
0
        public void TestKeyValueOnlyParsing_Bad()
        {
            ParamsObject _paramObj =
                DynamicParamsCreator
                .Create()
                .OverrideTypeParsers(() => new TypeParserContainer(false, new KeyValueParser()))
                .AddSwitch <KeyValuePair <string, int> >("NameAge")
                .AddSwitch <string>("FirstName")
                .FinishBuilding("/NameAge:Yizzy:30");

            TypeParserContainer _container = _paramObj.GetPropertyValue <TypeParserContainer>("TypeParser");

            Assert.IsTrue(_container.TypeParsers.Count() == 1, "More than 1 type parser should not have existed");

            bool _parseErr = false;

            try
            {
                _paramObj.CheckParams();
            }
            catch { _parseErr = true; }
            Assert.IsTrue(_parseErr, "String and int parsers were not explicated, so this should have failed");
            KeyValuePair <string, int> _namgeAge =
                _paramObj.GetPropertyValue <KeyValuePair <string, int> >("NameAge");

            Assert.IsNull(_namgeAge.Key, "Name key should have been null");
            Assert.IsTrue(_namgeAge.Value == 0, "Age value should have been null");
        }