Beispiel #1
0
        public async Task CreateMethodShouldAddRightReplyReportInDatabase(string description, int replyId)
        {
            var options = new DbContextOptionsBuilder <ForumDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new ForumDbContext(options);
            var dateTimeProvider = new Mock <IDateTimeProvider>();

            dateTimeProvider.Setup(dtp => dtp.Now()).Returns(new DateTime(2020, 3, 27));

            var postReportsService = new ReplyReportsService(db, null, dateTimeProvider.Object);

            var authorId = Guid.NewGuid().ToString();
            await postReportsService.CreateAsync(description, replyId, authorId);

            var expected = new ReplyReport
            {
                Id          = 1,
                Description = description,
                ReplyId     = replyId,
                AuthorId    = authorId,
                CreatedOn   = dateTimeProvider.Object.Now(),
            };

            var actual = await db.ReplyReports.FirstOrDefaultAsync();

            actual.Should().BeEquivalentTo(expected);
        }
Beispiel #2
0
        public async Task CreateMethodShouldAddReplyReportInDatabase(string description, int replyId)
        {
            var options = new DbContextOptionsBuilder <ForumDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            var db = new ForumDbContext(options);
            var dateTimeProvider = new Mock <IDateTimeProvider>();

            dateTimeProvider.Setup(dtp => dtp.Now()).Returns(new DateTime(2020, 3, 27));

            var replyReportsService = new ReplyReportsService(db, null, dateTimeProvider.Object);
            await replyReportsService.CreateAsync(description, replyId, Guid.NewGuid().ToString());

            db.ReplyReports.Should().HaveCount(1);
        }