public void Given_FRA_review_when_completed_then_review_is_Completed() { // Given var fra = new FireRiskAssessment(); var fraReview = new Mock<RiskAssessmentReview>(); fra.AddReview( fraReview.Object); fra.FireRiskAssessmentChecklists.Add(new FireRiskAssessmentChecklist()); _userRepo.Setup(x => x.GetByIdAndCompanyId(It.IsAny<Guid>(), It.IsAny<long>())).Returns(new User {Id = Guid.NewGuid()}); _riskAssessmentRepo.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(fra); var target = new FireRiskAssessmentService(_riskAssessmentRepo.Object , _userForAuditingRepo.Object , _checklistRepository.Object , _questionRepo.Object , _documentParameterHelper.Object, _log.Object, null,_userRepo.Object, null, null); var request = new CompleteRiskAssessmentReviewRequest {ReviewingUserId = Guid.NewGuid(), ClientId = 123}; // When target.CompleteFireRiskAssessementReview(request); // Then fraReview.Verify(x => x.Complete(It.IsAny<string>(), It.IsAny<UserForAuditing>() , It.IsAny<DateTime?>() , It.IsAny<bool>() , It.IsAny<IList<CreateDocumentParameters>>(),It.IsAny<User>())); }
public void Given_a_valid_request_When_CompleteRiskAssessmentReview_called_Then_review_repo_asked_to_retrieve_associated_RiskAssessmentReview() { //Given var target = CreateRiskAssessmentReviewService(); var model = new CompleteRiskAssessmentReviewRequest() { RiskAssessmentReviewId = 1234, ClientId = 5678, NextReviewDate = DateTime.Now }; var riskAssessmentReview = new RiskAssessmentReview { RiskAssessmentReviewTask = new RiskAssessmentReviewTask(), RiskAssessment = new GeneralRiskAssessment() }; _riskAssessmentReviewRepo .Setup(x => x.GetByIdAndCompanyId(1234, 5678)) .Returns(riskAssessmentReview); //When target.CompleteRiskAssessementReview(model); //Then _riskAssessmentReviewRepo.Verify(x => x.GetByIdAndCompanyId(model.RiskAssessmentReviewId, model.ClientId), Times.Once()); }
public void CompleteRiskAssessementReview(CompleteRiskAssessmentReviewRequest request) { _log.Add(request); var riskAssessmentReview = _riskAssessmentReviewRepository.GetByIdAndCompanyId(request.RiskAssessmentReviewId, request.ClientId); var reviewingUser = _auditedUserRepository.GetByIdAndCompanyId(request.ReviewingUserId, request.ClientId); var completingUser = _userRepository.GetByIdAndCompanyId(request.ReviewingUserId, request.ClientId); var createDocumentParameterObjects = _documentParameterHelper.GetCreateDocumentParameters(request.CreateDocumentRequests, request.ClientId).ToList(); riskAssessmentReview.Complete( request.CompletedComments, reviewingUser, request.NextReviewDate, request.Archive, createDocumentParameterObjects, completingUser); _riskAssessmentReviewRepository.SaveOrUpdate(riskAssessmentReview); }
public void Given_a_valid_request_When_CompleteRiskAssessmentReview_called_Then_review_repo_asked_to_update_associated_RiskAssessmentReview() { //Given var passedRiskAssessmentReview = new RiskAssessmentReview { RiskAssessmentReviewTask = new RiskAssessmentReviewTask(), RiskAssessment = new GeneralRiskAssessment() }; _riskAssessmentReviewRepo .Setup(x => x.GetByIdAndCompanyId(1234, 5678)) .Returns(passedRiskAssessmentReview); _riskAssessmentReviewRepo.Setup(x => x.SaveOrUpdate(It.IsAny<RiskAssessmentReview>())).Callback <RiskAssessmentReview>(y => passedRiskAssessmentReview = y); var target = CreateRiskAssessmentReviewService(); var model = new CompleteRiskAssessmentReviewRequest() { RiskAssessmentReviewId = 1234, ClientId = 5678, CompletedComments = "some comments", IsComplete = true, ReviewingUserId = Guid.NewGuid(), NextReviewDate = DateTime.Now, Archive = false }; //When target.CompleteRiskAssessementReview(model); //Then _riskAssessmentReviewRepo.Verify(x => x.SaveOrUpdate(It.IsAny<RiskAssessmentReview>()), Times.Once()); Assert.That(passedRiskAssessmentReview.Comments, Is.EqualTo(model.CompletedComments)); }
public void When_documents_attached_pass_to_entity() { //Given List<CreateDocumentParameters> passedCreateDocumentParameters = null; var mockRiskAssessmentReview = new Mock<RiskAssessmentReview>(); mockRiskAssessmentReview.Object.RiskAssessmentReviewTask = new RiskAssessmentReviewTask(); mockRiskAssessmentReview .Setup(x => x.Complete( It.IsAny<string>(), It.IsAny<UserForAuditing>(), It.IsAny<DateTime?>(), It.IsAny<bool>(), It.IsAny<List<CreateDocumentParameters>>(), It.IsAny<User>() )) .Callback<string, UserForAuditing, DateTime?, bool, IList<CreateDocumentParameters>,User>( (a, b, c, d, e,f) => passedCreateDocumentParameters = e.ToList() ); _riskAssessmentReviewRepo .Setup(x => x.GetByIdAndCompanyId( It.IsAny<long>(), It.IsAny<long>())) .Returns(mockRiskAssessmentReview.Object); const long companyId = 61889L; var returnedCreateDocumentParams = new CreateDocumentParameters() { ClientId = companyId, CreatedOn = DateTime.Today, CreatedBy = new UserForAuditing(), Description = "description", DocumentLibraryId = 1, DocumentOriginType = DocumentOriginType.TaskCreated, DocumentType = new DocumentType(), Extension = ".biz", Filename = "filename", FilesizeByte = 12345 }; _documentParameterHelper.Setup( x => x.GetCreateDocumentParameters(It.IsAny<List<CreateDocumentRequest>>(), It.IsAny<long>())) .Returns(new List<CreateDocumentParameters>() { returnedCreateDocumentParams }); var createDocumentsRequests = new List<CreateDocumentRequest>() { new CreateDocumentRequestBuilder() .WithCompanyId(companyId) .WithDocumentLibraryId(33L) .WithDocumentOriginTypeId(DocumentOriginType.TaskCompleted) .WithDocumentType(DocumentTypeEnum.GRAReview) .WithFilename("my filename.docx") .WithSiteId(12L) .Build() }; var model = new CompleteRiskAssessmentReviewRequest() { RiskAssessmentReviewId = 1234L, ClientId = companyId, CompletedComments = "comments", NextReviewDate = DateTime.Now, Archive = false, CreateDocumentRequests = createDocumentsRequests }; var target = CreateRiskAssessmentReviewService(); //When target.CompleteRiskAssessementReview(model); //Then mockRiskAssessmentReview.Verify(x => x.Complete(model.CompletedComments, It.IsAny<UserForAuditing>(), model.NextReviewDate, model.Archive, It.IsAny<IList<CreateDocumentParameters>>(), It.IsAny<User>()), Times.Once()); Assert.That(passedCreateDocumentParameters[0], Is.EqualTo(returnedCreateDocumentParams)); _documentParameterHelper.Verify(x => x.GetCreateDocumentParameters(It.IsAny<List<CreateDocumentRequest>>(), It.IsAny<long>())); }
public void Given_a_valid_request_When_CompleteRiskAssessmentReview_called_Then_entity_asked_to_complete_itself() { //Given var mockRiskAssessmentReview = new Mock<RiskAssessmentReview>(); mockRiskAssessmentReview.Object.RiskAssessmentReviewTask = new RiskAssessmentReviewTask(); mockRiskAssessmentReview.Setup(x => x.Complete(It.IsAny<string>(), It.IsAny<UserForAuditing>(), It.IsAny<DateTime?>(), It.IsAny<bool>(), null, It.IsAny<User>())); _riskAssessmentReviewRepo.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(mockRiskAssessmentReview.Object); var target = CreateRiskAssessmentReviewService(); var model = new CompleteRiskAssessmentReviewRequest() { RiskAssessmentReviewId = 1234, ClientId = 5678, CompletedComments = "comments", NextReviewDate = DateTime.Now, Archive = false }; //When target.CompleteRiskAssessementReview(model); //Then mockRiskAssessmentReview.Verify(x => x.Complete(model.CompletedComments, It.IsAny<UserForAuditing>(), model.NextReviewDate, model.Archive, It.IsAny<List<CreateDocumentParameters>>(),It.IsAny<User>()), Times.Once()); }
public void CompleteFireRiskAssessementReview(CompleteRiskAssessmentReviewRequest request) { var reviewingUser = _auditedUserRepository.GetByIdAndCompanyId(request.ReviewingUserId, request.ClientId); var completingUser = _userForAuditingRepository.GetByIdAndCompanyId(request.ReviewingUserId,request.ClientId); var createDocumentParameterObjects = _documentParameterHelper.GetCreateDocumentParameters(request.CreateDocumentRequests, request.ClientId).ToList(); var fireRiskAss = _fireRiskAssessmentRepository.GetByIdAndCompanyId(request.RiskAssessmentId, request.ClientId); fireRiskAss.Reviews .First(x => x.Id == request.RiskAssessmentReviewId) .Complete(request.CompletedComments, reviewingUser, request.NextReviewDate, request.Archive, createDocumentParameterObjects, completingUser); var replacementChecklist = fireRiskAss.LatestFireRiskAssessmentChecklist.CopyWithYesAnswers(reviewingUser); fireRiskAss.FireRiskAssessmentChecklists.Add(replacementChecklist); _fireRiskAssessmentRepository.SaveOrUpdate(fireRiskAss); }
public void Given_that_complete_is_called_When_required_fields_are_supplied_Then_current_user_is_added_to_request_model() { //Given var target = GetTarget(); var validModel = new CompleteReviewViewModel() { CompanyId = 123, RiskAssessmentId = 456, RiskAssessmentReviewId = 789, IsComplete = true, CompletedComments = "complete", NextReviewDate = DateTime.Today, RiskAssessmentType = RiskAssessmentType.GRA }; var modelPassedToService = new CompleteRiskAssessmentReviewRequest(); _riskAssessmentReviewService .Setup(x => x.CompleteRiskAssessementReview(It.IsAny<CompleteRiskAssessmentReviewRequest>())) .Callback<CompleteRiskAssessmentReviewRequest>(y => modelPassedToService = y); //When target.Complete(validModel); //Then _riskAssessmentReviewService.VerifyAll(); Assert.That(modelPassedToService.ReviewingUserId.ToString(), Is.Not.EqualTo("00000000-0000-0000-0000-000000000000")); }