Exemplo n.º 1
1
        public void Error_Thrown_With_Explicit_Configuration_On_Unmapped_Child_Collection()
        {
            TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;

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

            var exception = Assert.Throws <ArgumentOutOfRangeException>(() => TypeAdapter.Adapt <ParentPoco, ParentDto>(source));

            exception.Message.ShouldContain("UnmappedChildren");
        }
Exemplo n.º 2
0
        public void Fork_Setting_2()
        {
            var config = new TypeAdapterConfig();

            config.NewConfig <ParentPoco, ParentPoco>()
            .Fork(cfg => cfg.Default.PreserveReference(true));

            var grandChild = new GrandChildPoco
            {
                Id = Guid.NewGuid().ToString()
            };
            var child = new ChildPoco
            {
                GrandChildren = new List <GrandChildPoco>
                {
                    grandChild, grandChild
                }
            };
            var parent = new ParentPoco
            {
                Children = new List <ChildPoco>
                {
                    child, child
                }
            };

            var cloned = parent.Adapt <ParentPoco>(config);

            cloned.Children[0].GrandChildren[0].ShouldBeSameAs(cloned.Children[1].GrandChildren[1]);

            var childCloned = child.Adapt <ChildPoco>(config);

            childCloned.GrandChildren[0].ShouldNotBeSameAs(childCloned.GrandChildren[1]);
        }
Exemplo n.º 3
0
        public void No_Errors_Thrown_With_Default_Configuration_On_Unmapped_Child_Collection()
        {
            TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = false;
            TypeAdapterConfig<ParentPoco, ParentDto>.NewConfig().Compile();

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

            var destination = TypeAdapter.Adapt<ParentPoco, ParentDto>(source);

            destination.Name.ShouldBe("TestName");
            destination.UnmappedChildren.ShouldBeNull();
            destination.Children.Count.ShouldBe(1);
        }
Exemplo n.º 4
0
        public void Error_Thrown_With_Explicit_Configuration_On_Unmapped_Child_Collection()
        {
            try
            {
                TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;
                TypeAdapterConfig<ParentPoco, ParentDto>.NewConfig().Compile();

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

                TypeAdapter.Adapt<ParentPoco, ParentDto>(source);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                ex.Message.ShouldContain("UnmappedChildren");
            }
        }
Exemplo n.º 5
0
        public void No_Errors_Thrown_With_Default_Configuration_On_Unmapped_Child_Collection()
        {
            TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = false;

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

            var destination = TypeAdapter.Adapt <ParentPoco, ParentDto>(source);

            destination.Name.ShouldEqual("TestName");
            destination.UnmappedChildren.ShouldBeNull();
            destination.Children.Count.ShouldEqual(1);
        }
        public void Error_Thrown_With_Explicit_Configuration_On_Unmapped_Child_Collection()
        {
            try
            {
                TypeAdapterConfig.GlobalSettings.RequireDestinationMemberSource = true;
                TypeAdapterConfig <ParentPoco, ParentDto> .NewConfig().Compile();

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

                TypeAdapter.Adapt <ParentPoco, ParentDto>(source);
                Assert.Fail();
            }
            catch (ArgumentOutOfRangeException ex)
            {
                ex.Message.ShouldContain("UnmappedChildren");
            }
        }