Exemplo n.º 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();
        }
Exemplo n.º 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."));
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
        public WrmsSystemFormViewModel CreateFormViewModelFor(WrmsSystem wrmsSystem)
        {
            WrmsSystemFormViewModel viewModel = CreateFormViewModel();

            viewModel.WrmsSystem = wrmsSystem;
            return(viewModel);
        }
Exemplo n.º 6
0
        public virtual void CanGetByRequestId()
        {
            int        requestId = 1;
            WrmsSystem result    = _wrmsSystemRepository.GetByRequestId(requestId);

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

            instance.Code = "ABC";

            var instanceToCompareTo = new WrmsSystem();

            instanceToCompareTo.Code = "ABC";

            instance.ShouldEqual(instanceToCompareTo);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 13
0
        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);
        }
Exemplo n.º 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;
 }
Exemplo n.º 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);
        }
Exemplo n.º 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();
        }
Exemplo n.º 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."));
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 21
0
        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");
        }
Exemplo n.º 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);
        }
Exemplo n.º 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."));
            }
        }
Exemplo n.º 24
0
        public ActionResult Show(int id)
        {
            WrmsSystem wrmsSystem = _wrmsSystemManagementService.Get(id);

            return(View(wrmsSystem));
        }
Exemplo n.º 25
0
        public WrmsSystemFormViewModel CreateFormViewModelFor(int wrmsSystemId)
        {
            WrmsSystem wrmsSystem = _wrmsSystemRepository.Get(wrmsSystemId);

            return(CreateFormViewModelFor(wrmsSystem));
        }