public async Task CourtDeleteTest() { var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var townService = new CourtTownService(dbContext); await townService.CreateAsync("Rousse", "Боримечка 43"); await townService.CreateAsync("София", "Боримечка 44"); var townId = dbContext.CourtTowns.Where(x => x.Id == 1) .Select(x => x.Id) .FirstOrDefault(); var courtService = new CourtService(dbContext); await courtService.CreateAsync("Районен", townId); await courtService.CreateAsync("Окръжен", townId); var courtId = dbContext.Courts.Where(x => x.CourtType.ToString() == "Окръжен") .Select(x => x.Id).FirstOrDefault(); //Act var result = courtService.DeleteAsync(courtId); var myCourt = dbContext.Courts.Where(x => x.Id == courtId) .Select(x => x.CourtTown.TownName).FirstOrDefault(); //Assert Assert.Null(myCourt); //Assert.True(result.IsCompletedSuccessfully); }
public async Task CourtEditTest() { var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb"); var dbContext = new ApplicationDbContext(optionBuilder.Options); var townService = new CourtTownService(dbContext); await townService.CreateAsync("Rousse", "Боримечка 43"); await townService.CreateAsync("Rousse", "Боримечка 44"); var town = dbContext.CourtTowns.Where(x => x.Id == 1) .Select(x => x.Id) .FirstOrDefault(); var courtService = new CourtService(dbContext); await courtService.CreateAsync("Окръжен", town); await courtService.CreateAsync("Районен", town); var courtId = dbContext.Courts.Where(x => x.Id == 0) .Select(x => x.Id) .FirstOrDefault(); var result = courtService.EditAsync(courtId, "окръжен", 1); var courtType = await courtService.DetailsAsync(1); Assert.True(result.IsCompletedSuccessfully); // Assert.Equal("окръжен", courtType.CourtType.ToString()); Assert.NotNull(result); }
public void CourtTownCreateTest() { //Arrange var courtTown = new CourtTown { Id = 3, TownName = "Rousse3", Address = "myAddress3" }; var optionBuilder = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase("testDb"); var dbContext = new ApplicationDbContext(optionBuilder.Options); //await dbContext.CourtTowns.AddAsync(courtTown); //await dbContext.SaveChangesAsync(); var service = new CourtTownService(dbContext); //Act var result = service.CreateAsync(courtTown.TownName, courtTown.Address); var name = dbContext.CourtTowns.Where(x => x.TownName == courtTown.TownName) .Select(x => x.TownName).FirstOrDefault(); //Assert //Assert.NotNull(result); //Assert.IsType<List<CourtTownEditViewModel>>(result.Result); Assert.True(result.IsCompletedSuccessfully); Assert.Equal("Rousse3", name); //Assert.Equal("Rousse", result.Result.TownName); //Assert.Equal("myAddress", result.Result.Address); //Assert.Equal(1, result.Result.Id); }