public void Given_valid_request_no_existing_risk_assessments_with_matching_references_When_CreateRiskAssessment_Then_should_call_correct_methods() { //Given var riskAssessmentService = GetTarget(); var request = new SaveHazardousSubstanceRiskAssessmentRequestBuilder().WithTitle("Test").Build(); request.Title = "the title"; request.Reference = "the reference"; _riskAssessmentRepository .Setup(x => x.DoesAssessmentExistWithTheSameReference<HazardousSubstanceRiskAssessment>(request.CompanyId, request.Reference, It.IsAny<long?>()) ). Returns(false); //No longer being used. PTD 05/09/13 //_riskAssessmentRepository // .Setup(x => x.DoesAssessmentExistWithTheSameTitle<HazardousSubstanceRiskAssessment>(request.CompanyId, request.Title, It.IsAny<long?>())). // Returns(false); _hazardousSubstanceAssessmentRepository.Setup(rr => rr.SaveOrUpdate(It.IsAny<HazardousSubstanceRiskAssessment>())); //When riskAssessmentService.CreateRiskAssessment(request); //Then _riskAssessmentRepository.VerifyAll(); }
public static SaveHazardousSubstanceRiskAssessmentRequestBuilder Create() { var saveRiskAssessmentRequestBuilder = new SaveHazardousSubstanceRiskAssessmentRequestBuilder(); _title = "title"; _reference = "reference"; _assessmentDate = DateTime.Now; return saveRiskAssessmentRequestBuilder; }
public void Given_valid_request_with_existing_risk_assessments_which_match_references_When_CreateRiskAssessment_Then_should_throw_correct_exception() { //Given var riskAssessmentService = GetTarget(); var request = new SaveHazardousSubstanceRiskAssessmentRequestBuilder().WithTitle("Test").Build(); request.Reference = "reference"; _riskAssessmentRepository .Setup(x => x.DoesAssessmentExistWithTheSameReference<HazardousSubstanceRiskAssessment>(request.CompanyId, request.Reference, It.IsAny<long?>())). Returns(true); _riskAssessmentRepository .Setup(ra => ra.DoesAssessmentExistWithTheSameReference<HazardousSubstanceRiskAssessment>(request.CompanyId, request.Reference, It.IsAny<long?>())) .Returns(true); //When //Then Assert.Throws<ValidationException>(() => riskAssessmentService.CreateRiskAssessment(request)); }
public void Given_valid_request_When_UpdateRiskAssessmentDescription_Then_should_call_Update_on_RiskAssessment() { //Given var riskAssessmentService = GetTarget(); var request = new SaveHazardousSubstanceRiskAssessmentRequestBuilder() .Build(); _userRepository .Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId)) .Returns(_user); var mockRiskAssessment = new Mock<HazardousSubstanceRiskAssessment>(); mockRiskAssessment.Setup(x => x.Update( It.IsAny<UserForAuditing>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<bool>(), It.IsAny<string>() )); _hazardousSubstanceAssessmentRepository .Setup(x => x.GetByIdAndCompanyId(request.Id, request.CompanyId)). Returns(() => mockRiskAssessment.Object); //When riskAssessmentService.UpdateRiskAssessmentDescription(request); //Then mockRiskAssessment.Verify(x => x.Update( _user, request.IsInhalationRouteOfEntry, request.IsIngestionRouteOfEntry, request.IsAbsorptionRouteOfEntry, request.WorkspaceExposureLimits )); }
public void Given_valid_request_selected_hazardous_substance_id_is_passed_to_repo() { //Given var riskAssessmentService = GetTarget(); var request = new SaveHazardousSubstanceRiskAssessmentRequestBuilder().WithTitle("Test").WithHazardousSubstanceId(1234).Build(); var passedHazardousSubstanceRiskAssessment = new HazardousSubstanceRiskAssessment(); _riskAssessmentRepository .Setup(x => x.DoesAssessmentExistWithTheSameReference<HazardousSubstanceRiskAssessment>(request.CompanyId, request.Reference, It.IsAny<long?>())). Returns(false); _hazardousSubstanceAssessmentRepository .Setup(rr => rr.SaveOrUpdate(It.IsAny<HazardousSubstanceRiskAssessment>())) .Callback<HazardousSubstanceRiskAssessment>(y => passedHazardousSubstanceRiskAssessment = y); _hazardousSubstanceRepository .Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())) .Returns(new HazardousSubstance() { Id = 1234 }); //When riskAssessmentService.CreateRiskAssessment(request); //Then Assert.That(passedHazardousSubstanceRiskAssessment.HazardousSubstance.Id, Is.EqualTo(request.HazardousSubstanceId)); }