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"]);
        }
Пример #2
0
        public ActionResult Create(FormCollection collection, int id, int?userId = 1)
        {
            BreweryViewModel brewery = brewLogic.GetBrewery(id);
            UserViewModel    user    = new UserViewModel
            {
                Username = "******"
            };

            if (ModelState.IsValid)
            {
                try
                {
                    ReviewViewModel review = new ReviewViewModel
                    {
                        BreweryID         = id,
                        Rating            = Convert.ToInt32(collection["Rating"]),
                        ReviewDescription = collection["ReviewDescription"],
                        User    = user,
                        UserID  = (int)userId,
                        Brewery = brewery,
                    };
                    revLogic.PostReview(review);
                    return(RedirectToAction("Details", "Brewery", new { id = id }));
                }
                catch (Exception e)
                {
                    return(View("Caught Exception"));
                }
            }
            else
            {
                return(View("Invalid Model State"));
            }
        }