public void IgnoreIfPath() { TypeAdapterConfig <Poco, Dto> .NewConfig() .Map(dest => dest.Address, src => src.Child.Address) .IgnoreIf((src, dest) => src.Child.Address.Number == "100", dest => dest.Address.Location); var poco = new Poco { Id = Guid.NewGuid(), Child = new ChildPoco { Address = new Address { Number = "123", Location = "10,10" } } }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Address.Number.ShouldBe(poco.Child.Address.Number); dto.Address.Location.ShouldBe(poco.Child.Address.Location); poco.Child.Address.Number = "100"; var dto2 = poco.Adapt <Dto>(); dto2.Id.ShouldBe(poco.Id); dto2.Address.Number.ShouldBe(poco.Child.Address.Number); dto2.Address.Location.ShouldBeNull(); }
public void MapPath() { TypeAdapterConfig <Poco, Dto> .NewConfig() .Map(dest => dest.Address.Number, src => src.Child.Address.Number); TypeAdapterConfig <ChildPoco, Dto> .NewConfig() .Map(dest => dest.Address.Number, src => src.Address.Number + "test"); var poco = new Poco { Id = Guid.NewGuid(), Child = new ChildPoco { Address = new Address { Number = "123", Location = "10,10" } } }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Address.Number.ShouldBe(poco.Child.Address.Number); dto.Address.Location.ShouldBeNull(); var dto2 = poco.Child.Adapt <Dto>(); dto2.Address.Number.ShouldBe(poco.Child.Address.Number + "test"); }
public void Allow_GetType_If_Property_Is_Type() { var poco = new Poco { FirstName = "Foo", LastName = "Bar" }; var dto = poco.Adapt <Dto3>(); dto.Type.ShouldBe(typeof(Poco)); }
public void Should_Ignore_GetType() { var poco = new Poco { FirstName = "Foo", LastName = "Bar" }; var dto = poco.Adapt <Dto2>(); dto.Type.ShouldBeNull(); }
public void Should_Copy_Value_From_Get_Method() { var poco = new Poco { FirstName = "Foo", LastName = "Bar" }; var dto = poco.Adapt <Dto>(); dto.FullName.ShouldBe("Foo Bar"); }
public void MapPath_AllowNull() { TypeAdapterConfig <Poco, Dto> .NewConfig() .Map(dest => dest.Location, src => src.Child.Address.Location); var poco = new Poco { Id = Guid.NewGuid(), Child = new ChildPoco() }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Location.ShouldBeNull(); }
public void MapToConstructor_Auto() { TypeAdapterConfig <Poco, Dto> .NewConfig() .MapToConstructor(true); var poco = new Poco { Id = "A", Name = "Test", Prop = "Prop" }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Name.ShouldBe(poco.Name); dto.Age.ShouldBe(-1); dto.Prop.ShouldBe(poco.Prop); }
public void TestSource() { var poco = new Poco { Id = "Id", Prop1 = "Prop1", Prop2 = "Prop2", Prop3 = "Prop3" }; var dto = poco.Adapt <Dto>(); dto.Prop1.ShouldBeNull(); dto.Prop2.ShouldBeNull(); dto.Prop3.ShouldBe(poco.Prop3); }
public void MapToConstructor_UsingConstructorInfo() { var ctor = typeof(Dto).GetConstructor(new[] { typeof(string) }); TypeAdapterConfig <Poco, Dto> .NewConfig() .MapToConstructor(ctor); var poco = new Poco { Id = "A", Name = "Test", Prop = "Prop" }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Name.ShouldBeNull(); dto.Age.ShouldBe(0); dto.Prop.ShouldBe(poco.Prop); }
public void TestMaxDepth() { TypeAdapterConfig <Poco, Dto> .NewConfig() .MaxDepth(3); var poco = new Poco { Id = Guid.NewGuid() }; poco.Parent = poco; poco.Children = new List <Poco> { poco }; var result = poco.Adapt <Dto>(); AssertModel(result, poco, 1, 3); }
public void TestIgnore() { TypeAdapterConfig <Poco, Dto> .NewConfig() .TwoWays() .Ignore(it => it.Name); var poco = new Poco { Id = Guid.NewGuid(), Name = "test" }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Name.ShouldBeNull(); dto.Name = "bar"; var poco2 = dto.Adapt <Poco>(); poco2.Id.ShouldBe(dto.Id); poco2.Name.ShouldBeNull(); }
public void TestIgnoreMember() { TypeAdapterConfig <Poco, Dto> .NewConfig() .TwoWays() .IgnoreMember((member, side) => member.GetCustomAttribute <JsonIgnoreAttribute>() != null && side == MemberSide.Destination); var poco = new Poco { Id = Guid.NewGuid(), Name = "test" }; var dto = poco.Adapt <Dto>(); dto.Id.ShouldBe(poco.Id); dto.Name.ShouldBeNull(); dto.Name = "bar"; var poco2 = dto.Adapt <Poco>(); poco2.Id.ShouldBe(dto.Id); poco2.Name.ShouldBeNull(); }