private void SeedDb()
        {
            this.TruncatePostReportsTable();
            this.TruncateReplyReportsTable();
            this.TruncateUsersTable();
            this.TruncateQuoteReportsTable();

            var user = new ForumUser {
                Id = TestsConstants.TestId, UserName = TestsConstants.TestUsername1
            };

            this.dbService.DbContext.Users.Add(user);
            this.dbService.DbContext.SaveChanges();

            var replyReport = new ReplyReport {
                Author = user, AuthorId = user.Id
            };
            var postReport = new PostReport {
                Author = user, AuthorId = user.Id
            };
            var quoteReport = new QuoteReport {
                Author = user, AuthorId = user.Id
            };

            this.dbService.DbContext.ReplyReports.Add(replyReport);
            this.dbService.DbContext.PostReports.Add(postReport);
            this.dbService.DbContext.QuoteReports.Add(quoteReport);
            this.dbService.DbContext.SaveChanges();
        }
Example #2
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);
        }
        public async Task <ActionResult <ReplyReport> > PostReplyReport(ReplyReport replyReport)
        {
            replyReport.ReportedAt = DateTime.Now;

            _context.ReplyReports.Add(replyReport);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetReplyReport", new { id = replyReport.Id }, replyReport));
        }
        public async Task CreateAsync(string description, int replyId, string authorId)
        {
            var replyReport = new ReplyReport
            {
                Description = description,
                ReplyId     = replyId,
                AuthorId    = authorId,
                CreatedOn   = this.dateTimeProvider.Now()
            };

            await this.db.ReplyReports.AddAsync(replyReport);

            await this.db.SaveChangesAsync();
        }