public void TestGetParser__InnerParseMap() { IValueParser parser3 = Substitute.For <IValueParser>(); innerParseMap.GetParser(typeof(DummyClass3)).Returns(parser3); Assert.Same(parser3, parseMap.GetParser(typeof(DummyClass3))); }
public INodeDataMapper BuildMapper() { if (!CanBuild) { throw new InvalidOperationException(); } return(new ValueScalarMapper(nodeDataName, parseMap.GetParser(fieldType))); }
public INodeDataMapper BuildMapper() { if (!CanBuild) { throw new InvalidOperationException(); } return(new ValueListMapper(nodeDataName, parseMap.GetParser(elementType))); }
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); }
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)); }
public IValueParser GetParser(Type parseType) { parseType.ThrowIfNullArgument(nameof(parseType)); return(overrides.FirstOrDefault(parser => parser.ParseType == parseType) ?? innerParseMap.GetParser(parseType)); }
public IValueParser GetParser(Type parseType) { parseType.ThrowIfNullArgument(nameof(parseType)); return(map.GetParser(parseType)); }
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)); }