public void Base_Configuration_Map_Condition_Applies_To_Derived_Class() { TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig() .Map(dest => dest.Name, src => src.Name + "_Suffix", src => src.Name == "SourceName") .Compile(); TypeAdapterConfig <DerivedPoco, SimpleDto> .Clear(); var source = new DerivedPoco { Id = new Guid(), Name = "SourceName" }; var dto = TypeAdapter.Adapt <SimpleDto>(source); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBe(source.Name + "_Suffix"); var source2 = new DerivedPoco { Id = new Guid(), Name = "SourceName3" }; dto = TypeAdapter.Adapt <SimpleDto>(source2); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBeNull(); }
public void Setup() { TypeAdapterConfig <SimplePocoThatThrowsOnGet, SimpleDto> .Clear(); TypeAdapterConfig <SimplePoco, SimpleDtoThatThrowsOnSet> .Clear(); TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); }
public void Setup() { TypeAdapterConfig <SimplePocoBase, SimpleDto> .Clear(); TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); TypeAdapterConfig <SimplePoco, SimpleDtoWithoutMissingMembers> .Clear(); TypeAdapterConfig <SimpleFlattenedPoco, SimpleDto> .Clear(); }
public void Setup() { TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); TypeAdapterConfig <DerivedPoco, SimpleDto> .Clear(); TypeAdapterConfig <DerivedPoco, DerivedDto> .Clear(); TypeAdapterConfig.GlobalSettings.AllowImplicitDestinationInheritance = false; }
public void Global_Destination_Transform_Is_Applied_To_Class() { TypeAdapterConfig.GlobalSettings.Default.AddDestinationTransform((string x) => x.Trim()); TypeAdapterConfig <string, string> .Clear(); var source = new SimplePoco { Id = new Guid(), Name = "TestMethod" }; var destination = TypeAdapter.Adapt <SimpleDto>(source); destination.Name.ShouldBe("TestMethod"); }
public void Transform_Doesnt_Occur_If_None_Present() { TypeAdapterConfig <string, string> .Clear(); TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); var source = new SimplePoco { Id = new Guid(), Name = "TestMethod " }; var destination = TypeAdapter.Adapt <SimpleDto>(source); destination.Name.ShouldBe(source.Name); }
public void Can_Map_From_Null_Source_To_Non_Nullable_Target() { TypeAdapterConfig <NullablePrimitivesPoco, NonNullablePrimitivesDto> .Clear(); var poco = new NullablePrimitivesPoco { Id = Guid.NewGuid(), Name = "TestName" }; NonNullablePrimitivesDto dto = TypeAdapter.Adapt <NullablePrimitivesPoco, NonNullablePrimitivesDto>(poco); dto.Id.ShouldBe(poco.Id); dto.Name.ShouldBe(poco.Name); dto.IsImport.ShouldBeFalse(); }
public void Set_Primitive_Uri_Property_Success() { TypeAdapterConfig <SimplePoco, SimplePoco> .Clear(); TypeAdapterConfig.GlobalSettings.PrimitiveTypes.Add(typeof(Uri)); var sourceDto = new SimplePoco { Id = 1, Website = new Uri("http://example.com"), }; var targetDto = TypeAdapter.Adapt <SimplePoco, SimplePoco>(sourceDto); targetDto.Website.ShouldEqual(sourceDto.Website); }
public void Unmapped_Classes_Should_Throw() { TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true; TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); var simplePoco = new SimplePoco { Id = Guid.NewGuid(), Name = "TestName" }; var exception = Assert.Throws <InvalidOperationException>(() => TypeAdapter.Adapt <SimplePoco, SimpleDto>(simplePoco)); Console.WriteLine(exception.Message); exception.Message.ShouldContain("SimplePoco"); exception.Message.ShouldContain("SimpleDto"); }
public void Ignores_Are_Derived_From_Base_Configurations() { TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig() .Ignore(dest => dest.Name) .Compile(); TypeAdapterConfig <DerivedPoco, SimpleDto> .Clear(); var source = new DerivedPoco { Id = new Guid(), Name = "SourceName" }; var dto = TypeAdapter.Adapt <SimpleDto>(source); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBeNull(); }
public void Base_Configuration_Applies_To_Double_Derived_Class_If_No_Explicit_Configuration() { TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig() .Map(dest => dest.Name, src => src.Name + "_Suffix") .Compile(); TypeAdapterConfig <DoubleDerivedPoco, SimpleDto> .Clear(); var source = new DoubleDerivedPoco() { Id = new Guid(), Name = "SourceName" }; var dto = TypeAdapter.Adapt <SimpleDto>(source); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBe(source.Name + "_Suffix"); }
public void Base_Configuration_DestinationTransforms_Apply_To_Derived_Class() { var config = TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig(); config.AddDestinationTransform((string x) => x.Trim()); config.Compile(); TypeAdapterConfig <DerivedPoco, SimpleDto> .Clear(); var source = new DerivedPoco { Id = new Guid(), Name = "SourceName " }; var dto = TypeAdapter.Adapt <SimpleDto>(source); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBe(source.Name.Trim()); }
public void No_Primitive_Uri_Property_Should_Throw() { TypeAdapterConfig <SimplePoco, SimplePoco> .Clear(); var sourceDto = new SimplePoco { Id = 1, Website = new Uri("http://example.com"), }; var exception = Assert.Throws <InvalidOperationException>(() => TypeAdapter.Adapt <SimplePoco, SimplePoco>(sourceDto)); Console.WriteLine(exception.Message); var innerException = exception.InnerException; innerException.ShouldBeType <ArgumentNullException>(); ((ArgumentNullException)innerException).ParamName.ShouldEqual("con"); }
public void Derived_Class_Stops_At_First_Valid_Base_Configuration() { TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig() .Map(dest => dest.Name, src => src.Name + "_Suffix") .Compile(); TypeAdapterConfig <DerivedPoco, SimpleDto> .NewConfig() .Map(dest => dest.Name, src => src.Name + "_Derived") .Compile(); TypeAdapterConfig <DoubleDerivedPoco, SimpleDto> .Clear(); var source = new DoubleDerivedPoco { Id = new Guid(), Name = "SourceName" }; var dto = TypeAdapter.Adapt <SimpleDto>(source); dto.Id.ShouldBe(source.Id); dto.Name.ShouldBe(source.Name + "_Derived"); }
public void Unmapped_Classes_Should_Throw() { try { //compile first to prevent type initialize exception TypeAdapterConfig <SimplePoco, SimpleDto> .NewConfig().Compile(); TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true; TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); var simplePoco = new SimplePoco { Id = Guid.NewGuid(), Name = "TestName" }; TypeAdapter.Adapt <SimpleDto>(simplePoco); Assert.Fail(); } catch (InvalidOperationException ex) { ex.Message.ShouldContain("SimplePoco"); ex.Message.ShouldContain("SimpleDto"); } }
public void TearDown() { TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = false; TypeAdapterConfig <SimplePoco, SimpleDto> .Clear(); }
public static void Setup(TestContext context) { TypeAdapterConfig <Poco, Dto> .Clear(); }
public void Setup() { TypeAdapterConfig <Customer, CustomerDTO> .Clear(); TypeAdapterConfig <Address, AddressDTO> .Clear(); }
protected override void Reset() => TypeAdapterConfig <Customer, CustomerDto> .Clear();
protected override void Reset() => TypeAdapterConfig <Foo, Foo> .Clear();