示例#1
0
        public void TestCanAdd__Null()
        {
            ValueParseMap map = new ValueParseMap();

            map.AddParser(Exemplars.DummyValueParser <string>());

            Assert.Throws <ArgumentNullException>(() => map.CanAdd(null));
        }
示例#2
0
        public void TestGetParser__Null()
        {
            ValueParseMap map = new ValueParseMap();

            map.AddParser(Exemplars.ValueParser);

            Assert.Throws <ArgumentNullException>(() => map.GetParser(null));
        }
示例#3
0
        public void TestAddParser__GetParser()
        {
            ValueParseMap map = new ValueParseMap();

            map.AddParser(Exemplars.ValueParser);

            Assert.Same(Exemplars.ValueParser, map.GetParser(typeof(string)));
        }
示例#4
0
        public void TestGetParser__NotRegistered()
        {
            ValueParseMap map = new ValueParseMap();

            map.AddParser(Exemplars.ValueParser);

            Assert.Throws <ParseTypeNotRegisteredException>(() => map.GetParser(typeof(double)));
        }
示例#5
0
        public void TestAddParser__Null()
        {
            ValueParseMap map = new ValueParseMap();

            Assert.Throws <ArgumentNullException>(() => map.AddParser <int>(null, i => i.ToString()));
            Assert.Throws <ArgumentNullException>(() => map.AddParser <int>(int.Parse, null));
            Assert.Throws <ArgumentNullException>(() => map.AddParser(null));
        }
示例#6
0
        public void TestAddParser__GetParser__Func()
        {
            ValueParseMap map = new ValueParseMap();

            map.AddParser <string>(s => $">{s}<", s => $"<{s}>");

            Assert.Equal(">abc<", map.GetParser(typeof(string)).Parse("abc"));
            Assert.Equal("<abc>", map.GetParser(typeof(string)).Format("abc"));
        }
示例#7
0
        public void TestCanAdd()
        {
            ValueParseMap map = new ValueParseMap();

            Assert.True(map.CanAdd(typeof(string)));

            map.AddParser(Exemplars.DummyValueParser <string>());

            Assert.False(map.CanAdd(typeof(string)));
        }
示例#8
0
        public void TestClone()
        {
            IValueParser parser1 = Exemplars.DummyValueParser <int>();
            IValueParser parser2 = Exemplars.DummyValueParser <bool>();
            IValueParser parser3 = Exemplars.DummyValueParser <string>();

            ValueParseMap map = new ValueParseMap();

            map.AddParser(parser1);
            map.AddParser(parser2);

            ValueParseMap clone = map.Clone();

            Assert.Same(parser1, clone.GetParser(typeof(int)));
            Assert.Same(parser2, clone.GetParser(typeof(bool)));

            clone.AddParser(parser3);

            Assert.Same(parser3, clone.GetParser(typeof(string)));
            Assert.Throws <ParseTypeNotRegisteredException>(() => map.GetParser(typeof(string)));
        }