public async Task AddAsyncSucceeds() { // Arrange var options = GetTestDbContextOptions("Add_ScrapeJob_Database"); var testEntity = GenerateTestEntity(); // Act bool result; using (var context = new WaasDbContext(options)) { var testRepository = new BaseDomainService <ScrapeJob, long>(context); await testRepository.AddAsync(testEntity); result = await context.CommitAsync(); } // Assert Assert.True(result); using (var context = new WaasDbContext(options)) { var check = await context.ScrapeJobs.FindAsync(testEntity.Id); Assert.Equal(testEntity, check); } }
public async Task DeleteAsyncSucceeds() { // Arrange var options = GetTestDbContextOptions("Delete_ScrapeJob_Database"); var testEntity = GenerateTestEntity(); using (var context = new WaasDbContext(options)) { await context.AddAsync(testEntity); await context.SaveChangesAsync(); } // Act bool result; using (var context = new WaasDbContext(options)) { var testRepository = new BaseDomainService <ScrapeJob, long>(context); await testRepository.DeleteAsync(testEntity.Id); result = await context.CommitAsync(); } // Assert Assert.True(result); using (var context = new WaasDbContext(options)) { Assert.Null(await context.ScrapeJobs.FindAsync(testEntity.Id)); } }
public async Task UpdateAsyncSucceeds() { // Arrange var options = GetTestDbContextOptions("Update_ScrapeJob_Database"); var testEntity = GenerateTestEntity(); using (var context = new WaasDbContext(options)) { await context.AddAsync(testEntity); await context.SaveChangesAsync(); } // Act bool result; using (var context = new WaasDbContext(options)) { var testRepository = new BaseDomainService <ScrapeJob, long>(context); await testRepository.UpdateAsync(testEntity.Id, job => { job.Pattern = "updatedPattern"; job.Url = "updatedUrl"; job.Enabled = !testEntity.Enabled; }); result = await context.CommitAsync(); } // Assert Assert.True(result); using (var context = new WaasDbContext(options)) { var updatedEntity = await context.ScrapeJobs.FindAsync(testEntity.Id); Assert.NotEqual(testEntity.Pattern, updatedEntity.Pattern); Assert.NotEqual(testEntity.Url, updatedEntity.Url); Assert.NotEqual(testEntity.Enabled, updatedEntity.Enabled); } }