Example #1
0
        public async Task GetReportsShouldGetOne()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);

            var guideRepository = new EfDeletableEntityRepository <Guide>(context);
            var guideService    = new GuidesService(guideRepository);
            var guideModel      = new CreateGuideInputModel()
            {
                Category    = "Action",
                Description = "someDesc",
                GameId      = "1",
                ImageUrl    = "google",
                Title       = "test",
            };
            var guideId = await guideService.CreateAsync(guideModel, "1");

            var repository = new EfRepository <Report>(context);
            var service    = new ReportsService(repository);
            var model      = new AddReportToGuideInputModel()
            {
                UserId  = "1",
                GuideId = guideId,
                Reason  = "tupooooo",
            };
            await service.AddReportToGuideAsync(model);

            var actual = await service.GetByGuideAsync <ReportForGuideViewModel>(model.GuideId);

            Assert.Single(actual);
        }
Example #2
0
        public async Task <IActionResult> SendReport(AddReportToGuideInputModel model)
        {
            var user = await this.userManager.GetUserAsync(this.User);

            var userId = await this.userManager.GetUserIdAsync(user);

            model.UserId = userId;
            model.Reason = new HtmlSanitizer().Sanitize(model.Reason);

            if (!this.ModelState.IsValid || userId == null)
            {
                this.TempData["InfoMessage"] = "Something went wrong! Try again. :)";
                return(this.RedirectToAction("Details", "Guides", new { id = model.GuideId }));
            }

            var reportId = await this.reportsService.AddReportToGuideAsync(model);

            if (!reportId.HasValue)
            {
                this.TempData["InfoMessage"] = "You have already reported this guide. :)";
            }
            else
            {
                this.TempData["InfoMessage"] = "Your report is with us! We are going to review it soon! :)";
            }

            return(this.RedirectToAction("Details", "Guides", new { id = model.GuideId }));
        }
Example #3
0
        public async Task AddOnReportShouldAdd()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString());
            var context = new ApplicationDbContext(options.Options);

            var repository = new EfRepository <Report>(context);
            var service    = new ReportsService(repository);
            var model      = new AddReportToGuideInputModel()
            {
                UserId  = "1",
                GuideId = "1",
                Reason  = "tupooooo",
            };

            var actual = await service.AddReportToGuideAsync(model);

            Assert.True(actual.HasValue);
        }