public ActionResult Create(NewBragViewModel viewModel) { var brag = new Brag { Author = this._runtimeSession.GetCurrentUser(), Title = viewModel.Title, Description = viewModel.Description, SubmittedOn = DateTime.Now }; this._repository.Save(brag); return null; }
public void Create_WithValidViewModel_ShouldSaveANewBrag_AndRedirectsToList() { // arrange var authenticatedUser = A_user_is_logged_in(1, "Amir"); var viewModel = new NewBragViewModel { AuthorId = 1, Title = "Awesome thing", Description = "This thing I did was really awesome." }; // act var result = this.controller.Create(viewModel); // assert repository.AssertWasCalled(r => r.Save(Arg<Brag>.Matches(b => b.Author == authenticatedUser && b.Title == "Awesome thing"))); // assert result.AssertActionRedirect().ToAction<HomeController>(c => c.Index()); }
public void Update_WithValidViewModel_ShouldUpdateBrag_AndRedirectsToList() { var expected = GivenIHaveABrag(1, "Update Test Title", "Update Test Desc"); // arrange var authenticatedUser = A_user_is_logged_in(1, "Amir"); var viewModel = new NewBragViewModel { Id = expected.Id, Title = expected.Title, Description = expected.Description }; // act var result = this.controller.Update(viewModel); // assert repository.AssertWasCalled(r => r.Save(Arg<Brag>.Matches(b => b.Title == expected.Title && b.Description == expected.Description))); // assert result.AssertActionRedirect().ToAction<HomeController>(c => c.Index()); }
public ActionResult New() { var vm = new NewBragViewModel(); return View(vm); }