Beispiel #1
0
        public void DomainEntity_To_ConsoleEntity()
        {
            // Arrange...
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Sex, string>().ConvertUsing <SexEnumToStringTypeConverter>();
                cfg.CreateMap <DateTime, string>().ConvertUsing <DateTimeToStringTypeConverter>();
                cfg.CreateMap <DomainEntity, ConsoleEntity>();
            });

            configuration.AssertConfigurationIsValid();
            var          sut          = configuration.CreateMapper();
            DomainEntity domainEntity = new DomainEntity("John Doe")
            {
                Id      = Guid.NewGuid(),
                Title   = Title.Mr,
                Sex     = Sex.Male,
                Created = new DateTime(1, 2, 3, 4, 5, 6)
            };

            // Act...
            ConsoleEntity consoleEntity = sut.Map <DomainEntity, ConsoleEntity>(domainEntity);

            // Assert...
            consoleEntity.Should().NotBeNull();
            consoleEntity.Id.Should().Be(domainEntity.Id);
            consoleEntity.Name.Should().Be(domainEntity.Name);
            consoleEntity.Title.Should().Be("Mr");
            consoleEntity.Sex.Should().Be("Male");
            consoleEntity.Created.Should().Be("0001-02-03 04:05:06");
        }