public void Adapter_Destination_Transform_Collection()
        {
            var config = new TypeAdapterConfig();

            config.Default.AddDestinationTransform((IReadOnlyList <ChildDto> list) => list ?? new List <ChildDto>());

            var source      = new CollectionPoco();
            var destination = source.Adapt <CollectionDto>(config);

            destination.Children.ShouldNotBeNull();
        }
        public void Adapter_Destination_Transform_CreateNewIfNull()
        {
            var config = new TypeAdapterConfig();

            config.Default.AddDestinationTransform(DestinationTransform.CreateNewIfNull);

            var source      = new CollectionPoco();
            var destination = source.Adapt <CollectionPoco>(config);

            destination.Children.Count.ShouldBe(0);
            destination.ChildDict.Count.ShouldBe(0);
            destination.Set.Count.ShouldBe(0);
        }
        public void Adapter_Destination_Transform_Collection_Generic()
        {
            var config = new TypeAdapterConfig();

            config.Default.AddDestinationTransform(DestinationTransform.EmptyCollectionIfNull);

            var source      = new CollectionPoco();
            var destination = source.Adapt <CollectionDto>(config);

            destination.Children.Count.ShouldBe(0);
            destination.Array.Length.ShouldBe(0);
            destination.MultiDimentionalArray.Length.ShouldBe(0);
            destination.ChildDict.Count.ShouldBe(0);
            destination.Set.Count.ShouldBe(0);
        }
        public void Mapped_Classes_Succeed_With_Child_Mapping()
        {
            TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;

            TypeAdapterConfig <CollectionPoco, CollectionDto> .NewConfig();

            TypeAdapterConfig <ChildPoco, ChildDto> .NewConfig();

            var collectionPoco = new CollectionPoco {
                Id = Guid.NewGuid(), Name = "TestName", Children = new List <ChildPoco>()
            };

            var collectionDto = TypeAdapter.Adapt <CollectionPoco, CollectionDto>(collectionPoco);

            collectionDto.Name.ShouldBe(collectionPoco.Name);
        }
        public void Non_Public_Destination_Collection_Setter_Is_Populated()
        {
            var poco = new CollectionPoco
            {
                Id = Guid.NewGuid(),
                Name = "TestName",
                Children = new List<ChildDto> {new ChildDto {Id = Guid.NewGuid(), Name = "TestChild"}}
            };

            CollectionDto dto = TypeAdapter.Adapt<CollectionPoco, CollectionDto>(poco);

            dto.Id.ShouldEqual(poco.Id);
            dto.Name.ShouldEqual(poco.Name);

            dto.Children.ShouldNotBeNull();
            dto.Children.Count.ShouldEqual(1);
            dto.Children[0].Id.ShouldEqual(poco.Children[0].Id);
        }
Example #6
0
        public void Non_Public_Destination_Collection_Setter_Is_Populated()
        {
            var poco = new CollectionPoco
            {
                Id       = Guid.NewGuid(),
                Name     = "TestName",
                Children = new List <ChildDto> {
                    new ChildDto {
                        Id = Guid.NewGuid(), Name = "TestChild"
                    }
                }
            };

            CollectionDto dto = TypeAdapter.Adapt <CollectionPoco, CollectionDto>(poco);

            dto.Id.ShouldBe(poco.Id);
            dto.Name.ShouldBe(poco.Name);

            dto.Children.ShouldNotBeNull();
            dto.Children.Count.ShouldBe(1);
            dto.Children[0].Id.ShouldBe(poco.Children[0].Id);
        }
        public void Mapped_Classes_Succeed_With_Child_Mapping()
        {
            TypeAdapterConfig.GlobalSettings.RequireExplicitMapping = true;

            TypeAdapterConfig<CollectionPoco, CollectionDto>.NewConfig();
            TypeAdapterConfig<ChildPoco, ChildDto>.NewConfig();

            var collectionPoco = new CollectionPoco {Id = Guid.NewGuid(), Name = "TestName", Children = new List<ChildPoco>()};

            var collectionDto = TypeAdapter.Adapt<CollectionPoco, CollectionDto>(collectionPoco);

            collectionDto.Name.ShouldBe(collectionPoco.Name);
        }