public static ViewResponsibilityTaskViewModel CreateFrom(ResponsibilityTaskDto responsibilityTask) { var viewModel = new ViewResponsibilityTaskViewModel(); viewModel.CompanyId = responsibilityTask.Responsibility.CompanyId; viewModel.ResponsibilityTaskId = responsibilityTask.Id; viewModel.Title = responsibilityTask.Title; viewModel.Description = responsibilityTask.Description; viewModel.IsRecurring = responsibilityTask.IsReoccurring; viewModel.TaskReoccurringType = responsibilityTask.TaskReoccurringType; viewModel.TaskReoccurringTypeId = (int)responsibilityTask.TaskReoccurringType; viewModel.ReoccurringStartDate = responsibilityTask.TaskCompletionDueDate; viewModel.ReoccurringEndDate = responsibilityTask.TaskReoccurringEndDate; viewModel.CompletionDueDate = responsibilityTask.TaskCompletionDueDate; viewModel.ResponsibilityTaskSite = responsibilityTask.Site != null ? responsibilityTask.Site.Name : string.Empty; viewModel.ResponsibilityTaskSiteId = responsibilityTask.Site != null ? responsibilityTask.Site.Id : default(long); viewModel.AssignedTo = responsibilityTask.TaskAssignedTo != null ? responsibilityTask.TaskAssignedTo.FullName : string.Empty; viewModel.AssignedToId = responsibilityTask.TaskAssignedTo != null ? responsibilityTask.TaskAssignedTo.Id : Guid.Empty; viewModel.DoNotSendTaskAssignedNotification = !responsibilityTask.SendTaskCompletedNotification; viewModel.DoNotSendTaskCompletedNotification = !responsibilityTask.SendTaskCompletedNotification; viewModel.DoNotSendTaskOverdueNotification = !responsibilityTask.SendTaskOverdueNotification; viewModel.TaskStatusId = responsibilityTask.TaskStatusId; viewModel.TaskCompletedDate = (string) (responsibilityTask.TaskCompletedDate.HasValue ? responsibilityTask.TaskCompletedDate.GetValueOrDefault().ToLocalTime().ToString("g") : null); viewModel.TaskCompletedComments = responsibilityTask.TaskCompletedComments; viewModel.ExistingDocuments = ExistingDocumentsViewModel.CreateFrom(responsibilityTask.Documents); viewModel.ExistingDocuments.CanDeleteDocuments = false; viewModel.ExistingDocuments.DocumentTypeId = (int)DocumentTypeEnum.Responsibility; viewModel.ResponsibilitySummary = new ResponsibilitySummaryViewModel { Id = responsibilityTask.Responsibility.Id, Title = responsibilityTask.Responsibility.Title, Description = responsibilityTask.Responsibility.Description }; return viewModel; }
public ResponsibilityTaskDto MapWithAssignedTo(ResponsibilityTask entity) { var dto = new ResponsibilityTaskDto(); dto = PopulateTaskDto(entity, dto) as ResponsibilityTaskDto; dto.StatutoryResponsibilityTaskTemplateCreatedFrom = new StatutoryResponsibilityTaskTemplateDtoMapper().Map( entity.StatutoryResponsibilityTaskTemplateCreatedFrom); return dto; }
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_search_for_current_user_When_GetViewModel_is_called_Then_returns_model() { //Given var taskId = 124124124L; var target = CreateTarget(); var site = new SiteDto() {Id = 1L, Name = "the main site"}; var taskDocument = new TaskDocumentDto() {Id = 12312, DocumentLibraryId = 13123, Description = "doc description", Filename = "the filename"}; var responsibility = new ResponsibilityDto{Id = 1L, CompanyId = _companyId, Title = "Responsibilty Title",Description = "Responsibilty Description"}; var responsibilityTask = new ResponsibilityTaskDto { Id = taskId, Title = "task title", Description = "task description", TaskAssignedTo = new EmployeeDto {FullName = "Test employee name", Id=Guid.NewGuid()}, CreatedDate = DateTime.Now.ToShortDateString(), TaskCompletionDueDate = DateTime.Now.ToShortDateString(), TaskStatusString = string.Empty, Site = site, Responsibility = responsibility, TaskReoccurringType = TaskReoccurringType.Monthly, TaskReoccurringEndDate = DateTime.Now.AddDays(234), IsReoccurring = true, SendTaskCompletedNotification = true, SendTaskNotification = true, SendTaskOverdueNotification = true, Documents = new List<TaskDocumentDto>(){taskDocument} }; _responsibilityTaskService .Setup(x=> x.GetByIdAndCompanyId(taskId, It.IsAny<long>())) .Returns(() => responsibilityTask ); //When var result = target .WithCompanyId(_companyId) .WithResponsibilityTaskId(taskId) .GetViewModel(); //Then Assert.That(result.CompanyId, Is.EqualTo(responsibility.CompanyId)); Assert.That(result.ResponsibilityTaskId, Is.EqualTo(responsibilityTask.Id)); Assert.That(result.ResponsibilitySummary.Id, Is.EqualTo(responsibility.Id)); Assert.That(result.ResponsibilitySummary.Title, Is.EqualTo(responsibility.Title)); Assert.That(result.ResponsibilitySummary.Description, Is.EqualTo(responsibility.Description)); Assert.That(result.ResponsibilityTask.CompanyId, Is.EqualTo(responsibility.CompanyId)); Assert.That(result.ResponsibilityTask.ResponsibilityTaskId, Is.EqualTo(responsibilityTask.Id)); Assert.That(result.ResponsibilityTask.Title, Is.EqualTo(responsibilityTask.Title)); Assert.That(result.ResponsibilityTask.Description, Is.EqualTo(responsibilityTask.Description)); Assert.That(result.ResponsibilityTask.IsRecurring, Is.EqualTo(responsibilityTask.IsReoccurring)); Assert.That(result.ResponsibilityTask.TaskReoccurringType, Is.EqualTo(responsibilityTask.TaskReoccurringType)); Assert.That(result.ResponsibilityTask.TaskReoccurringTypeId, Is.EqualTo((int)responsibilityTask.TaskReoccurringType)); Assert.That(result.ResponsibilityTask.ReoccurringStartDate, Is.EqualTo(responsibilityTask.TaskCompletionDueDate)); Assert.That(result.ResponsibilityTask.ReoccurringEndDate, Is.EqualTo(responsibilityTask.TaskReoccurringEndDate)); Assert.That(result.ResponsibilityTask.CompletionDueDate, Is.EqualTo(responsibilityTask.TaskCompletionDueDate)); Assert.That(result.ResponsibilityTask.ResponsibilityTaskSite, Is.EqualTo(responsibilityTask.Site.Name)); Assert.That(result.ResponsibilityTask.ResponsibilityTaskSiteId, Is.EqualTo(responsibilityTask.Site.Id)); Assert.That(result.ResponsibilityTask.AssignedTo, Is.EqualTo(responsibilityTask.TaskAssignedTo.FullName)); Assert.That(result.ResponsibilityTask.AssignedToId, Is.EqualTo(responsibilityTask.TaskAssignedTo.Id)); Assert.That(result.ResponsibilityTask.DoNotSendTaskAssignedNotification, Is.EqualTo(!responsibilityTask.SendTaskNotification)); Assert.That(result.ResponsibilityTask.DoNotSendTaskCompletedNotification, Is.EqualTo(!responsibilityTask.SendTaskCompletedNotification)); Assert.That(result.ResponsibilityTask.DoNotSendTaskOverdueNotification, Is.EqualTo(!responsibilityTask.SendTaskOverdueNotification)); Assert.That(result.ResponsibilityTask.TaskStatusId, Is.EqualTo(responsibilityTask.TaskStatusId)); Assert.That(result.ResponsibilityTask.ExistingDocuments.CanDeleteDocuments, Is.EqualTo(false)); Assert.That(result.ResponsibilityTask.ExistingDocuments.DocumentTypeId, Is.EqualTo((int)DocumentTypeEnum.Responsibility)); Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Id, Is.EqualTo(taskDocument.Id)); Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].DocumentLibraryId, Is.EqualTo(taskDocument.DocumentLibraryId)); Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Filename, Is.EqualTo(taskDocument.Filename)); Assert.That(result.ResponsibilityTask.ExistingDocuments.PreviouslyAddedDocuments[0].Description, Is.EqualTo(taskDocument.Description)); Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Id, Is.EqualTo(responsibility.Id)); Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Title, Is.EqualTo(responsibility.Title)); Assert.That(result.ResponsibilityTask.ResponsibilitySummary.Description, Is.EqualTo(responsibility.Description)); }