コード例 #1
0
        public DocumentDto Map(Document entity)
        {
            DocumentDto dto;
            var furtherControlMeasureDocument = entity as TaskDocument;
            var addedDocument = entity as AddedDocument;
            var accidentRecordDocument = entity as AccidentRecordDocument;

            if(furtherControlMeasureDocument != null)
            {
                dto = new TaskDocumentDto();
                var furtherControlMeasureDocumentDto = dto as TaskDocumentDto;
                furtherControlMeasureDocumentDto.DocumentOriginType = furtherControlMeasureDocument.DocumentOriginType;
            }
            else if(addedDocument != null)
            {
                dto = new AddedDocumentDto();
                var addedDocumentDto = dto as AddedDocumentDto;
                addedDocumentDto.SiteId = addedDocument.Site != null ? addedDocument.Site.Id : default(long);
                addedDocumentDto.SiteName = addedDocument.Site != null ? addedDocument.Site.Name : "All";
            }
            else if(accidentRecordDocument != null)
            {
                dto = new AccidentRecordDocumentDto();
                var accidentRecordDocumentDto = dto as AccidentRecordDocumentDto;
                accidentRecordDocumentDto.AccidentRecord = new AccidentRecordDtoMapper().Map(accidentRecordDocument.AccidentRecord);
            }
            else
            {
                dto = new DocumentDto();
            }

            dto.Id = entity.Id;
            dto.DocumentLibraryId = entity.DocumentLibraryId;
            dto.Filename = entity.Filename;
            dto.Extension = entity.Extension;
            dto.FilesizeByte = entity.FilesizeByte;
            dto.Description = entity.Description;
            dto.Title = entity.Title;
            dto.CreatedOn = entity.CreatedOn;
            dto.CreatedByName = entity.CreatedBy != null ? new AuditedUserDtoMapper().Map(entity.CreatedBy).Name: string.Empty;
            dto.CreatedBy = entity.CreatedBy != null ? new AuditedUserDtoMapper().Map(entity.CreatedBy) : null;
            dto.LastModifiedOn = entity.LastModifiedOn;
            dto.Deleted = entity.Deleted;
            dto.DocumentReference = entity.DocumentReference;
            dto.SiteReference = entity.SiteReference;
            
            if(entity.DocumentType != null)
                dto.DocumentType = new DocumentTypeDtoMapper().Map(entity.DocumentType);

            return dto;
        }
コード例 #2
0
        public void Given_a_user_with_delete_added_documents_permissions_and_task_is_not_an_added_document_When_IsDeleteEnabled_Then_returns_false
            ()
        {
            //Given
            var target = new AddedDocumentsLibraryViewModel();
            var user = new Mock<IPrincipal>();
            user.Setup(x => x.IsInRole(It.IsAny<string>())).Returns(true);

            var addedDocumentDto = new TaskDocumentDto()
            {
                DocumentType = new DocumentTypeDto(),
                CreatedOn = DateTime.Now
            };
            var viewModel = DocumentViewModel.CreateFrom(addedDocumentDto);

            //When
            var result = target.IsDeleteDocumentEnabled(user.Object, viewModel);

            //Then
            Assert.IsFalse(result);
        }
        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));
        }