public PremisesInformationViewModel GetViewModel(PremisesInformationViewModel viewModel)
 {
     var riskAssessment = _riskAssessmentService.GetRiskAssessment(viewModel.RiskAssessmentId, viewModel.CompanyId, _currentUserId);
     viewModel.NonEmployees = riskAssessment.NonEmployees != null ? GetNonEmployees(riskAssessment.NonEmployees) : new List<Tuple<long, string>>();
     viewModel.Employees = riskAssessment.Employees != null ? GetEmployees(riskAssessment.Employees) : new List<Tuple<Guid, string>>();
    return viewModel;
 }
示例#2
0
        public void Setup()
        {
            _viewModel = new PremisesInformationViewModel();

            _premisesInformationViewModelFactory = new Mock<IPremisesInformationViewModelFactory>();

            _target = GetTarget();
            _currentUserId = _target.CurrentUser.UserId;

            _premisesInformationViewModelFactory
                .Setup(x => x.WithCompanyId(_companyId))
                .Returns(_premisesInformationViewModelFactory.Object);

            _premisesInformationViewModelFactory
                .Setup(x => x.WithRiskAssessmentId(_riskAssessmentId))
                .Returns(_premisesInformationViewModelFactory.Object);

            _premisesInformationViewModelFactory
                .Setup(x => x.WithCurrentUserId(_currentUserId))
                .Returns(_premisesInformationViewModelFactory.Object);

            _premisesInformationViewModelFactory
                .Setup(x => x.GetViewModel())
                .Returns(_viewModel);
        }
示例#3
0
        public void Given_invalid_viewmodel_When_Save_called_Then_should_return_correct_result()
        {
            // Arrange
            var target = GetTarget();

            target.ModelState.AddModelError("Anything", "Anything");
            
            _premisesInformationViewModelFactory
               .Setup(x => x.WithCompanyId(_viewModel.CompanyId))
               .Returns(_premisesInformationViewModelFactory.Object);

            var currentUserId = target.CurrentUser.UserId;
            _premisesInformationViewModelFactory
                .Setup(x => x.WithCurrentUserId(currentUserId))
                .Returns(_premisesInformationViewModelFactory.Object);

            var expectedViewModel = new PremisesInformationViewModel();
            _premisesInformationViewModelFactory
                .Setup(x => x.GetViewModel(_viewModel))
                .Returns(expectedViewModel);

            // Act
            var result = target.Save(_viewModel) as ViewResult;

            // Assert
            Assert.That(result.Model, Is.EqualTo(expectedViewModel));
            Assert.That(result.ViewName, Is.EqualTo("Index"));
        }
示例#4
0
        public void Setup()
        {
            _viewModel = new PremisesInformationViewModel();

            _premisesInformationViewModelFactory = new Mock<IPremisesInformationViewModelFactory>();
            _riskAssessmentService = new Mock<IMultiHazardRiskAssessmentService>();

        }
 private void UpdateRiskAssessment(PremisesInformationViewModel request)
 {
     _riskAssessmentService.UpdateRiskAssessmentPremisesInformation(new SaveRiskAssessmentPremisesInformationRequest
     {
         CompanyId = request.CompanyId,
         Id = request.RiskAssessmentId,
         LocationAreaDepartment = request.LocationAreaDepartment,
         TaskProcessDescription = request.TaskProcessDescription,
         UserId = CurrentUser.UserId
     });
 }
 public ActionResult Save(PremisesInformationViewModel viewModel)
 {
     if (!ModelState.IsValid)
     {
         var premisesInformationViewModel = _premisesInformationViewModelFactory
                                                 .WithCompanyId(viewModel.CompanyId)
                                                 .WithCurrentUserId(CurrentUser.UserId)
                                                 .GetViewModel(viewModel);
         return View("Index", premisesInformationViewModel);
     }
     
     UpdateRiskAssessment(viewModel);
    
     TempData["Notice"] = "Premises Information Successfully Saved";
     return RedirectToAction("Index", new { riskAssessmentId = viewModel.RiskAssessmentId, companyId = viewModel.CompanyId });
 }
 public PremisesInformationViewModel GetViewModel()
 {
     var riskAssessment = _riskAssessmentService.GetRiskAssessment(_riskAssessmentId, _companyId, _currentUserId);
     
     var viewModel = new PremisesInformationViewModel()
                         {
                             CompanyId = _companyId,
                             RiskAssessmentId = _riskAssessmentId,
                             NonEmployees = riskAssessment.NonEmployees != null ? GetNonEmployees(riskAssessment.NonEmployees) : new List<Tuple<long, string>>(),
                             Employees = riskAssessment.Employees != null ? GetEmployees(riskAssessment.Employees) : new List<Tuple<Guid, string>>(),
                             LocationAreaDepartment = riskAssessment.Location,
                             TaskProcessDescription = riskAssessment.TaskProcessDescription
                         };
     
     return viewModel;
 }
        public void Given_that_save_and_next_is_called_when_valid_Then_should_call_correct_methods()
        {
            //Given
            var target = GetTarget();

            var request = new PremisesInformationViewModel()
                              {
                                  RiskAssessmentId = 100,
                                  CompanyId = 200,
                                  LocationAreaDepartment = "Test Location",
                                  TaskProcessDescription = "Test Task"
                              };

            //When
            target.SaveAndNext(request);

            //Then
            _riskAssessmentService.Verify(x => x.UpdateRiskAssessmentPremisesInformation(It.IsAny<SaveRiskAssessmentPremisesInformationRequest>()), Times.Once());
        }
        public void When_post_to_save_next_Then_should_return_correct_result()
        {
            //Given
            var target = GetTarget();
            var request = new PremisesInformationViewModel()
                              {
                                  RiskAssessmentId = 100,
                                  CompanyId = 200,
                                  LocationAreaDepartment = "Test Location",
                                  TaskProcessDescription = "Test Task"
                              };

            //When
            var result = target.SaveAndNext(request) as JsonResult;

            //Then
            // Assert
            dynamic data = result.Data;
            Assert.That(data.ToString(), Contains.Substring("Success = True"));

        }
        public JsonResult SaveAndNext(PremisesInformationViewModel request)
        {
            UpdateRiskAssessment(request);

            return Json(new { Success = true });
        }
        public void Given_factory_takes_viewmodel_When_GetViewModel_Then_should_call_the_correct_result()
        {
            // Given
            var target = GetTarget();

            var riskAssessment = new PersonalRiskAssessmentDto()
            {
                CompanyId = _companyId,
                Id = _riskAssessmentId,
                Employees = new[]
                                {
                                    new RiskAssessmentEmployeeDto{ Employee = new EmployeeDto() }
                                },
                NonEmployees = new[]
                                   {
                                       new RiskAssessmentNonEmployeeDto{ NonEmployee = new NonEmployeeDto() }
                                   },
            };

            var viewModel = new PremisesInformationViewModel()
            {
                RiskAssessmentId = _riskAssessmentId,
                CompanyId = _companyId,
                TaskProcessDescription = "Test Task",
                LocationAreaDepartment = "Test Location"
            };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(viewModel.RiskAssessmentId, viewModel.CompanyId, _currentUserId))
                .Returns(riskAssessment);
            
            // When
            var result = target
                                .WithCompanyId(_companyId)
                                .WithRiskAssessmentId(_riskAssessmentId)
                                .WithCurrentUserId(_currentUserId)
                                .GetViewModel(viewModel);

            // Then
            Assert.That(result.CompanyId, Is.EqualTo(_companyId));
            Assert.That(result.RiskAssessmentId, Is.EqualTo(_riskAssessmentId));
            Assert.That(result.Employees.Count(), Is.EqualTo(riskAssessment.Employees.Count()));
            Assert.That(result.NonEmployees.Count(), Is.EqualTo(riskAssessment.NonEmployees.Count()));
            Assert.That(result.LocationAreaDepartment, Is.EqualTo(viewModel.LocationAreaDepartment));
            Assert.That(result.TaskProcessDescription, Is.EqualTo(viewModel.TaskProcessDescription));
        }
        public void Given_factory_takes_viewmodel_When_GetViewModel_Then_should_call_the_correct_methods()
        {
            // Given
            var target = GetTarget();

            var riskAssessment = new PersonalRiskAssessmentDto()
            {
                CompanyId = _companyId,
                Id = _riskAssessmentId,
                NonEmployees = new RiskAssessmentNonEmployeeDto[] { },
                Employees = new RiskAssessmentEmployeeDto[] { },
                RiskAssessmentSite = new SiteDto()
            };

            var viewModel = new PremisesInformationViewModel()
                                {
                                    RiskAssessmentId = _riskAssessmentId,
                                    CompanyId = _companyId
                                };

            _riskAssessmentService
                .Setup(x => x.GetRiskAssessment(viewModel.RiskAssessmentId, viewModel.CompanyId, _currentUserId))
                .Returns(riskAssessment);
            
            // When
            target
                .WithCompanyId(viewModel.CompanyId)
                .WithRiskAssessmentId(viewModel.RiskAssessmentId)
                .WithCurrentUserId(_currentUserId)
                .GetViewModel(viewModel);

            // Then
            _riskAssessmentService.VerifyAll();
        }