コード例 #1
0
        public void MapToNotVisibleInterfaceThrows()
        {
            var dto = new Dto
            {
                Id             = 1,
                Name           = "Test",
                UnmappedSource = "Lorem ipsum"
            };

            var ex = Should.Throw <CompileException>(() => dto.Adapt <INotVisibleInterface>());

            ex.InnerException.ShouldBeOfType <InvalidOperationException>();
            ex.InnerException.Message.ShouldContain("not accessible", "Correct InvalidOperationException must be thrown.");
        }
コード例 #2
0
        public void TestDest()
        {
            var dto = new Dto
            {
                Id    = "Id",
                Prop1 = "Prop1",
                Prop2 = "Prop2",
                Prop3 = "Prop3"
            };
            var poco = dto.Adapt <Poco>();

            poco.Prop1.ShouldBeNull();
            poco.Prop2.ShouldBe(dto.Prop2);
            poco.Prop3.ShouldBeNull();
        }
コード例 #3
0
        public void MapToReadOnlyInterface()
        {
            var dto = new Dto
            {
                Id             = 1,
                Name           = "Test",
                UnmappedSource = "Lorem ipsum"
            };

            var idto = dto.Adapt <IReadOnlyInterface>();

            idto.ShouldNotBeNull();
            idto.ShouldSatisfyAllConditions(
                () => idto.Id.ShouldBe(dto.Id),
                () => idto.Name.ShouldBe(dto.Name)
                );
        }
コード例 #4
0
        public void TestNestedSources()
        {
            TypeAdapterConfig <Dto, Poco> .NewConfig()
            .Map(dest => dest, src => src.Details);

            var dto = new Dto
            {
                Name    = "foo",
                Details = new SubDto {
                    Extras = "bar"
                }
            };
            var poco = dto.Adapt <Poco>();

            poco.Name.ShouldBe(dto.Name);
            poco.Extras.ShouldBe(dto.Details.Extras);
        }
コード例 #5
0
        public void MapToInterfaceWithMethods()
        {
            var dto = new Dto
            {
                Id             = 1,
                Name           = "Test",
                UnmappedSource = "Lorem ipsum"
            };

            IInterfaceWithMethods idto = dto.Adapt <IInterfaceWithMethods>();

            idto.ShouldNotBeNull();
            idto.ShouldSatisfyAllConditions(
                () => idto.Id.ShouldBe(dto.Id),
                () => idto.Name.ShouldBe(dto.Name),
                () => Should.Throw <NotImplementedException>(() => idto.DoSomething())
                );
        }