public void TestCanParse__InnerParseMap() { innerParseMap.CanParse(typeof(DummyClass3)).Returns(true); innerParseMap.CanParse(typeof(DummyClass4)).Returns(false); Assert.True(parseMap.CanParse(typeof(DummyClass3))); Assert.False(parseMap.CanParse(typeof(DummyClass4))); }
public void TestBuildMapper__CantBuild() { IValueParseMap parseMap = Substitute.For <IValueParseMap>(); ValueScalarMapperBuilder builder = new ValueScalarMapperBuilder("foo", typeof(DummyClass), parseMap); parseMap.CanParse(typeof(DummyClass)).Returns(false); Assert.Throws <InvalidOperationException>(() => builder.BuildMapper()); }
public void TestCanBuild__False() { IValueParseMap parseMap = Substitute.For <IValueParseMap>(); ValueScalarMapperBuilder builder = new ValueScalarMapperBuilder("foo", typeof(DummyClass), parseMap); parseMap.CanParse(typeof(DummyClass)).Returns(false); Assert.False(builder.CanBuild); }
public void TestCanBuild__True() { IValueParseMap parseMap = Substitute.For <IValueParseMap>(); ValueListMapperBuilder builder = new ValueListMapperBuilder("foo", typeof(List <DummyClass>), parseMap); parseMap.CanParse(typeof(DummyClass)).Returns(true); Assert.True(builder.CanBuild); }
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 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 bool CanParse(Type parseType) { parseType.ThrowIfNullArgument(nameof(parseType)); if (overrides.Any(parser => parser.ParseType == parseType)) { return(true); } if (parseType.IsNullableValueType()) { Type valueType = parseType.GetGenericArguments()[0]; if (overrides.Any(parser => parser.ParseType == valueType)) { return(true); } } return(innerParseMap.CanParse(parseType)); }
public bool CanParse(Type parseType) { parseType.ThrowIfNullArgument(nameof(parseType)); return(overrides.Any(parser => parser.ParseType == parseType) || innerParseMap.CanParse(parseType)); }
public bool CanParse(Type parseType) { parseType.ThrowIfNullArgument(nameof(parseType)); return(map.CanParse(parseType)); }