Esempio n. 1
0
        public async Task AllWithInvalidId()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);

            var machineContersService = new MachineCountersService(new EfRepository <MachineCounters>(dbContext));

            var service = new ReportService(new EfDeletableEntityRepository <Report>(dbContext), machineContersService);
            var data    = DateTime.UtcNow;

            for (int i = 1; i <= 5; i++)
            {
                await service.AddAsync(data, 1 + i, 1 + i, "1");
            }

            var reports = service.All <IndexReportViewModel>("11");

            int count = 0;

            foreach (var report in reports)
            {
                count++;
            }

            Assert.Equal(0, count);
            dbContext.Database.EnsureDeleted();
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
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));
            }
        }
Esempio n. 5
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());
            }
        }
Esempio n. 6
0
        public async Task AddAsyncWithCorectData()
        {
            ApplicationDbContext dbContext = new ApplicationDbContext(new DbContextOptionsBuilder <ApplicationDbContext>()
                                                                      .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()).Options);

            var machineContersService = new MachineCountersService(new EfRepository <MachineCounters>(dbContext));

            var service = new ReportService(new EfDeletableEntityRepository <Report>(dbContext), machineContersService);
            var data    = DateTime.UtcNow;
            await service.AddAsync(data, 1, 1, "1");

            var report = await dbContext.Reports.FirstOrDefaultAsync();

            Assert.Equal(data, report.Date);
            Assert.Equal(1, report.InForDay);
            Assert.Equal(1, report.OutForDay);
            Assert.Equal("1", report.GamingHallId);
            dbContext.Database.EnsureDeleted();
        }