public void When_GetControlSystem_should_call_correct_methods()
        {
            // Given
            string hazardousSubstanceGroupCode = "AbcDef";
            MatterState? matterState = MatterState.Liquid;
            Quantity? quantity = Quantity.Medium;
            DustinessOrVolatility? dustinessOrVolatility = DustinessOrVolatility.High;
            var riskAssessmentId = 100L;
            var controlSystemDto = new ControlSystemDto
                                       {
                                           Id = 4L
                                       };

            var target = GetTarget();

            _controlSystemService
                .Setup(x => x.Calculate(hazardousSubstanceGroupCode, matterState, quantity, dustinessOrVolatility))
                .Returns(controlSystemDto);

            // When
            target.GetControlSystem(riskAssessmentId, hazardousSubstanceGroupCode, matterState, quantity, dustinessOrVolatility);

            // Then
            _controlSystemService.VerifyAll();
            _hazardousSubstanceRiskAssessmentService.Verify(x => x.SaveLastRecommendedControlSystem(It.Is<SaveLastRecommendedControlSystemRequest>(
                y => y.Id == riskAssessmentId &&
                     y.ControlSystemId == controlSystemDto.Id &&
                     y.UserId == target.CurrentUser.UserId
                )));
        }
        public void When_get_view_model_is_called_Then_correct_view_model_is_returned()
        {
            //Given
            const long companyId = 1234L;
            const long hazardousSubstanceRiskAssessmentId = 5678L;

            var hazardousSubstanceRiskAssessmentDto = new HazardousSubstanceRiskAssessmentDto
            {
                Id = 99L,
                MatterState = MatterState.Solid,
                Quantity = Quantity.Medium,
                DustinessOrVolatility = DustinessOrVolatility.Medium,
                Group = new HazardousSubstanceGroupDto { Id = 1L, Code = "A" },
                HazardousSubstance = new HazardousSubstanceDto(),
                CreatedOn = DateTime.Now
            };

            _hazardousSubstanceRiskAssessmentService
                .Setup(x => x.GetRiskAssessment(hazardousSubstanceRiskAssessmentId, companyId))
                .Returns(hazardousSubstanceRiskAssessmentDto);

            var controlSystemDto = new ControlSystemDto
                                       {
                                           Id = 98L,
                                           Description = "Test Control System",
                                           DocumentLibraryId = 1020L
                                       };

            _controlSystemService
                .Setup(x => x.Calculate(
                    hazardousSubstanceRiskAssessmentDto.Group.Code,
                    hazardousSubstanceRiskAssessmentDto.MatterState,
                    hazardousSubstanceRiskAssessmentDto.Quantity,
                    hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility))
                .Returns(controlSystemDto);

            var expectedUrlIn = "~/Documents/Document/DownloadPublicDocument?enc=" +
                              HttpUtility.UrlEncode(
                                  EncryptionHelper.Encrypt("documentLibraryId=" + controlSystemDto.DocumentLibraryId));

            var expectedUrlOut = "Test URL";

            _virtualPathUtilityWrapper
                .Setup(x => x.ToAbsolute(expectedUrlIn))
                .Returns(expectedUrlOut);

            // When
            var result = _target
                .WithCompanyId(companyId)
                .WithRiskAssessmentId(hazardousSubstanceRiskAssessmentId)
                .GetViewModel();

            // Then
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.MatterState, result.MatterState);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.Quantity, result.Quantity);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.DustinessOrVolatility, result.DustinessOrVolatility);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.Group.Code, result.HazardGroup);
            Assert.AreEqual(hazardousSubstanceRiskAssessmentDto.HealthSurveillanceRequired, result.HealthSurveillanceRequired);
            Assert.AreEqual(controlSystemDto.Description, result.WorkApproach);
            Assert.AreEqual(expectedUrlOut, result.Url);
        }