예제 #1
0
        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();
        }
예제 #3
0
        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."));
            }
        }
예제 #4
0
        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));
        }
예제 #5
0
        public WrmsSystemFormViewModel CreateFormViewModelFor(WrmsSystem wrmsSystem)
        {
            WrmsSystemFormViewModel viewModel = CreateFormViewModel();

            viewModel.WrmsSystem = wrmsSystem;
            return(viewModel);
        }
예제 #6
0
        public virtual void CanGetByRequestId()
        {
            int        requestId = 1;
            WrmsSystem result    = _wrmsSystemRepository.GetByRequestId(requestId);

            Assert.That(result != null);
            Assert.That(result.Id == 307);
        }
예제 #7
0
        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.");
        }
예제 #8
0
        public void CanCompareWrmsSystems()
        {
            var instance = new WrmsSystem();

            instance.Code = "ABC";

            var instanceToCompareTo = new WrmsSystem();

            instanceToCompareTo.Code = "ABC";

            instance.ShouldEqual(instanceToCompareTo);
        }
예제 #9
0
        public void CannotSaveOrUpdateInvalidWrmsSystem()
        {
            // Establish Context
            var invalidWrmsSystem = new WrmsSystem();

            // Act
            ActionConfirmation confirmation =
                _wrmsSystemManagementService.SaveOrUpdate(invalidWrmsSystem);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
예제 #10
0
        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);
        }
예제 #11
0
        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);
        }
예제 #12
0
        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);
        }
예제 #14
0
 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;
 }
예제 #15
0
        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);
        }
예제 #16
0
        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();
        }
예제 #17
0
        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."));
            }
        }
예제 #18
0
        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);
        }
예제 #19
0
        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);
        }
예제 #20
0
        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");
        }
예제 #22
0
        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);
        }
예제 #23
0
        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."));
            }
        }
예제 #24
0
        public ActionResult Show(int id)
        {
            WrmsSystem wrmsSystem = _wrmsSystemManagementService.Get(id);

            return(View(wrmsSystem));
        }
예제 #25
0
        public WrmsSystemFormViewModel CreateFormViewModelFor(int wrmsSystemId)
        {
            WrmsSystem wrmsSystem = _wrmsSystemRepository.Get(wrmsSystemId);

            return(CreateFormViewModelFor(wrmsSystem));
        }