public async Task AddWallMaterialTask()
        {
            var wallMaterial = WallMaterial.Create("Кирпич", true).Value;
            await _uow.WallMaterialRepository.AddAsync(wallMaterial);

            await _uow.SaveChangesAsync();

            var wallMaterials = await _uow.WallMaterialRepository.ListAsync();

            wallMaterials.Count().Should().Be(1);
        }
Exemplo n.º 2
0
        public static void Register()
        {
            if (Mapper != null)
            {
                throw new InvalidOperationException("Метод регистрации AutoMapper не может быть вызванн повторно");
            }

            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <EfHouse, House>()
                .ForMember(dest => dest.Year, opt => opt.MapFrom(src => src.Year))
                .ForMember(dest => dest.MetroStation, opt => opt.MapFrom(src => src.MetroStation))
                .ForMember(dest => dest.Address, opt => opt.MapFrom(src => src.Address))
                .ForMember(dest => dest.WallMaterial, opt => opt.MapFrom(src => src.WallMaterial))
                .ReverseMap();

                cfg.CreateMap <EfWallMaterial, WallMaterial>()
                .ConstructUsing(src => WallMaterial.Create(src.Name, src.IsShared).Value)
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.IsShared, opt => opt.MapFrom(src => src.IsShared));
                cfg.CreateMap <WallMaterial, EfWallMaterial>()
                .ConstructUsing(src => new EfWallMaterial {
                    Name = src.Name, IsShared = src.IsShared
                })
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.IsShared, opt => opt.MapFrom(src => src.IsShared))
                .ForMember(dest => dest.Houses, opt => opt.Ignore());



                //cfg.CreateMap<EfWallMaterial, WallMaterial>()
                //    .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                //    .ForMember(dest => dest.IsShared, opt => opt.MapFrom(src => src.IsShared));
                //cfg.CreateMap<WallMaterial, EfWallMaterial>()
                //    .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                //    .ForMember(dest => dest.IsShared, opt => opt.MapFrom(src => src.IsShared))
                //    .ForMember(dest => dest.Houses, opt => opt.Ignore());

                cfg.CreateMap <EfCompany, Company>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.CompanyDetails, opt => opt.MapFrom(src => src.CompanyDetails))
                .ForMember(dest => dest.GetHouses, opt => opt.MapFrom(src => src.Houses));
                cfg.CreateMap <Company, EfCompany>()
                .ForMember(dest => dest.Name, opt => opt.MapFrom(src => src.Name))
                .ForMember(dest => dest.CompanyDetails, opt => opt.MapFrom(src => src.CompanyDetails))
                .ForMember(dest => dest.Houses, opt => opt.MapFrom(src => src.GetHouses));
            });

            Mapper = config.CreateMapper();
        }
        public async Task AddWallMaterialsTest()
        {
            var wallMaterials = new List <WallMaterial>
            {
                WallMaterial.Create("Кирпич", true).Value,
                WallMaterial.Create("Бетон", true).Value,
                WallMaterial.Create("Дерево", true).Value
            };
            await _uow.WallMaterialRepository.AddRangeAsync(wallMaterials);

            await _uow.SaveChangesAsync();

            var listWm = (await _uow.WallMaterialRepository.ListAsync()).ToList();
            var count  = listWm.Count;

            count.Should().Be(3);
        }