コード例 #1
0
        public async Task GetDetailsAsyncReturnsCompanyDetails()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());

            var repository = new EfRepository <Company>(new ApplicationDbContext(options.Options));
            await repository.AddAsync(new Company { Name = "Авангард ЕООД" });

            await repository.AddAsync(new Company { Name = "ЕТ Саламандър" });

            await repository.AddAsync(new Company { Name = "Тиесто Гранд" });

            await repository.SaveChangesAsync();

            var companiesService = new CompaniesService(repository);

            var companyFromDb = repository.AllAsNoTracking().FirstOrDefault(c => c.Name == "Тиесто Гранд");

            AutoMapperConfig.RegisterMappings(typeof(DetailsCompanyViewModel).Assembly);
            var company = await companiesService.GetDetailsAsync <DetailsCompanyViewModel>(companyFromDb.Id);

            Assert.Equal(company.Name, companyFromDb.Name);
            Assert.Equal(company.Bulstat, companyFromDb.Bulstat);
            Assert.Equal(company.PhoneNumber, companyFromDb.PhoneNumber);
            Assert.Equal(company.Address, companyFromDb.Address);
        }