public async Task IncrementDownloadCountWithOne() { ulong testDownloadCount = 7; var testReport = new ReportEntity() { DownloadCount = testDownloadCount }; var options = TestUtilities.GetOptions(nameof(IncrementDownloadCountWithOne)); using (var actContext = new ReportablyDbContext(options)) { actContext.Reports.Add(testReport); await actContext.SaveChangesAsync(); var report = await actContext.Reports.FirstOrDefaultAsync(); var SUT = new ReportService(actContext); await SUT.UpdateDownloadCountAsync(report.Id, new CancellationToken()); } using (var assertContext = new ReportablyDbContext(options)) { var report = await assertContext.Reports.FirstOrDefaultAsync(); ulong expected = testDownloadCount + 1; Assert.AreEqual(expected, report.DownloadCount); } }
public async Task ReturnTrue_WhenReportWithPassedReportIdExistInDb() { var options = TestUtilities.GetOptions(nameof(ReturnTrue_WhenReportWithPassedReportIdExistInDb)); using (var actContext = new ReportablyDbContext(options)) { actContext.Reports.Add(new ReportEntity()); await actContext.SaveChangesAsync(); var report = await actContext.Reports.FirstOrDefaultAsync(); var SUT = new ReportService(actContext); var result = await SUT.UpdateDownloadCountAsync(report.Id, new CancellationToken()); Assert.IsTrue(result); } }
public async Task ReturnAllReports() { var options = TestUtilities.GetOptions(nameof(ReturnAllReports)); using (var actContext = new ReportablyDbContext(options)) { actContext.Reports.Add(new ReportEntity()); actContext.Reports.Add(new ReportEntity()); actContext.Reports.Add(new ReportEntity()); await actContext.SaveChangesAsync(); } using (var assertContext = new ReportablyDbContext(options)) { var SUT = new ReportService(assertContext); var reports = await SUT.GetAllAsync(new CancellationToken()); Assert.AreEqual(3, reports.Count()); } }
public async Task ReturnReportInstance_WhenReportExistInDb() { var options = TestUtilities.GetOptions(nameof(ReturnReportInstance_WhenReportExistInDb)); using (var actContext = new ReportablyDbContext(options)) { actContext.Reports.Add(new ReportEntity()); actContext.Reports.Add(new ReportEntity()); await actContext.SaveChangesAsync(); } using (var assertContext = new ReportablyDbContext(options)) { var report = await assertContext.Reports.FirstAsync(); var SUT = new ReportService(assertContext); var result = await SUT.FindByIdAsync(report.Id, new CancellationToken()); Assert.IsInstanceOfType(result, typeof(Report)); } }