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 SetPassedPublicationDateValueOfReport() { var testPublicationDate = new DateTime(2020, 2, 2); var testReport = new Report() { PublicationDate = testPublicationDate, }; var options = TestUtilities.GetOptions(nameof(SetPassedPublicationDateValueOfReport)); using (var actContext = new ReportablyDbContext(options)) { var SUT = new ReportService(actContext); await SUT.AddAsync(testReport, new CancellationToken()); } using (var assertContext = new ReportablyDbContext(options)) { var report = await assertContext.Reports.FirstOrDefaultAsync(); Assert.AreEqual(testPublicationDate, report.PublicationDate); } }
public async Task SetPassedAuthorValueOfReport() { var testAuthor = "Test Author Name"; var testReport = new Report() { Author = testAuthor, }; var options = TestUtilities.GetOptions(nameof(SetPassedAuthorValueOfReport)); using (var actContext = new ReportablyDbContext(options)) { var SUT = new ReportService(actContext); await SUT.AddAsync(testReport, new CancellationToken()); } using (var assertContext = new ReportablyDbContext(options)) { var report = await assertContext.Reports.FirstOrDefaultAsync(); Assert.AreEqual(testAuthor, report.Author); } }
public void ReturnInstance() { var contextOptions = TestUtilities.GetOptions(nameof(ReturnInstance)); using (var context = new ReportablyDbContext(contextOptions)) { var SUT = new ReportService(context); Assert.IsNotNull(SUT); Assert.IsInstanceOfType(SUT, typeof(ReportService)); } }
public async Task ReturnIReadOnlyCollectionWithReport() { var options = TestUtilities.GetOptions(nameof(ReturnIReadOnlyCollectionWithReport)); using (var assertContext = new ReportablyDbContext(options)) { var SUT = new ReportService(assertContext); var reports = await SUT.GetAllAsync(new CancellationToken()); Assert.IsInstanceOfType(reports, typeof(IReadOnlyCollection <Report>)); } }
public async Task ReturnNull_WhenReportDoesNotExistInDb() { var options = TestUtilities.GetOptions(nameof(ReturnNull_WhenReportDoesNotExistInDb)); using (var assertContext = new ReportablyDbContext(options)) { var SUT = new ReportService(assertContext); var result = await SUT.FindByIdAsync(new Guid(), new CancellationToken()); Assert.IsNull(result); } }
public async Task ReturnIstanceOfReportSystem() { var options = TestUtilities.GetOptions(nameof(ReturnIstanceOfReportSystem)); using (var assertContext = new ReportablyDbContext(options)) { var SUT = new ReportService(assertContext); var reports = await SUT.GetTotalReportsbCountAsync(new CancellationToken()); Assert.IsInstanceOfType(reports, typeof(ReportSystem)); } }
public async Task ReturnFalse_WhenReportWithPassedReportIdDoesNotExistInDb() { var options = TestUtilities.GetOptions(nameof(ReturnFalse_WhenReportWithPassedReportIdDoesNotExistInDb)); using (var actContext = new ReportablyDbContext(options)) { Guid reportId = new Guid("CD1D4E6B-D86D-4AA1-2661-08D7AE3670FB"); var SUT = new ReportService(actContext); var result = await SUT.UpdateDownloadCountAsync(reportId, new CancellationToken()); Assert.IsFalse(result); } }
public async Task ReturnReportInstance() { var testReport = new Report(); var options = TestUtilities.GetOptions(nameof(ReturnReportInstance)); using (var actContext = new ReportablyDbContext(options)) { var SUT = new ReportService(actContext); var result = await SUT.AddAsync(testReport, new CancellationToken()); Assert.IsInstanceOfType(result, typeof(Report)); } }
public async Task SaveReportInDatabase() { var options = TestUtilities.GetOptions(nameof(SaveReportInDatabase)); using (var actContext = new ReportablyDbContext(options)) { var SUT = new ReportService(actContext); await SUT.AddAsync(new Report(), new CancellationToken()); } using (var assertContext = new ReportablyDbContext(options)) { Assert.AreEqual(1, assertContext.Reports.Count()); } }
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)); } }
public UploadedFileService(ReportablyDbContext context) { this.context = context ?? throw new ArgumentNullException(nameof(context)); }