public ActionTaskDto MapWithAssignedTo(ActionTask entity) { var dto = new ActionTaskDto(); dto = PopulateTaskDto(entity, dto) as ActionTaskDto; dto.Action = entity.Action != null ? new ActionDtoMapper().Map(entity.Action) : null; return dto; }
public void given_action_id_and_company_id_when_get_view_model_then_existing_documents_are_returned() { //given var companyId = 123L; var actionId = 1L; var target = GetTarget(); var assignedTo = new EmployeeDto { Id = Guid.NewGuid(), FullName = "employee'" }; var task = new ActionTaskDto { Id = 1L, Title = "Title", Description = "Description", TaskAssignedTo = assignedTo }; var action = new ActionDto { Id = actionId, ActionTasks = new List<ActionTaskDto> { task }, }; _actionService .Setup(x => x.GetByIdAndCompanyId( actionId, companyId )) .Returns(action); ExistingDocumentsViewModel existingDocumentsViewModel = new ExistingDocumentsViewModel(); existingDocumentsViewModel.PreviouslyAddedDocuments = new List<PreviouslyAddedDocumentGridRowViewModel>(); PreviouslyAddedDocumentGridRowViewModel padGridRowViewModel = new PreviouslyAddedDocumentGridRowViewModel(); padGridRowViewModel.Id = 1234L; padGridRowViewModel.Filename = "somefilename.doc"; padGridRowViewModel.Description = ""; padGridRowViewModel.DocumentLibraryId = 765L; padGridRowViewModel.DocumentOriginType = DocumentOriginType.TaskUpdated; padGridRowViewModel.DocumentTypeName = "somedocumenttype"; existingDocumentsViewModel.PreviouslyAddedDocuments.Add(padGridRowViewModel); _existingDocumentsViewModelFactory .Setup(x => x.GetViewModel(It.IsAny<IEnumerable<TaskDocumentDto>>())) .Returns(existingDocumentsViewModel); var result = target .WithCompanyId(companyId) .WithActionId(actionId) .GetViewModel(); // then Assert.IsNotNull(result.ExistingDocuments); Assert.IsNotNull(result.ExistingDocuments.PreviouslyAddedDocuments); Assert.AreEqual( 1, result.ExistingDocuments.PreviouslyAddedDocuments.Count); Assert.AreEqual(padGridRowViewModel.Id, result.ExistingDocuments.PreviouslyAddedDocuments[0].Id); //Assert.AreEqual( DocumentTypeEnum.Action, result.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentTypeName); Assert.AreEqual(DocumentOriginType.TaskUpdated, result.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentOriginType); }
public void Given_SendTaskNofication_is_false_then_DoNotSendTaskAssignedNotification_equals_true() { //given var assignedTo = new EmployeeDto { Id = Guid.NewGuid(), FullName = "employee'" }; var task = new ActionTaskDto { Id = 1L, Title = "Title", Description = "Description", TaskAssignedTo = assignedTo, SendTaskNotification = false }; var action = new ActionDto { Id = 234234, ActionTasks = new List<ActionTaskDto> { task } }; var target = GetTarget(); _actionService. Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())). Returns(action); //when var result = target .WithCompanyId(123) .WithActionId(1123) .GetViewModel(); //then Assert.That(result.DoNotSendTaskAssignedNotification, Is.EqualTo(true)); }
public void given_company_id_when_get_view_model_then_get_viewmodel_maps_corect_result() { //given var companyId = 123L; var actionPlanId = 1231L; var actionId = 1L; var assignedTo = new EmployeeDto { Id = Guid.NewGuid(), FullName = "employee'" }; var task = new ActionTaskDto { Id = 1L, Title = "Title", Description = "Description", TaskAssignedTo = assignedTo }; var action = new ActionDto { Id = actionId, ActionTasks = new List<ActionTaskDto> { task }, GuidanceNote = "1.1" }; var target = GetTarget(); _actionService. Setup(x => x.GetByIdAndCompanyId(It.Is<long>(a => a == actionId), It.Is<long>(c => c == companyId))). Returns(action); //when var result = target .WithCompanyId(companyId) .WithActionPlanId(actionPlanId) .WithActionId(actionId) .GetViewModel(); //then Assert.That(result.ActionPlanId, Is.EqualTo(actionPlanId)); Assert.That(result.ActionId, Is.EqualTo(action.Id)); Assert.That(result.CompanyId, Is.EqualTo(companyId)); Assert.That(result.Title, Is.EqualTo(task.Title)); Assert.That(result.Description, Is.EqualTo(task.Description)); Assert.That(result.GuidanceNotes, Is.EqualTo(action.GuidanceNote)); Assert.That(result.DueDate, Is.EqualTo(task.TaskCompletionDueDate)); Assert.That(result.ActionTaskAssignedTo, Is.EqualTo(task.TaskAssignedTo.FullName)); Assert.That(result.ActionTaskAssignedToId, Is.EqualTo(task.TaskAssignedTo.Id)); }
public void given_factory_when_get_view_model_then_result_maps_ActionTaskDto_to_viewmodel() { //given IViewActionTaskViewModelFactory viewActionTaskViewModelFactory = new ViewActionTaskViewModelFactory(_actionTaskService.Object, _existingDocumentsViewModelFactory.Object); var actionTaskDto = new ActionTaskDto() { Site = new SiteDto() {}, Action = new ActionDto() { Reference = "123ref", AreaOfNonCompliance = " area of non compliance", ActionRequired = "aciont required", GuidanceNote = "guidance note", TargetTimescale = "timescale", AssignedTo = Guid.NewGuid(), DueDate = DateTime.Now, Status = DerivedTaskStatusForDisplay.None, Category = ActionCategory.Action }, SendTaskNotification = true, SendTaskCompletedNotification = true, SendTaskOverdueNotification = true }; var target = GetTarget(viewActionTaskViewModelFactory); _actionTaskService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())) .Returns( actionTaskDto); //when var result = target.WithCompanyId(_companyId).WithActionTaskId(_actionTaskId).GetViewModel(); //then Assert.That(result.ActionTaskId, Is.EqualTo(_actionTaskId), "Action task id not mapped"); Assert.That(result.CompanyId, Is.EqualTo(_companyId), "Company id not mapped"); Assert.That(result.ActionTask.ActionSummary.AreaOfNonCompliance, Is.EqualTo(actionTaskDto.Action.AreaOfNonCompliance), "Area of non-compliance not mapped"); Assert.That(result.ActionTask.DoNotSendTaskAssignedNotification,Is.EqualTo(!actionTaskDto.SendTaskNotification)); Assert.That(result.ActionTask.DoNotSendTaskCompletedNotification, Is.EqualTo(!actionTaskDto.SendTaskCompletedNotification)); Assert.That(result.ActionTask.DoNotSendTaskOverdueNotification, Is.EqualTo(!actionTaskDto.SendTaskOverdueNotification)); }
public TaskDto MapWithAssignedTo(Task entity) { TaskDto dto = null; if (entity.Self as ResponsibilityTask != null) { var responsibilityTask = (ResponsibilityTask) entity; dto = new ResponsibilityTaskDto() { Responsibility = new ResponsibilityDto() { Id = responsibilityTask.Responsibility.Id, Title = responsibilityTask.Responsibility.Title, Description = responsibilityTask.Responsibility.Description } }; } if (entity.Self as ActionTask != null) { dto = new ActionTaskDto(); } if (entity.Self as RiskAssessmentReviewTask != null) { dto = new RiskAssessmentReviewTaskDto(); } if (entity.Self as MultiHazardRiskAssessmentFurtherControlMeasureTask != null) { if (entity.RiskAssessment.Self is GeneralRiskAssessment) { dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.GRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } if (entity.RiskAssessment.Self is PersonalRiskAssessment) { dto = new MultiHazardRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.PRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } } if (entity.Self as HazardousSubstanceRiskAssessmentFurtherControlMeasureTask != null) { dto = new HazardousSubstanceRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.HSRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } if (entity.Self as FireRiskAssessmentFurtherControlMeasureTask != null) { dto = new FireRiskAssessmentFurtherControlMeasureTaskDto(); dto.DefaultDocumentType = DocumentTypeEnum.FRADocumentType; //TODO: This does not belong here, it belongs in the entity then map that. PTD. } return PopulateTaskDto(entity, dto); }
public void given_factory_when_get_view_model_then_result_maps_ActionPlanDto_to_viewmodel() { //given var actionPlan = new ActionPlanDto() { Id = 1234L, CompanyId = 1L, Title = "Action Plan1", Site = new SiteDto { SiteId = 1L, Name = "Site1" }, DateOfVisit = DateTime.Now, VisitBy = "Consultant1", SubmittedOn = DateTime.Now.AddDays(-1) }; var action = new ActionDto() { Id = 123123, Title = "test title" , AreaOfNonCompliance = "area not compliaint", ActionRequired = "action required test", Category = ActionCategory.Action, QuestionStatus = ActionQuestionStatus.Red }; var task = new ActionTaskDto { Id = 1L, TaskAssignedTo = new EmployeeDto { Id = Guid.NewGuid() }, TaskCompletionDueDate = DateTime.Now.ToShortDateString(), }; action.ActionTasks = new List<ActionTaskDto>() {(task)}; actionPlan.Actions = new List<ActionDto>() { action }; var target = GetTarget(); _actionPlanService.Setup(x => x.GetByIdAndCompanyId(It.IsAny<long>(), It.IsAny<long>())).Returns(actionPlan); //when var result = target.WithActionPlanId(actionPlan.Id).GetViewModel(); //then Assert.That(result.SiteName, Is.EqualTo(actionPlan.Site.Name), "Site name not mapped"); Assert.That(result.VisitDate, Is.EqualTo(actionPlan.DateOfVisit), "Visit Date name not mapped"); Assert.That(result.Actions.FirstOrDefault().HasTask, Is.True); Assert.That(result.Actions.First().AssignedTo == task.TaskAssignedTo.Id); Assert.That(result.Actions.First().DueDate == DateTime.Parse(task.TaskCompletionDueDate)); }