public void TestGetParser__InnerParseMap()
        {
            IValueParser parser3 = Substitute.For <IValueParser>();

            innerParseMap.GetParser(typeof(DummyClass3)).Returns(parser3);

            Assert.Same(parser3, parseMap.GetParser(typeof(DummyClass3)));
        }
예제 #2
0
        public INodeDataMapper BuildMapper()
        {
            if (!CanBuild)
            {
                throw new InvalidOperationException();
            }

            return(new ValueScalarMapper(nodeDataName, parseMap.GetParser(fieldType)));
        }
예제 #3
0
        public INodeDataMapper BuildMapper()
        {
            if (!CanBuild)
            {
                throw new InvalidOperationException();
            }

            return(new ValueListMapper(nodeDataName, parseMap.GetParser(elementType)));
        }
예제 #4
0
        public void TestBuildMapper()
        {
            IValueParseMap           parseMap = Substitute.For <IValueParseMap>();
            ValueScalarMapperBuilder builder  = new ValueScalarMapperBuilder("foo", typeof(DummyClass), parseMap);

            IValueParser parser = Substitute.For <IValueParser>();

            parseMap.CanParse(typeof(DummyClass)).Returns(true);
            parseMap.GetParser(typeof(DummyClass)).Returns(parser);

            ValueScalarMapper mapper = Assert.IsType <ValueScalarMapper>(builder.BuildMapper());

            parseMap.Received().GetParser(typeof(DummyClass));

            Assert.Equal("foo", mapper.name);
            Assert.Same(parser, mapper.parser);
        }
예제 #5
0
        public void TestNew__UseParser()
        {
            Type type1 = typeof(DummyClass1);
            Type type2 = typeof(DummyClass2);
            Type type3 = typeof(DummyClass3);
            Type type4 = typeof(DummyClass4);

            IValueParser parser1 = Substitute.For <IValueParser>();
            IValueParser parser2 = Substitute.For <IValueParser>();
            IValueParser parser3 = Substitute.For <IValueParser>();

            parser1.ParseType.Returns(type1);
            parser2.ParseType.Returns(type2);

            IUseParser useParser1 = Substitute.For <IUseParser>();
            IUseParser useParser2 = Substitute.For <IUseParser>();

            useParser1.CreateParser().Returns(parser1);
            useParser2.CreateParser().Returns(parser2);

            parseMap.CanParse(type3).Returns(true);
            parseMap.CanParse(Arg.Is <Type>(y => y != type3)).Returns(false);

            parseMap.GetParser(type3).Returns(parser3);
            parseMap.When(x => x.GetParser(Arg.Is <Type>(y => y != type3))).Throw <Exception>();

            fieldWrapper.MemberInfo.GetCustomAttributes(true).Returns(new[] { useParser1, useParser2 });
            NodeDataBuilder builder2 = new NodeDataBuilder(nodeData, fieldWrapper, parseMap);

            OverrideValueParseMap newParseMap = Assert.IsType <OverrideValueParseMap>(builder2.valueParseMap);

            Assert.True(newParseMap.CanParse(type1));
            Assert.True(newParseMap.CanParse(type2));
            Assert.True(newParseMap.CanParse(type3));
            Assert.False(newParseMap.CanParse(type4));

            Assert.Same(parser1, newParseMap.GetParser(type1));
            Assert.Same(parser2, newParseMap.GetParser(type2));
            Assert.Same(parser3, newParseMap.GetParser(type3));
            Assert.Throws <Exception>(() => newParseMap.GetParser(type4));
        }
예제 #6
0
        public IValueParser GetParser(Type parseType)
        {
            parseType.ThrowIfNullArgument(nameof(parseType));

            return(overrides.FirstOrDefault(parser => parser.ParseType == parseType) ?? innerParseMap.GetParser(parseType));
        }
예제 #7
0
 public IValueParser GetParser(Type parseType)
 {
     parseType.ThrowIfNullArgument(nameof(parseType));
     return(map.GetParser(parseType));
 }
예제 #8
0
        public IValueParser GetParser(Type parseType)
        {
            parseType.ThrowIfNullArgument(nameof(parseType));

            if (overrides.FirstOrDefault(testParser => testParser.ParseType == parseType) is IValueParser parser)
            {
                return(parser);
            }

            if (parseType.IsNullableValueType())
            {
                Type valueType = parseType.GetGenericArguments()[0];
                foreach (IValueParser testParser in overrides)
                {
                    if (testParser.ParseType == valueType)
                    {
                        return(testParser);
                    }
                }
            }

            return(overrides.FirstOrDefault(testParser => testParser.ParseType == parseType) ?? innerParseMap.GetParser(parseType));
        }