public void Given_user_without_permissions_When_IsSaveEnabled_Then_returns_correct_result()
        {
            // Arrange
            var user = new Mock<ICustomPrincipal>();
            user.Setup(x => x.IsInRole(It.IsAny<string>())).Returns(false);

            // Act
            var result = new DescriptionViewModel().IsSaveButtonEnabled(user.Object);

            // Assert
            Assert.False(result);
        }
        public JsonResult SaveAndNext(DescriptionViewModel model)
        {
            try
            {
                UpdateRiskAssessment(model);

                return Json(new { Success = true });
            }
            catch (ValidationException validationException)
            {
                ModelState.AddValidationErrors(validationException);

                return ModelStateErrorsAsJson();
            }
        }
        public ActionResult Save(DescriptionViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return View("Index", viewModel);
            }

            try
            {
                UpdateRiskAssessment(viewModel);
            }
            catch (ValidationException validationException)
            {
                ModelState.AddValidationErrors(validationException);
                return View("Index", viewModel);
            }
            
            TempData["Notice"] = "Description Information Successfully Saved";
            return RedirectToAction("Index", new { riskAssessmentId = viewModel.RiskAssessmentId, companyId = viewModel.CompanyId });
        }
Esempio n. 4
0
        public void Given_valid_request_When_save_is_called_Then_should_call_the_correct_methods()
        {
            //Given
            var target = CreateController();
            var request = new DescriptionViewModel()
                              {
                                  CompanyId = _companyId,
                                  RiskAssessmentId = _riskAssessmentId
                              };

            //When
            target.Save(request);

            //Then
            _hazardousSubstanceRiskAssessmentService
                .Verify(x => x.UpdateRiskAssessmentDescription(It.Is<SaveHazardousSubstanceRiskAssessmentRequest>(r => 
                                                                                                       r.CompanyId == request.CompanyId && 
                                                                                                       r.Id == request.RiskAssessmentId && 
                                                                                                       r.UserId == target.CurrentUser.UserId)));

        }
Esempio n. 5
0
        public void Given_service_encouters_validation_exception_When_save_is_called_Then_should_return_correct_result()
        {
            //Given
            var target = CreateController();
            var viewModel = new DescriptionViewModel()
            {
                CompanyId = _companyId,
                RiskAssessmentId = _riskAssessmentId
            };

            var failures = new List<ValidationFailure>();
            _hazardousSubstanceRiskAssessmentService
                .Setup(x => x.UpdateRiskAssessmentDescription(It.IsAny<SaveHazardousSubstanceRiskAssessmentRequest>()))
                .Throws(new ValidationException(failures));

            //When
            var result = target.Save(viewModel) as ViewResult;

            //Then
            Assert.That(result.ViewName, Is.EqualTo("Index"));
            var returnedViewModel = result.Model as DescriptionViewModel;
            Assert.That(returnedViewModel, Is.EqualTo(viewModel));
        }
Esempio n. 6
0
        public void Given_valid_request_Then_risk_assessment_is_saved_and_redirected_to_correct_view()
        {
            //Given
            var target = CreateController();

            var request = new DescriptionViewModel()
            {
                CompanyId = _companyId,
                RiskAssessmentId = _riskAssessmentId
            };
            
            //When
            var result = target.Save(request) as RedirectToRouteResult;

            //Then
            Assert.That(target.TempData["Notice"], Is.Not.Null);
            Assert.That(result.RouteValues["controller"], Is.Null);
            Assert.That(result.RouteValues["action"], Is.EqualTo("Index"));
            Assert.That(result.RouteValues["riskAssessmentId"], Is.EqualTo(request.RiskAssessmentId));
            Assert.That(result.RouteValues["CompanyId"], Is.EqualTo(request.CompanyId));

        }
 private void UpdateRiskAssessment(DescriptionViewModel viewModel)
 {
     _hazardousSubstanceRiskAssessmentService.UpdateRiskAssessmentDescription(new SaveHazardousSubstanceRiskAssessmentRequest
                                                                       {
                                                                           CompanyId = viewModel.CompanyId,
                                                                           Id = viewModel.RiskAssessmentId,
                                                                           UserId = CurrentUser.UserId,
                                                                           IsInhalationRouteOfEntry = viewModel.IsInhalationRouteOfEntry,
                                                                           IsIngestionRouteOfEntry = viewModel.IsIngestionRouteOfEntry,
                                                                           IsAbsorptionRouteOfEntry = viewModel.IsAbsorptionRouteOfEntry,
                                                                           WorkspaceExposureLimits = viewModel.WorkspaceExposureLimits,
                                                                           HazardousSubstanceId = viewModel.HazardousSubstanceId
                                                                       });
 }