public void Edit_Test_ValidInput()
        {
            // Arrange
            ReviewViewModel oldReview = CreateReviewFromForm(collection);

            rLogic.PostReview(oldReview);
            oldReview = rLogic.GetReviews().FirstOrDefault();
            FormCollection newCollection = new FormCollection
            {
                { "BreweryID", brewery.BreweryID.ToString() },
                { "UserID", user.UserID.ToString() }
            };

            foreach (var i in collection.AllKeys)
            {
                newCollection.Add(i, collection.GetValue(i).AttemptedValue);
            }
            newCollection.Set("ReviewDescription", "new description");

            // Act
            RedirectToRouteResult result = controller.Edit(oldReview.ReviewID, newCollection) as RedirectToRouteResult;

            // Assert
            ReviewViewModel newReview = rLogic.GetReviews().FirstOrDefault();

            Assert.AreNotEqual(newReview.ReviewDescription, collection["ReviewDescription"]);
        }
        public async Task CanEditReview()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            var review = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "Test Private",
                StepId       = 1,
                Rating       = 3
            };

            tc.Reviews.Add(review);
            Step step = new Step {
                StepId = 1, Trip = new Trip {
                    TripId = 10, TripOwner = "ABC123"
                }
            };

            tc.Steps.Add(step);

            ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("ABC123");

            // Act
            var updatedReview = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "New notes",
                StepId       = 1,
                Rating       = 4
            };
            var result = await controller.Edit(updatedReview);

            // Assert
            Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult));
        }
        public async Task CannotSaveInvalidReview()
        {
            // Arrange - create mock repository
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            // Arrange - create a review
            Step step = new Step {
                StepId = 21, Trip = new Trip {
                    TripId = 321, TripOwner = "ABC123"
                }
            };

            tc.Steps.Add(step);
            Review review = new Review()
            {
                StepId = 21, Step = step, PrivateNotes = "Test"
            };
            // Arrange - create the controller
            ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("ABC123");

            // Arrange - add an error to the model state
            controller.ModelState.AddModelError("error", "error");
            // Act - try to save the review
            ActionResult result = await controller.Edit(review);

            // Assert - check the method result type
            Assert.IsInstanceOfType(result, typeof(ViewResult));
        }
        public async Task CannotEditSomebodyElseReview()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            var review = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "Test Private",
                StepId       = 1,
                Rating       = 3
            };

            tc.Reviews.Add(review);
            Step step = new Step {
                StepId = 1, Trip = new Trip {
                    TripId = 10, TripOwner = "ABC123"
                }
            };

            tc.Steps.Add(step);

            ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("AnotherUser");

            // Act
            var updatedReview = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "New notes",
                StepId       = 1,
                Rating       = 4
            };
            var result = await controller.Edit(updatedReview) as ViewResult;

            // Assert
            Assert.AreEqual("CustomisedError", result.ViewName);
        }
        public async Task EditReviewReturnsCorrectDetails()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();

            var expectedReview = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "Test Private",
                StepId       = 1,
                Rating       = 3,
                Images       = new List <Image>()
            };

            tc.Reviews.Add(expectedReview);
            tc.Steps.Add(new Step {
                StepId = 1, From = "A", To = "B", Review = expectedReview
            });

            ReviewController controller = new ReviewController(tc);

            // act
            var result = await controller.Edit(1) as ViewResult;

            var resultData = (Review)result.ViewData.Model;

            // assert
            Assert.AreEqual(expectedReview.Rating, resultData.Rating);
            Assert.AreEqual(expectedReview.PrivateNotes, resultData.PrivateNotes);
        }
Example #6
0
        public void ReviewModelScoreTest()
        {
            ReviewController controller = new ReviewController();

            var detailCheck = controller.Edit(3, 6) as ViewResult;
            var actual      = detailCheck.Model as Review;

            Assert.AreEqual(3, actual.ReviewScore);
        }
Example #7
0
        public void ReviewModelTextTest()
        {
            ReviewController controller = new ReviewController();

            var detailCheck = controller.Edit(3, 8) as ViewResult;
            var actual      = detailCheck.Model as Review;

            Assert.AreEqual("Its fine", actual.ReviewText);
        }
Example #8
0
        public void BadReviewIsNullTest()
        {
            ReviewController controller = new ReviewController();

            var check  = controller.Edit(3, 1) as ViewResult;
            var actual = check.Model as Review;

            Assert.IsNull(actual);
        }
Example #9
0
        public void EditModelUnitTest()
        {
            ReviewController controller = new ReviewController();

            var editData = controller.Edit(10) as ViewResult;
            var actual   = editData.Model;

            Assert.IsNotNull(actual);
        }
Example #10
0
        public void EditModelDataUnitTest()
        {
            ReviewController controller = new ReviewController();

            var result = controller.Edit(10) as ViewResult;
            var data   = result.Model as Review;

            Assert.AreEqual("Cristina Reynolds", data.ReviewerName);
        }
        public void EditDataTest()
        {
            ReviewController controller = new ReviewController();

            var result = controller.Edit(4) as ViewResult;
            var data   = result.Model as Review;

            Assert.AreEqual("Place was alright", data.Comment);
        }
Example #12
0
        public void GoodReviewIsNotNullTest()
        {
            ReviewController controller = new ReviewController();

            var detailCheck = controller.Edit(3, 6) as ViewResult;
            var actual      = detailCheck.Model as Review;

            Assert.IsNotNull(actual);
        }
        public async Task EditForNullIdReturnsBadRequest()
        {
            var controller = new ReviewController(new TestTrekStoriesContext());
            var expected   = (int)System.Net.HttpStatusCode.BadRequest;

            int?test      = null;
            var badResult = await controller.Edit(test) as HttpStatusCodeResult;

            Assert.AreEqual(expected, badResult.StatusCode);
        }
Example #14
0
        public void TestEdit()
        {
            //Arrange
            ReviewController controller = new ReviewController();
            string           expected   = "Reviews";

            //Act
            var    action = (RedirectToRouteResult)controller.Edit(new Review());
            string actual = action.RouteValues["action"].ToString();

            //Assert
            Assert.AreEqual(expected, actual);
        }
        private void BtUpdateReview_Click(object sender, RoutedEventArgs e)
        {
            Review review = new Review()
            {
                ReviewID   = TransformStringIntoInt(TbReviewId.Text),
                BookID     = TransformStringIntoInt(TbReviewBookId.Text),
                ReviewText = TbReviewText.Text
                             //Book = reviewDataGrid.ItemsSource as List<Review>
            };

            Review editedReview = reviewsController.Edit(review.ReviewID, review);

            MessageBox.Show("The review with " + editedReview.ToString() + " has been updated successfully.");
            LoadBooks();
        }
        public void TestReviewDetails()
        {
            ReviewController rc = new ReviewController();

            PLC.Functionality func = new PLC.Functionality();
            var reviews            = func.GetReviews(1); // Grab Carl's Jr. reviews

            string expected = "zschiesterl11";           // Reviewer that gave Carl's Jr. a rating of 4

            var action = rc.Edit(reviews[reviews.Count - 2]) as ViewResult;

            var actual = ((PLC.Review)action.Model).Author; // The actual reviewer that was passed to the view

            Assert.AreEqual(expected, actual);
        }
Example #17
0
        public void DB_Edit_Test()
        {
            ReviewController controller = new ReviewController(db);
            Review           testReview = new Review();

            testReview.ReviewId    = 1;
            testReview.Author      = "Matt";
            testReview.ContentBody = "Best chili I've ever had!";
            testReview.Rating      = 4;
            testReview.ProductId   = 1;

            controller.Create(testReview);

            testReview.Author = "Matthew";
            controller.Edit(testReview);

            Assert.AreEqual("Matthew", testReview.Author);
        }
        public async Task CannotEditNonexistentReview()
        {
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            var review = new Review
            {
                ReviewId     = 1,
                PrivateNotes = "Test Private",
                StepId       = 1,
                Rating       = 3
            };

            tc.Reviews.Add(review);
            var controller = new ReviewController(tc);

            // Act
            var badResult = await controller.Edit(2) as ViewResult;

            // Assert
            Assert.AreEqual("CustomisedError", badResult.ViewName);
        }
        public async Task CanAddValidReview()
        {
            // Arrange - create mock repository
            TestTrekStoriesContext tc = new TestTrekStoriesContext();
            // Arrange - create the controller
            ReviewController controller = new ReviewController(tc).WithAuthenticatedUser("ABC123");
            // Arrange - create a review for an existing step
            Step step = new Step {
                StepId = 21, Trip = new Trip {
                    TripId = 321, TripOwner = "ABC123"
                }
            };

            tc.Steps.Add(step);
            Review review = new Review()
            {
                StepId = 21, PrivateNotes = "Test"
            };
            // Act - try to save the step
            ActionResult result = await controller.Edit(review);

            // Assert - check the method result type
            Assert.IsNotInstanceOfType(result, typeof(ViewResult));
        }
Example #20
0
        public void ReviewControllerEditReturnsView_ExpectedSuccess()
        {
            // Arrange
            Review review = new Review
            {
                ReviewId    = 1,
                Rating      = 5,
                Comment     = "Nice driver! Arrived on time. Will book again next time!",
                RideId      = 1,
                PassengerId = 1,
                DriverId    = 1
            };

            var _mock = new Mock <IReviewLogic>();

            _mock.Setup(x => x.GetSingleReview(It.IsAny <Int32>())).ReturnsAsync(GetReview());
            var controllerUnderTest = new ReviewController(_context, _mock.Object);

            // Act
            var result = controllerUnderTest.Edit(1, review);

            // Assert
            var viewResult = Assert.IsType <Task <IActionResult> >(result);
        }