public void TestEditPostWithValidDataAndVersioningRedirects1() { #region Arrange var categories = new List<Category>(); for (int i = 0; i < 3; i++) { categories.Add(CreateValidEntities.Category(i + 1)); } var fakeCategories = new FakeCategories(); fakeCategories.Records(0, CategoryRepository, categories); var categoryToEdit = CreateValidEntities.Category(3); categoryToEdit.SetIdTo(3); categoryToEdit.Name = "Updated"; var answers = new List<Answer>(); for (int i = 0; i < 3; i++) { answers.Add(CreateValidEntities.Answer(i + 1)); } answers[1].Category = CategoryRepository.GetNullableById(3); var fakeAnswers = new FakeAnswers(); fakeAnswers.Records(0, AnswerRepository, answers); #endregion Arrange #region Act var result = Controller.Edit(3, categoryToEdit) .AssertActionRedirect() .ToAction<CategoryController>(a => a.Edit(9)); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual("Category Edited Successfully", Controller.Message); Assert.AreEqual(3, result.RouteValues["id"]); CategoryRepository.AssertWasCalled(a => a.EnsurePersistent(Arg<Category>.Is.Anything)); var args = (Category)CategoryRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg<Category>.Is.Anything))[0][0]; Assert.AreEqual("Updated", args.Name); #endregion Assert }
public void TestEditGetReturnsView1() { #region Arrange var categories = new List<Category>(); for (int i = 0; i < 3; i++) { categories.Add(CreateValidEntities.Category(i + 1)); } categories[1].IsCurrentVersion = false; categories[2].Survey = CreateValidEntities.Survey(3); var fakeCategories = new FakeCategories(); fakeCategories.Records(0, CategoryRepository, categories); var answers = new List<Answer>(); for (int i = 0; i < 3; i++) { answers.Add(CreateValidEntities.Answer(i+1)); } answers[1].Category = CategoryRepository.GetNullableById(3); var fakeAnswers = new FakeAnswers(); fakeAnswers.Records(0, AnswerRepository, answers); #endregion Arrange #region Act var result = Controller.Edit(3) .AssertViewRendered() .WithViewData<CategoryViewModel>(); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual("Name3", result.Survey.Name); Assert.AreEqual("Name3", result.Category.Name); Assert.IsTrue(result.HasRelatedAnswers); #endregion Assert }
public void TestEditPostWithInvalidDataReturnsView() { #region Arrange var categories = new List<Category>(); for (int i = 0; i < 3; i++) { categories.Add(CreateValidEntities.Category(i + 1)); } var fakeCategories = new FakeCategories(); fakeCategories.Records(0, CategoryRepository, categories); var categoryToEdit = CreateValidEntities.Category(3); categoryToEdit.SetIdTo(3); categoryToEdit.Name = string.Empty; var answers = new List<Answer>(); for (int i = 0; i < 3; i++) { answers.Add(CreateValidEntities.Answer(i + 1)); } answers[1].Category = CategoryRepository.GetNullableById(1); var fakeAnswers = new FakeAnswers(); fakeAnswers.Records(0, AnswerRepository, answers); #endregion Arrange #region Act var result = Controller.Edit(3, categoryToEdit) .AssertViewRendered() .WithViewData<CategoryViewModel>(); #endregion Act #region Assert Assert.IsNotNull(result); Assert.AreEqual("Unable to Edit Category", Controller.Message); Controller.ModelState.AssertErrorsAre("The Name field is required."); Assert.AreEqual(string.Empty, result.Category.Name); Assert.IsFalse(result.HasRelatedAnswers); #endregion Assert }