public void When_MarkForDelete_Then_should_call_correct_methods() { // Given var request = new MarkHazardousSubstanceAsDeleteRequest() { CompanyId = 1, HazardousSubstanceId = 200, UserId = Guid.NewGuid() }; hazardousSubstanceRiskAssessmentRepository .Setup(x => x.DoesRiskAssessmentsExistForHazardousSubstance(request.HazardousSubstanceId, request.CompanyId)) .Returns(false); var user = new UserForAuditing(); userRepository .Setup(x => x.GetByIdAndCompanyId(request.UserId, request.CompanyId)) .Returns(user); var hazardousSubstance = new Mock<HazardousSubstance>(); hazardousSubstanceRepository .Setup(x => x.GetByIdAndCompanyId(request.HazardousSubstanceId, request.CompanyId)) .Returns(hazardousSubstance.Object); // When target.MarkForDelete(request); // Then hazardousSubstanceRiskAssessmentRepository.VerifyAll(); hazardousSubstance.Verify(x => x.MarkForDelete(user)); hazardousSubstanceRepository.Verify(x => x.SaveOrUpdate(hazardousSubstance.Object)); }
public void Given_hazardous_substance_used_in_risk_assessments_When_MarkForDelete_Then_should_throw_correct_exception() { // Given var request = new MarkHazardousSubstanceAsDeleteRequest() { CompanyId = 1, HazardousSubstanceId = 200, UserId = Guid.NewGuid() }; hazardousSubstanceRiskAssessmentRepository .Setup(x => x.DoesRiskAssessmentsExistForHazardousSubstance(request.HazardousSubstanceId, request.CompanyId)) .Returns(true); // When // Then Assert.Throws<TryingToDeleteHazardousSubstanceThatUsedByRiskAssessmentsException>(() => target.MarkForDelete(request)); }
public void MarkForDelete(MarkHazardousSubstanceAsDeleteRequest request) { bool riskAssessmentsExist = HasHazardousSubstanceGotRiskAssessments(request.HazardousSubstanceId, request.CompanyId); if (riskAssessmentsExist) { throw new TryingToDeleteHazardousSubstanceThatUsedByRiskAssessmentsException(request.HazardousSubstanceId); } var hazardousSubstance = _hazardousSubstancesRepository.GetByIdAndCompanyId(request.HazardousSubstanceId, request.CompanyId); var user = _userForAuditingRepository.GetByIdAndCompanyId(request.UserId, request.CompanyId); hazardousSubstance.MarkForDelete(user); _hazardousSubstancesRepository.SaveOrUpdate(hazardousSubstance); }