コード例 #1
0
        public void CanAutoMapUsingCustomMapper()
        {
            var mapper = new CustomMapper();

            mapper
            .AddMap <UserEntity, UserDto>(x => new UserDto(x.Firstname + " " + x.Lastname)
            {
                Id       = x.Id,
                IsOnline = x.IsOnline,
                Username = x.Username
            });

            Mapping.SetMapper(mapper);

            FlowQuerySelection <UserDto> dtos = Query <UserEntity>()
                                                .Select()
                                                .ToMap <UserDto>();

            Assert.That(dtos.Count(), Is.EqualTo(4));

            foreach (UserDto item in dtos)
            {
                Assert.That(Usernames, Contains.Item(item.Username));
                Assert.That(Ids, Contains.Item(item.Id));
                Assert.That(Fullnames, Contains.Item(item.Fullname));
            }
        }