Ejemplo n.º 1
0
        public ActionResult Create(RequestEstimate requestEstimate)
        {
            if (ViewData.ModelState.IsValid)
            {
                requestEstimate.LastUpdateTimeStamp = DateTime.Now;
                requestEstimate.LastUpdateUser      = GetCurrentUser().Id;
                ActionConfirmation saveOrUpdateConfirmation =
                    _requestEstimateManagementService.SaveOrUpdate(requestEstimate);

                if (saveOrUpdateConfirmation.WasSuccessful)
                {
                    TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                        saveOrUpdateConfirmation.Message;
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                requestEstimate = null;
            }

            RequestEstimateFormViewModel viewModel =
                _requestEstimateManagementService.CreateFormViewModelFor(requestEstimate);

            return(View(viewModel));
        }
        public ActionConfirmation Delete(int id)
        {
            RequestEstimate requestEstimateToDelete = _requestEstimateRepository.Get(id);

            if (requestEstimateToDelete != null)
            {
                _requestEstimateRepository.Delete(requestEstimateToDelete);

                try
                {
                    _requestEstimateRepository.DbContext.CommitChanges();

                    return(ActionConfirmation.CreateSuccessConfirmation(
                               "The requestEstimate was successfully deleted."));
                }
                catch
                {
                    _requestEstimateRepository.DbContext.RollbackTransaction();

                    return(ActionConfirmation.CreateFailureConfirmation(
                               "A problem was encountered preventing the requestEstimate from being deleted. " +
                               "Another item likely depends on this requestEstimate."));
                }
            }
            else
            {
                return(ActionConfirmation.CreateFailureConfirmation(
                           "The requestEstimate could not be found for deletion. It may already have been deleted."));
            }
        }
        public ActionResult Create(RequestEstimate requestEstimate)
        {
            if (ViewData.ModelState.IsValid)
            {
                requestEstimate.LastUpdateTimeStamp = DateTime.Now;
                requestEstimate.LastUpdateUser = GetCurrentUser().Id;
                ActionConfirmation saveOrUpdateConfirmation =
                    _requestEstimateManagementService.SaveOrUpdate(requestEstimate);

                if (saveOrUpdateConfirmation.WasSuccessful)
                {
                    TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()] =
                        saveOrUpdateConfirmation.Message;
                    return RedirectToAction("Index");
                }
            }
            else
            {
                requestEstimate = null;
            }

            RequestEstimateFormViewModel viewModel =
                _requestEstimateManagementService.CreateFormViewModelFor(requestEstimate);
            return View(viewModel);
        }
        public RequestEstimateFormViewModel CreateFormViewModelFor(RequestEstimate requestEstimate)
        {
            RequestEstimateFormViewModel viewModel = CreateFormViewModel();

            viewModel.RequestEstimate = requestEstimate;
            return(viewModel);
        }
 private void TransferFormValuesTo(RequestEstimate requestEstimateToUpdate,
                                   RequestEstimate requestEstimateFromForm)
 {
     requestEstimateToUpdate.RequestId           = requestEstimateFromForm.RequestId;
     requestEstimateToUpdate.EstimatedHours      = requestEstimateFromForm.EstimatedHours;
     requestEstimateToUpdate.LastUpdateTimeStamp = requestEstimateFromForm.LastUpdateTimeStamp;
     requestEstimateToUpdate.LastUpdateUser      = requestEstimateFromForm.LastUpdateUser;
 }
        public virtual void CanGetLatest()
        {
            //RequestEstimateSearchRequest searchRequest = new RequestEstimateSearchRequest();
            //searchRequest.RequestEstimateQuery = "e";

            RequestEstimate result = _requestEstimateRepository.GetLatestByRequest(1);

            Assert.That(result.Id == 1903);
        }
Ejemplo n.º 7
0
        public void CanCompareRequestEstimates()
        {
            var instance = new RequestEstimate();
            instance.RequestId = 1;
            instance.EstimatedHours = 40;

            var instanceToCompareTo = new RequestEstimate();
            instanceToCompareTo.RequestId = 1;
            instanceToCompareTo.EstimatedHours = 40;

            instance.ShouldEqual(instanceToCompareTo);
        }
Ejemplo n.º 8
0
        public void CanCompareRequestEstimates()
        {
            var instance = new RequestEstimate();

            instance.RequestId      = 1;
            instance.EstimatedHours = 40;

            var instanceToCompareTo = new RequestEstimate();

            instanceToCompareTo.RequestId      = 1;
            instanceToCompareTo.EstimatedHours = 40;

            instance.ShouldEqual(instanceToCompareTo);
        }
Ejemplo n.º 9
0
        public void CannotSaveOrUpdateInvalidRequestEstimate()
        {
            // Establish Context
            var invalidRequestEstimate = new RequestEstimate();

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.SaveOrUpdate(invalidRequestEstimate);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
Ejemplo n.º 10
0
        public void CanSaveOrUpdateValidRequestEstimate()
        {
            // Establish Context
            RequestEstimate validRequestEstimate =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.SaveOrUpdate(validRequestEstimate);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(validRequestEstimate);
        }
        public void CanShowRequestEstimate()
        {
            // Establish Context
            RequestEstimate requestEstimate =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            _requestEstimateManagementService.Expect(r => r.Get(1))
            .Return(requestEstimate);

            // Act
            ViewResult result = _requestEstimatesController.Show(1).AssertViewRendered();

            // Assert
            result.ViewData.Model.ShouldNotBeNull();
            (result.ViewData.Model as RequestEstimate).ShouldNotBeNull();
            (result.ViewData.Model as RequestEstimate).ShouldEqual(requestEstimate);
        }
Ejemplo n.º 12
0
        public void CanDeleteRequestEstimate()
        {
            // Establish Context
            var requestEstimateToDelete = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
            .Return(requestEstimateToDelete);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.Delete(1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldBeNull();
        }
Ejemplo n.º 13
0
        public void CanGetRequestEstimate()
        {
            // Establish Context
            RequestEstimate requestEstimateToExpect =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
            .Return(requestEstimateToExpect);

            // Act
            RequestEstimate requestEstimateRetrieved =
                _requestEstimateManagementService.Get(1);

            // Assert
            requestEstimateRetrieved.ShouldNotBeNull();
            requestEstimateRetrieved.ShouldEqual(requestEstimateToExpect);
        }
        public void CanDeleteRequestEstimate()
        {
            // Establish Context
            var requestEstimateToDelete = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
                .Return(requestEstimateToDelete);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.Delete(1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldBeNull();
        }
Ejemplo n.º 15
0
        protected bool SaveEstimate(Request request)
        {
            //Get the Latest Estimate
            var latestEstimate = _requestEstimateManagementService.GetLatestByRequest(request.Id);

            if (latestEstimate == null || latestEstimate.EstimatedHours != request.EstimatedHours)
            {
                //Save the New Estimate
                var estimate = new RequestEstimate();
                estimate.EstimatedHours = request.EstimatedHours;
                estimate.RequestId      = request.Id;
                if (!_requestEstimateManagementService.SaveOrUpdate(estimate).WasSuccessful)
                {
                    return(false);
                }
            }
            return(true);
        }
Ejemplo n.º 16
0
        public void CanCreateFormViewModelForRequestEstimate()
        {
            // Establish Context
            var viewModelToExpect = new RequestEstimateFormViewModel();

            RequestEstimate requestEstimate =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
            .Return(requestEstimate);

            // Act
            RequestEstimateFormViewModel viewModelRetrieved =
                _requestEstimateManagementService.CreateFormViewModelFor(1);

            // Assert
            viewModelRetrieved.ShouldNotBeNull();
            viewModelRetrieved.RequestEstimate.ShouldNotBeNull();
            viewModelRetrieved.RequestEstimate.ShouldEqual(requestEstimate);
        }
Ejemplo n.º 17
0
        public void CannotUpdateWithInvalidRequestEstimateFromForm()
        {
            // Establish Context
            var invalidRequestEstimateFromForm = new RequestEstimate();

            // Intentionally empty to ensure successful transfer of values
            var requestEstimateFromDb = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
            .Return(requestEstimateFromDb);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.UpdateWith(invalidRequestEstimateFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
        public ActionConfirmation SaveOrUpdate(RequestEstimate requestEstimate)
        {
            if (requestEstimate.IsValid())
            {
                _requestEstimateRepository.SaveOrUpdate(requestEstimate);

                ActionConfirmation saveOrUpdateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The requestEstimate was successfully saved.");
                saveOrUpdateConfirmation.Value = requestEstimate;

                return(saveOrUpdateConfirmation);
            }
            else
            {
                _requestEstimateRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The requestEstimate could not be saved due to missing or invalid information."));
            }
        }
        public void CanCreateValidRequestEstimateFromForm()
        {
            // Establish Context
            var requestEstimateFromForm = new RequestEstimate();
            var testUser = PersonInstanceFactory.CreateValidTransientPerson();
            testUser.SetAssignedIdTo(1);

            _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(r => r.GetByUserName(Arg<string>.Is.Anything)).Return(testUser);
            _requestEstimateManagementService.Expect(r => r.SaveOrUpdate(requestEstimateFromForm))
                .Return(ActionConfirmation.CreateSuccessConfirmation("saved"));

            // Act
            RedirectToRouteResult redirectResult =
                _requestEstimatesController.Create(requestEstimateFromForm)
                    .AssertActionRedirect().ToAction("Index");

            // Assert
            _requestEstimatesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString
                ()
                .ShouldEqual("saved");
        }
        public ActionConfirmation UpdateWith(RequestEstimate requestEstimateFromForm, int idOfRequestEstimateToUpdate)
        {
            RequestEstimate requestEstimateToUpdate =
                _requestEstimateRepository.Get(idOfRequestEstimateToUpdate);

            TransferFormValuesTo(requestEstimateToUpdate, requestEstimateFromForm);

            if (requestEstimateToUpdate.IsValid())
            {
                ActionConfirmation updateConfirmation = ActionConfirmation.CreateSuccessConfirmation(
                    "The requestEstimate was successfully updated.");
                updateConfirmation.Value = requestEstimateToUpdate;

                return(updateConfirmation);
            }
            else
            {
                _requestEstimateRepository.DbContext.RollbackTransaction();

                return(ActionConfirmation.CreateFailureConfirmation(
                           "The requestEstimate could not be saved due to missing or invalid information."));
            }
        }
Ejemplo n.º 21
0
        public void CanGetAllRequestEstimates()
        {
            // Establish Context
            IList <RequestEstimate> requestEstimatesToExpect = new List <RequestEstimate>();

            RequestEstimate requestEstimate =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            requestEstimatesToExpect.Add(requestEstimate);

            _requestEstimateRepository.Expect(r => r.GetAll())
            .Return(requestEstimatesToExpect);

            // Act
            IList <RequestEstimate> requestEstimatesRetrieved =
                _requestEstimateManagementService.GetAll();

            // Assert
            requestEstimatesRetrieved.ShouldNotBeNull();
            requestEstimatesRetrieved.Count.ShouldEqual(1);
            requestEstimatesRetrieved[0].ShouldNotBeNull();
            requestEstimatesRetrieved[0].ShouldEqual(requestEstimate);
        }
Ejemplo n.º 22
0
        public void CanUpdateWithValidRequestEstimateFromForm()
        {
            // Establish Context
            RequestEstimate validRequestEstimateFromForm =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            // Intentionally empty to ensure successful transfer of values
            var requestEstimateFromDb = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
            .Return(requestEstimateFromDb);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.UpdateWith(validRequestEstimateFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(requestEstimateFromDb);
            confirmation.Value.ShouldEqual(validRequestEstimateFromForm);
        }
        public void CanCreateValidRequestEstimateFromForm()
        {
            // Establish Context
            var requestEstimateFromForm = new RequestEstimate();
            var testUser = PersonInstanceFactory.CreateValidTransientPerson();

            testUser.SetAssignedIdTo(1);

            _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(r => r.GetByUserName(Arg <string> .Is.Anything)).Return(testUser);
            _requestEstimateManagementService.Expect(r => r.SaveOrUpdate(requestEstimateFromForm))
            .Return(ActionConfirmation.CreateSuccessConfirmation("saved"));

            // Act
            RedirectToRouteResult redirectResult =
                _requestEstimatesController.Create(requestEstimateFromForm)
                .AssertActionRedirect().ToAction("Index");

            // Assert
            _requestEstimatesController.TempData[ControllerEnums.GlobalViewDataProperty.PageMessage.ToString()].ToString
                ()
            .ShouldEqual("saved");
        }
        public void CannotUpdateInvalidRequestEstimateFromForm()
        {
            // Establish Context
            var requestEstimateFromForm = new RequestEstimate();
            var viewModelToExpect       = new RequestEstimateFormViewModel();
            var testUser = PersonInstanceFactory.CreateValidTransientPerson();

            testUser.SetAssignedIdTo(1);

            _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(r => r.GetByUserName(Arg <string> .Is.Anything)).Return(testUser);
            _requestEstimateManagementService.Expect(r => r.UpdateWith(requestEstimateFromForm, 0))
            .Return(ActionConfirmation.CreateFailureConfirmation("not updated"));
            _requestEstimateManagementService.Expect(r => r.CreateFormViewModelFor(requestEstimateFromForm))
            .Return(viewModelToExpect);

            // Act
            ViewResult result =
                _requestEstimatesController.Edit(requestEstimateFromForm).AssertViewRendered();

            // Assert
            result.ViewData.Model.ShouldNotBeNull();
            (result.ViewData.Model as RequestEstimateFormViewModel).ShouldNotBeNull();
        }
        public RequestEstimateFormViewModel CreateFormViewModelFor(int requestEstimateId)
        {
            RequestEstimate requestEstimate = _requestEstimateRepository.Get(requestEstimateId);

            return(CreateFormViewModelFor(requestEstimate));
        }
Ejemplo n.º 26
0
        public ActionResult Show(int id)
        {
            RequestEstimate requestEstimate = _requestEstimateManagementService.Get(id);

            return(View(requestEstimate));
        }
        public void CannotUpdateInvalidRequestEstimateFromForm()
        {
            // Establish Context
            var requestEstimateFromForm = new RequestEstimate();
            var viewModelToExpect = new RequestEstimateFormViewModel();
            var testUser = PersonInstanceFactory.CreateValidTransientPerson();
            testUser.SetAssignedIdTo(1);

            _authenticationProvider.Expect(r => r.GetLoggedInUser()).Return("testuser");
            _personManagementService.Expect(r => r.GetByUserName(Arg<string>.Is.Anything)).Return(testUser);
            _requestEstimateManagementService.Expect(r => r.UpdateWith(requestEstimateFromForm, 0))
                .Return(ActionConfirmation.CreateFailureConfirmation("not updated"));
            _requestEstimateManagementService.Expect(r => r.CreateFormViewModelFor(requestEstimateFromForm))
                .Return(viewModelToExpect);

            // Act
            ViewResult result =
                _requestEstimatesController.Edit(requestEstimateFromForm).AssertViewRendered();

            // Assert
            result.ViewData.Model.ShouldNotBeNull();
            (result.ViewData.Model as RequestEstimateFormViewModel).ShouldNotBeNull();
        }
        public void CannotSaveOrUpdateInvalidRequestEstimate()
        {
            // Establish Context
            var invalidRequestEstimate = new RequestEstimate();

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.SaveOrUpdate(invalidRequestEstimate);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
        public void CannotUpdateWithInvalidRequestEstimateFromForm()
        {
            // Establish Context
            var invalidRequestEstimateFromForm = new RequestEstimate();

            // Intentionally empty to ensure successful transfer of values
            var requestEstimateFromDb = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
                .Return(requestEstimateFromDb);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.UpdateWith(invalidRequestEstimateFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeFalse();
            confirmation.Value.ShouldBeNull();
        }
        public void CanUpdateWithValidRequestEstimateFromForm()
        {
            // Establish Context
            RequestEstimate validRequestEstimateFromForm =
                RequestEstimateInstanceFactory.CreateValidTransientRequestEstimate();

            // Intentionally empty to ensure successful transfer of values
            var requestEstimateFromDb = new RequestEstimate();

            _requestEstimateRepository.Expect(r => r.Get(1))
                .Return(requestEstimateFromDb);

            // Act
            ActionConfirmation confirmation =
                _requestEstimateManagementService.UpdateWith(validRequestEstimateFromForm, 1);

            // Assert
            confirmation.ShouldNotBeNull();
            confirmation.WasSuccessful.ShouldBeTrue();
            confirmation.Value.ShouldNotBeNull();
            confirmation.Value.ShouldEqual(requestEstimateFromDb);
            confirmation.Value.ShouldEqual(validRequestEstimateFromForm);
        }
Ejemplo n.º 31
0
 protected bool SaveEstimate(Request request)
 {
     //Get the Latest Estimate
     var latestEstimate = _requestEstimateManagementService.GetLatestByRequest(request.Id);
     if (latestEstimate == null || latestEstimate.EstimatedHours != request.EstimatedHours)
     {
         //Save the New Estimate
         var estimate = new RequestEstimate();
         estimate.EstimatedHours = request.EstimatedHours;
         estimate.RequestId = request.Id;
         if (!_requestEstimateManagementService.SaveOrUpdate(estimate).WasSuccessful)
         {
             return false;
         }
     }
     return true;
 }