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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        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));
            }
        }
Exemplo n.º 5
0
        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>));
            }
        }
Exemplo n.º 6
0
        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);
            }
        }
Exemplo n.º 9
0
        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));
            }
        }
Exemplo n.º 10
0
        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);
            }
        }
Exemplo n.º 12
0
        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());
            }
        }
Exemplo n.º 13
0
        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));
            }
        }
Exemplo n.º 14
0
 public UploadedFileService(ReportablyDbContext context)
 {
     this.context = context ?? throw new ArgumentNullException(nameof(context));
 }