Exemple #1
0
        public async Task GetByNameAsyncReturnsCompanyId()
        {
            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 companyIdDb = repository.AllAsNoTracking().Where(c => c.Name == "Авангард ЕООД").Select(c => c.Id).FirstOrDefault();

            var companyId = await companiesService.GetByNameAsync("Авангард ЕООД");

            Assert.Equal(companyIdDb, companyId);
        }