public async Task CreateAsync_ShouldReturn_True_IfInputDataIsCorrect() { var db = this.GetDatabase(); var mapper = this.GetMapper(); var companyServiec = new CompaniesService(db, mapper); const string name = "Петров 96"; const string address = "София Младост 6"; const string bulstat = "BG063698652"; const string accountablePerson = "Ivan Metodiev"; //Act var result = await companyServiec.CreateAsync(name, address, bulstat, accountablePerson); var savedEntry = await db.Companies.FirstOrDefaultAsync(x => x.Name == "Петров 96"); //Assert result .Should() .BeTrue(); savedEntry .Should() .NotBeNull() .And .BeOfType <Company>() .And .Match <Company>(x => x.Bulstat == "BG063698652" && x.Name == "Петров 96"); }
public async Task CreateAsyncCreatesCompany() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()); var repository = new EfRepository <Company>(new ApplicationDbContext(options.Options)); var companiesService = new CompaniesService(repository); await companiesService.CreateAsync("Авангард ЕООД"); await companiesService.CreateAsync("ЕТ Саламандър"); var companyCount = repository.AllAsNoTracking().ToList().Count(); Assert.Equal(2, companyCount); }
public async Task WhenCreateCompanyThatExistInDatabase() { var companies = new List <Company>(); var mockCompanyRepo = new Mock <IDeletableEntityRepository <Company> >(); mockCompanyRepo.Setup(x => x.All()).Returns(companies.AsQueryable()); mockCompanyRepo.Setup(x => x.AddAsync(It.IsAny <Company>())).Callback( (Company company) => companies.Add(company)); var mockHotelRepo = new Mock <IDeletableEntityRepository <Hotel> >(); var service = new CompaniesService(mockCompanyRepo.Object, mockHotelRepo.Object); await service.CreateAsync("NeykovEOOD", "131071587", "0888989844", "*****@*****.**", 1, "Първи май №2", 1); await service.CreateAsync("NeykovEOOD", "131071587", "0888989844", "*****@*****.**", 1, "Първи май №2", 1); Assert.Single(companies); }