public void CanSaveOrUpdateValidRequest() { // Establish Context Request validRequest = RequestInstanceFactory.CreateValidTransientRequest(); WrmsSystem systemToExpect = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemManagementService.Expect(r => r.Get(13)) .Return(systemToExpect); _requestEstimateManagementService.Expect( r => r.SaveOrUpdate(new RequestEstimate { RequestId = validRequest.Id, EstimatedHours = validRequest.EstimatedHours })).Return( ActionConfirmation.CreateSuccessConfirmation("")); // Act ActionConfirmation confirmation = _requestManagementService.SaveOrUpdate(validRequest); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(validRequest); }
public void CannotUpdateInvalidWrmsSystemFromForm() { // Establish Context var wrmsSystemFromForm = new WrmsSystem(); var viewModelToExpect = new WrmsSystemFormViewModel(); var testUser = new Person(); testUser.SetAssignedIdTo(1); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1"); _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser); _wrmsSystemManagementService.Expect(r => r.UpdateWith(wrmsSystemFromForm, 0)) .Return(ActionConfirmation.CreateFailureConfirmation("not updated")); _wrmsSystemManagementService.Expect(r => r.CreateFormViewModelFor(wrmsSystemFromForm)) .Return(viewModelToExpect); // Act ViewResult result = _wrmsSystemsController.Edit(wrmsSystemFromForm).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as WrmsSystemFormViewModel).ShouldNotBeNull(); }
public ActionConfirmation Delete(int id) { WrmsSystem wrmsSystemToDelete = _wrmsSystemRepository.Get(id); if (wrmsSystemToDelete != null) { _wrmsSystemRepository.Delete(wrmsSystemToDelete); try { _wrmsSystemRepository.DbContext.CommitChanges(); return(ActionConfirmation.CreateSuccessConfirmation( "The wrmsSystem was successfully deleted.")); } catch { _wrmsSystemRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "A problem was encountered preventing the wrmsSystem from being deleted. " + "Another item likely depends on this wrmsSystem.")); } } else { return(ActionConfirmation.CreateFailureConfirmation( "The wrmsSystem could not be found for deletion. It may already have been deleted.")); } }
public ActionResult Edit(WrmsSystem wrmsSystem) { try { if (ViewData.ModelState.IsValid) { wrmsSystem.LastUpdateTimeStamp = DateTime.Now; wrmsSystem.LastUpdateUser = GetCurrentUser().Id; ActionConfirmation updateConfirmation = _wrmsSystemManagementService.UpdateWith(wrmsSystem, wrmsSystem.Id); if (updateConfirmation.WasSuccessful) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = updateConfirmation.Message; return(RedirectToAction("Search")); } } } catch (PreconditionException pce) { TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] = pce.Message; } WrmsSystemFormViewModel viewModel = _wrmsSystemManagementService.CreateFormViewModelFor(wrmsSystem); return(View(viewModel)); }
public WrmsSystemFormViewModel CreateFormViewModelFor(WrmsSystem wrmsSystem) { WrmsSystemFormViewModel viewModel = CreateFormViewModel(); viewModel.WrmsSystem = wrmsSystem; return(viewModel); }
public virtual void CanGetByRequestId() { int requestId = 1; WrmsSystem result = _wrmsSystemRepository.GetByRequestId(requestId); Assert.That(result != null); Assert.That(result.Id == 307); }
protected void ValidateWrmsSystem(WrmsSystem wrmsSystem) { var example = new WrmsSystem { Code = wrmsSystem.Code }; Check.Require(_wrmsSystemRepository.GetCountByExample(example, wrmsSystem.Id) == 0, "A system with this code already exist."); }
public void CanCompareWrmsSystems() { var instance = new WrmsSystem(); instance.Code = "ABC"; var instanceToCompareTo = new WrmsSystem(); instanceToCompareTo.Code = "ABC"; instance.ShouldEqual(instanceToCompareTo); }
public void CannotSaveOrUpdateInvalidWrmsSystem() { // Establish Context var invalidWrmsSystem = new WrmsSystem(); // Act ActionConfirmation confirmation = _wrmsSystemManagementService.SaveOrUpdate(invalidWrmsSystem); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public void CanSaveOrUpdateValidWrmsSystem() { // Establish Context WrmsSystem validWrmsSystem = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); // Act ActionConfirmation confirmation = _wrmsSystemManagementService.SaveOrUpdate(validWrmsSystem); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(validWrmsSystem); }
public void CanGetWrmsSystem() { // Establish Context WrmsSystem wrmsSystemToExpect = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemRepository.Expect(r => r.Get(1)) .Return(wrmsSystemToExpect); // Act WrmsSystem wrmsSystemRetrieved = _wrmsSystemManagementService.Get(1); // Assert wrmsSystemRetrieved.ShouldNotBeNull(); wrmsSystemRetrieved.ShouldEqual(wrmsSystemToExpect); }
public void CanDeleteWrmsSystem() { // Establish Context var wrmsSystemToDelete = new WrmsSystem(); _wrmsSystemRepository.Expect(r => r.Get(1)) .Return(wrmsSystemToDelete); // Act ActionConfirmation confirmation = _wrmsSystemManagementService.Delete(1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldBeNull(); }
public void CanShowWrmsSystem() { // Establish Context WrmsSystem wrmsSystem = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemManagementService.Expect(r => r.Get(1)) .Return(wrmsSystem); // Act ViewResult result = _wrmsSystemsController.Show(1).AssertViewRendered(); // Assert result.ViewData.Model.ShouldNotBeNull(); (result.ViewData.Model as WrmsSystem).ShouldNotBeNull(); (result.ViewData.Model as WrmsSystem).ShouldEqual(wrmsSystem); }
private void TransferFormValuesTo(WrmsSystem wrmsSystemToUpdate, WrmsSystem wrmsSystemFromForm) { wrmsSystemToUpdate.Code = wrmsSystemFromForm.Code; wrmsSystemToUpdate.ShortDesc = wrmsSystemFromForm.ShortDesc; wrmsSystemToUpdate.LongDesc = wrmsSystemFromForm.LongDesc; wrmsSystemToUpdate.CallListDesc = wrmsSystemFromForm.CallListDesc; wrmsSystemToUpdate.PrimaryContact = wrmsSystemFromForm.PrimaryContact; wrmsSystemToUpdate.PrimaryContactCallNotes = wrmsSystemFromForm.PrimaryContactCallNotes; wrmsSystemToUpdate.SecondaryContact = wrmsSystemFromForm.SecondaryContact; wrmsSystemToUpdate.SecondaryContactCallNotes = wrmsSystemFromForm.SecondaryContactCallNotes; wrmsSystemToUpdate.ThirdContact = wrmsSystemFromForm.ThirdContact; wrmsSystemToUpdate.ThirdContactCallNotes = wrmsSystemFromForm.ThirdContactCallNotes; wrmsSystemToUpdate.ManagerContact = wrmsSystemFromForm.ManagerContact; wrmsSystemToUpdate.ManagerContactCallNotes = wrmsSystemFromForm.ManagerContactCallNotes; wrmsSystemToUpdate.CallListNotes = wrmsSystemFromForm.CallListNotes; wrmsSystemToUpdate.Platform = wrmsSystemFromForm.Platform; wrmsSystemToUpdate.IsActive = wrmsSystemFromForm.IsActive; wrmsSystemToUpdate.LastUpdateTimeStamp = wrmsSystemFromForm.LastUpdateTimeStamp; wrmsSystemToUpdate.LastUpdateUser = wrmsSystemFromForm.LastUpdateUser; }
public void CanCreateFormViewModelForWrmsSystem() { // Establish Context var viewModelToExpect = new WrmsSystemFormViewModel(); WrmsSystem wrmsSystem = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemRepository.Expect(r => r.Get(1)) .Return(wrmsSystem); // Act WrmsSystemFormViewModel viewModelRetrieved = _wrmsSystemManagementService.CreateFormViewModelFor(1); // Assert viewModelRetrieved.ShouldNotBeNull(); viewModelRetrieved.WrmsSystem.ShouldNotBeNull(); viewModelRetrieved.WrmsSystem.ShouldEqual(wrmsSystem); }
public void CannotUpdateWithInvalidWrmsSystemFromForm() { // Establish Context var invalidWrmsSystemFromForm = new WrmsSystem(); // Intentionally empty to ensure successful transfer of values var wrmsSystemFromDb = new WrmsSystem(); _wrmsSystemRepository.Expect(r => r.Get(1)) .Return(wrmsSystemFromDb); // Act ActionConfirmation confirmation = _wrmsSystemManagementService.UpdateWith(invalidWrmsSystemFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeFalse(); confirmation.Value.ShouldBeNull(); }
public ActionConfirmation SaveOrUpdate(WrmsSystem wrmsSystem) { if (wrmsSystem.IsValid()) { ValidateWrmsSystem(wrmsSystem); _wrmsSystemRepository.SaveOrUpdate(wrmsSystem); ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The wrmsSystem was successfully saved."); saveOrUpdateConfirmation.Value = wrmsSystem; return(saveOrUpdateConfirmation); } else { _wrmsSystemRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The wrmsSystem could not be saved due to missing or invalid information.")); } }
public void CanGetTimeEntry() { // Establish Context TimeEntry timeEntryToExpect = TimeEntryInstanceFactory.CreateValidTransientTimeEntry(); WrmsSystem system = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _timeEntryRepository.Expect(r => r.Get(Arg <int> .Is.Anything)) .Return(timeEntryToExpect); _wrmsSystemRepository.Expect(r => r.GetByRequestId(Arg <int> .Is.Anything)) .Return(system); // Act TimeEntry timeEntryRetrieved = _timeEntryManagementService.Get(Arg <int> .Is.Anything); // Assert timeEntryRetrieved.ShouldNotBeNull(); timeEntryRetrieved.ShouldEqual(timeEntryToExpect); }
public void CanUpdateWithValidRequestFromForm() { // Establish Context Request validRequestFromForm = RequestInstanceFactory.CreateValidTransientRequest(); // Intentionally empty to ensure successful transfer of values var requestFromDb = new Request(); _requestRepository.Expect(r => r.Get(1)) .Return(requestFromDb); WrmsSystem systemToExpect = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); _wrmsSystemManagementService.Expect(r => r.Get(13)) .Return(systemToExpect); _requestEstimateManagementService.Expect( r => r.SaveOrUpdate(new RequestEstimate { RequestId = validRequestFromForm.Id, EstimatedHours = validRequestFromForm.EstimatedHours })).Return( ActionConfirmation.CreateSuccessConfirmation("")); // Act ActionConfirmation confirmation = _requestManagementService.UpdateWith(validRequestFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(requestFromDb); confirmation.Value.ShouldEqual(validRequestFromForm); }
public void CanGetAllWrmsSystems() { // Establish Context IList <WrmsSystem> wrmsSystemsToExpect = new List <WrmsSystem>(); WrmsSystem wrmsSystem = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); wrmsSystemsToExpect.Add(wrmsSystem); _wrmsSystemRepository.Expect(r => r.GetAll()) .Return(wrmsSystemsToExpect); // Act IList <WrmsSystem> wrmsSystemsRetrieved = _wrmsSystemManagementService.GetAll(); // Assert wrmsSystemsRetrieved.ShouldNotBeNull(); wrmsSystemsRetrieved.Count.ShouldEqual(1); wrmsSystemsRetrieved[0].ShouldNotBeNull(); wrmsSystemsRetrieved[0].ShouldEqual(wrmsSystem); }
public void CanCreateValidWrmsSystemFromForm() { // Establish Context var wrmsSystemFromForm = new WrmsSystem(); var testUser = new Person(); testUser.SetAssignedIdTo(1); _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("user1"); _personManagementService.Expect(r => r.GetByUserName("user1")).Return(testUser); _wrmsSystemManagementService.Expect(r => r.SaveOrUpdate(wrmsSystemFromForm)) .Return(ActionConfirmation.CreateSuccessConfirmation("saved")); // Act RedirectToRouteResult redirectResult = _wrmsSystemsController.Create(wrmsSystemFromForm) .AssertActionRedirect().ToAction("Search"); // Assert _wrmsSystemsController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString() .ShouldEqual("saved"); }
public void CanUpdateWithValidWrmsSystemFromForm() { // Establish Context WrmsSystem validWrmsSystemFromForm = WrmsSystemInstanceFactory.CreateValidTransientWrmsSystem(); // Intentionally empty to ensure successful transfer of values var wrmsSystemFromDb = new WrmsSystem(); _wrmsSystemRepository.Expect(r => r.Get(1)) .Return(wrmsSystemFromDb); // Act ActionConfirmation confirmation = _wrmsSystemManagementService.UpdateWith(validWrmsSystemFromForm, 1); // Assert confirmation.ShouldNotBeNull(); confirmation.WasSuccessful.ShouldBeTrue(); confirmation.Value.ShouldNotBeNull(); confirmation.Value.ShouldEqual(wrmsSystemFromDb); confirmation.Value.ShouldEqual(validWrmsSystemFromForm); }
public ActionConfirmation UpdateWith(WrmsSystem wrmsSystemFromForm, int idOfWrmsSystemToUpdate) { WrmsSystem wrmsSystemToUpdate = _wrmsSystemRepository.Get(idOfWrmsSystemToUpdate); ValidateWrmsSystem(wrmsSystemFromForm); TransferFormValuesTo(wrmsSystemToUpdate, wrmsSystemFromForm); if (wrmsSystemToUpdate.IsValid()) { ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation( "The wrmsSystem was successfully updated."); updateConfirmation.Value = wrmsSystemToUpdate; return(updateConfirmation); } else { _wrmsSystemRepository.DbContext.RollbackTransaction(); return(ActionConfirmation.CreateFailureConfirmation( "The wrmsSystem could not be saved due to missing or invalid information.")); } }
public ActionResult Show(int id) { WrmsSystem wrmsSystem = _wrmsSystemManagementService.Get(id); return(View(wrmsSystem)); }
public WrmsSystemFormViewModel CreateFormViewModelFor(int wrmsSystemId) { WrmsSystem wrmsSystem = _wrmsSystemRepository.Get(wrmsSystemId); return(CreateFormViewModelFor(wrmsSystem)); }