public void CanCompareEntries() { Entry instance = new Entry(); instance.Content = "This is an entry"; Entry instanceToCompareTo = new Entry(); instanceToCompareTo.Content = "This is an entry"; instance.ShouldEqual(instanceToCompareTo); }
public void CanDeleteEntry() { // Establish Context Entry entryToDelete = new Entry(); entryRepository.Expect(r => r.Get(1)) .Return(entryToDelete); // Act ActionConfirmation confirmation = entryManagementService.Delete(1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldBeNull(); }
public void CanCreateValidEntryFromForm() { // Establish Context Entry entryFromForm = new Entry(); entryManagementService.Expect(r => r.SaveOrUpdate(entryFromForm)) .Return(ActionConfirmation.CreateSuccessConfirmation("saved")); // Act RedirectToRouteResult redirectResult = entriesController.Create(entryFromForm) .AssertActionRedirect().ToAction("Index"); // Assert entriesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString() .ShouldEqual("saved"); }
public ActionResult Create(Entry entry) { if (ViewData.ModelState.IsValid) { ActionConfirmation saveOrUpdateConfirmation = entryManagementService.SaveOrUpdate(entry); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; return RedirectToAction("Index"); } } else { entry = null; } EntryFormViewModel viewModel = entryManagementService.CreateFormViewModelFor(entry); return View(viewModel); }
public JsonResult CreateEntry(Entry entry) { if (ViewData.ModelState.IsValid) { //entry.PostingDateTime = System.DateTime.Now; ActionConfirmation saveOrUpdateConfirmation = entryManagementService.SaveOrUpdate(entry); if (saveOrUpdateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = saveOrUpdateConfirmation.Message; return Json(entry); } } else { entry = null; } return Json("Failed to create new entry"); }
public void CanUpdateWithValidEntryFromForm() { // Establish Context Entry validEntryFromForm = EntryInstanceFactory.CreateValidTransientEntry(); // Intentionally empty to ensure successful transfer of values Entry entryFromDb = new Entry(); entryRepository.Expect(r => r.Get(1)) .Return(entryFromDb); // Act ActionConfirmation confirmation = entryManagementService.UpdateWith(validEntryFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(entryFromDb); confirmation.Value.ShouldEqual(validEntryFromForm); }
public void CannotUpdateWithInvalidEntryFromForm() { // Establish Context Entry invalidEntryFromForm = new Entry(); // Intentionally empty to ensure successful transfer of values Entry entryFromDb = new Entry(); entryRepository.Expect(r => r.Get(1)) .Return(entryFromDb); // Act ActionConfirmation confirmation = entryManagementService.UpdateWith(invalidEntryFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public void CannotSaveOrUpdateInvalidEntry() { // Establish Context Entry invalidEntry = new Entry(); // Act ActionConfirmation confirmation = entryManagementService.SaveOrUpdate(invalidEntry); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public void CannotUpdateInvalidEntryFromForm() { // Establish Context Entry entryFromForm = new Entry(); EntryFormViewModel viewModelToExpect = new EntryFormViewModel(); entryManagementService.Expect(r => r.UpdateWith(entryFromForm, 0)) .Return(ActionConfirmation.CreateFailureConfirmation("not updated")); entryManagementService.Expect(r => r.CreateFormViewModelFor(entryFromForm)) .Return(viewModelToExpect); // Act ViewResult result = entriesController.Edit(entryFromForm).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as EntryFormViewModel).ShouldNotBeNull(); }
public ActionResult Edit(Entry entry) { if (ViewData.ModelState.IsValid) { ActionConfirmation updateConfirmation = entryManagementService.UpdateWith(entry, entry.Id); if (updateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = updateConfirmation.Message; return RedirectToAction("Index"); } } EntryFormViewModel viewModel = entryManagementService.CreateFormViewModelFor(entry); return View(viewModel); }
public ActionConfirmation SaveOrUpdate(Entry entry) { if (entry.IsValid()) { entryRepository.SaveOrUpdate(entry); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The entry was successfully saved."); saveOrUpdateConfirmation.Value = entry; return saveOrUpdateConfirmation; } else { entryRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The entry could not be saved due to missing or invalid information."); } }
public EntryFormViewModel CreateFormViewModelFor(Entry entry) { EntryFormViewModel viewModel = CreateFormViewModel(); viewModel.Entry = entry; return viewModel; }
private void TransferFormValuesTo(Entry entryToUpdate, Entry entryFromForm) { entryToUpdate.Content = entryFromForm.Content; entryToUpdate.PostingDateTime = entryFromForm.PostingDateTime; }
public ActionConfirmation UpdateWith(Entry entryFromForm, int idOfEntryToUpdate) { Entry entryToUpdate = entryRepository.Get(idOfEntryToUpdate); TransferFormValuesTo(entryToUpdate, entryFromForm); if (entryToUpdate.IsValid()) { ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The entry was successfully updated."); updateConfirmation.Value = entryToUpdate; return updateConfirmation; } else { entryRepository.DbContext.RollbackTransaction(); return ActionConfirmation.CreateFailureConfirmation( "The entry could not be saved due to missing or invalid information."); } }