private async Task <FindMyTutorWebContext> GetContext() { var options = new DbContextOptionsBuilder <FindMyTutorWebContext>() .UseInMemoryDatabase(databaseName: "FindMyTutor_InMemory_Database") .Options; var context = new FindMyTutorWebContext(options); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var reportedComment = new ReportedComment { Id = 122, ReporterId = "a", ResourceCreatorId = "b" }; var reportedOffer = new ReportedOffer { Id = 112, ReporterId = "a", ResourceCreatorId = "n" }; context.ReportedComment.Add(reportedComment); context.ReportedOffers.Add(reportedOffer); await context.SaveChangesAsync(); return(context); }
public ReportTest() { eportedComments \ = new ReportedComment[] { new ReportedComment { Id = 1, ReporterId = "a", ResourceCreatorId = "b", Rationale = "bad" }, new ReportedComment { Id = 2, ReporterId = "a", ResourceCreatorId = "b", Rationale = "bad offer" }, new ReportedComment { Id = 3, ReporterId = "a", ResourceCreatorId = "b", Rationale = "bad comment" }, new ReportedComment { Id = 4, ReporterId = "a", ResourceCreatorId = "b", Rationale = "bad" }, }; mockCOmmentRepo = new Mock <IRepository <ReportedOffer> >(); mockCOmmentRepo.Setup(p => p.All()).Returns(this.eportedComments \.AsQueryable()); var config = new MapperConfiguration(opts => { opts.AddProfile(new ReportProfile()); }); mapper = config.CreateMapper(); serviceMock = new Mock <ReportService>(mockCOmmentRepo.Object, mapper); }
public ActionResult Report(ReportCommentViewModel model) { var reportedComment = new ReportedComment() { CommentId = model.Id, UserId = User.Identity.GetUserId(), Reason = model.Reason, }; try { ctx.ReportedComments.Add(reportedComment); ctx.SaveChanges(); } catch (Exception e) { return(new HttpStatusCodeResult(HttpStatusCode.InternalServerError)); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
public ReportResponse Report(ReportModel reportModel) { var comment = _session.Get <Comment>(reportModel.CommentId); if (comment == null) { return(new ReportResponse { Type = CommentResponseType.Error, Message = "Could not find comment to report, it may have already been deleted" }); } var reportedComment = new ReportedComment { Comment = comment }; User currentUser = CurrentRequestData.CurrentUser; if (currentUser != null) { reportedComment.User = currentUser; } else { reportedComment.IPAddress = reportModel.IPAddress; } _session.Transact(session => session.Save(reportedComment)); EventContext.Instance.Publish <IOnCommentReported, CommentReportedEventArgs>( new CommentReportedEventArgs(comment)); return(new ReportResponse { Type = CommentResponseType.Info, Message = "The comment has been reported, and will be dealt with by site admin", RedirectUrl = "~/" + comment.Webpage.LiveUrlSegment }); }
public ViewResult Show(ReportedComment reportedComment) { return(View(reportedComment)); }