Exemplo n.º 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;
        }
        public void Given_a_user_with_delete_added_documents_permissions_and_task_is_an_added_document_When_IsDeleteEnabled_Then_returns_true
            ()
        {
            //Given
            var target = new AddedDocumentsLibraryViewModel();
            var user = new Mock<IPrincipal>();
            user.Setup(x => x.IsInRole(It.IsAny<string>())).Returns(true);

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

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

            //Then
            Assert.IsTrue(result);
        }
        public void Given_a_user_without_delete_added_documents_permissions_When_IsDeleteEnabled_Then_returns_false
            ()
        {
            //Given
            var target = new AddedDocumentsLibraryViewModel();
            var user = new Mock<IPrincipal>();
            user.Setup(x => x.IsInRole(Permissions.DeleteAddedDocuments.ToString())).Returns(false);

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

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

            //Then
            Assert.IsFalse(result);
        }