public void Create_Increases_Count()
        {
            underTest.Create(new Review()
            {
                Content = "Baby"
            });

            var count = underTest.Count();

            Assert.Equal(1, count);
        }
Example #2
0
        public void Create_Increases_Count()
        {
            underTest.Create(new Review()
            {
                Content      = "I love this pony",
                ReviewerName = "Carl",
                Rating       = 5.0,
                ProductId    = 1,
            });

            var count = underTest.Count();

            Assert.Equal(5, count);
        }
        public ActionResult SubmitReview(Review review)
        {
            if (!ModelState.IsValid)
            {
                return(View("Submit"));
            }

            reviewRepository = new ReviewRepository();
            reviewRepository.Create(review);
            return(RedirectToAction("Reviews"));
        }
        public void CreateCallsAdd()
        {
            //Arrange
            var mockSet = new Mock <DbSet <Review> >();

            mockSet.Setup(a => a.Add(It.IsAny <Review>())).Verifiable();

            var mock = new Mock <RentContext>();

            mock.Setup(a => a.Reviews).Returns(mockSet.Object);

            //Act
            var repository = new ReviewRepository(mock.Object);

            repository.Create(new Review());

            //Assert
            Mock.Verify(mockSet);
        }
        public async Task CreateTest()
        {
            //Arrange
            using (var context = new AppDbContext(options))
            {
                var review = new GoodReview {
                    Id = 1
                };
                var repo = new ReviewRepository(context);

                //Act
                await repo.Create(review);

                var expectedResult = 1;
                var actualResult   = context.Reviews.Local.Count;

                //Assert
                Assert.AreEqual(expectedResult, actualResult);
            }
        }
Example #6
0
        public async Task <ActionResult> CreateReview(Review review, Guid testsGuid)
        {
            ModelState.Remove("testsGuid");
            ModelState.Remove(nameof(Review.Id));
            ModelState.Remove(nameof(Review.Created));
            ModelState.Remove(nameof(Review.Creator));
            if (ModelState.IsValid)
            {
                TestsRepository testsRepo = new TestsRepository();
                var             testsTask = testsRepo.GetByIdAsync(testsGuid);

                ApplicationUserRepository <Tester> userRepo = new ApplicationUserRepository <Tester>();
                var testerTask = userRepo.GetByUserNameAsync(User.Identity.Name);

                review.Created = DateTime.Now;
                review.Creator = await testerTask;

                DataAccess.Model.Tests.Tests tests = await testsTask;

                tests.Test.Reviews.Add(review);

                tests.Test.CountRating();
                tests.Status = TestsStatus.Reviewed;

                ReviewRepository reviewRepo = new ReviewRepository();

                reviewRepo.Create(review);

                testsRepo.Update(tests);

                return(RedirectToAction("FinishedTests"));
            }

            ViewBag.TestsGuid = testsGuid;
            return(View("AddReview", review));
        }
        public async Task <ActionResult <ReviewDTO> > PostReview(ReviewDTO review)
        {
            await _reviewRepository.Create(review);

            return(CreatedAtAction("GetReview", new { id = review.ID }, review));
        }
        public ActionResult AddSave(Review review, HttpPostedFileBase upload)
        {
            // missing PublishDate
            if (review.PublishDate == DateTime.MinValue)
            {
                TempData["Error"] = TempData["Error"] + " Publish Date was empty";
            }


            // missing Type
            if (String.IsNullOrEmpty(review.ReviewType))
            {
                TempData["Error"] = TempData["Error"] + " Review Type was empty";
            }


            // Odd way to handle empty image, but it works
            try
            {
                if (upload.GetType() == typeof(HttpPostedFileBase))
                {
                    // This will never hit
                    TempData["Error"] = null;
                }
            }
            catch {
                TempData["Error"] = TempData["Error"] + " Image was not uploaded correctly";
            }

            // missing header
            if (String.IsNullOrEmpty(review.ReviewHeader))
            {
                TempData["Error"] = TempData["Error"] + " Title was empty";
            }


            // missing review
            if (String.IsNullOrEmpty(review.ReviewText))
            {
                TempData["Error"] = TempData["Error"] + " Review was empty";
            }

            // return with error
            if (TempData["Error"] != null)
            {
                return(View("Add"));
            }


            if (upload.ContentLength > 3500000)
            {
                TempData["Error"] = "File Size is Too Large";
                return(View("Add"));
            }


            // final catch if somehow there is an issue, but gets by other checks
            if (!ModelState.IsValid)
            {
                TempData["Error"] = "Unable to process, form data was missing";
                return(View("Add"));
            }

            reviewRepository = new ReviewRepository();

            if (upload != null && upload.ContentLength > 0)
            {
                var image = new Image
                {
                    ImageName   = System.IO.Path.GetFileName(upload.FileName),
                    ContentType = upload.ContentType
                };
                using (var reader = new System.IO.BinaryReader(upload.InputStream))
                {
                    image.ImageData = reader.ReadBytes(upload.ContentLength);
                }
                review.Image = image;
            }

            reviewRepository.Create(review);

            TempData["Success"] = "Successfully Added Review ";
            return(View("Index"));
            // If I ever wanted to show addition right away:
            // return RedirectToAction("Index", "Home");
        }
Example #9
0
 public int CreateReview(Review R)
 {
     return(_reviewRepo.Create(R));
 }