Пример #1
0
        //readonly SendNotificationCommandHGandler sendNotificationCommand;

        public DocumentController(
            CreateDocumentCommandHandler createCommandHandler,
            SearchDocumentsQuery searchDocumentsQuery,
            SearchCountQuery searchCountQuery,
            DownloadFileQuery downloadFileQuery,
            GetOneDocumentQuery getOneQuery,
            GetAllDocumentTypesQuery getDTsQuery,
            GetAllEntitiesQuery getEsQuery,
            GetAllDocumentTypesByUserQuery getDTByUserQuery,
            DocumentsWithoutFilePagedQuery withoutFileQuery,
            UpdateFileToDocumentCommandHandler updateFileCommandHandler,
            DeleteDocumentCommandHandler deleteDocumentCommand,
            SendDocumentNotificationCommandHandler sendDocmentNotificationCommandHandler
            //SendNotificationCommandHGandler sendNotificationCommand) {
            )
        {
            _createCommandHandler         = createCommandHandler;
            this.searchDocumentsQuery     = searchDocumentsQuery;
            this.searchCountQuery         = searchCountQuery;
            this.downloadFileQuery        = downloadFileQuery;
            this.getOneQuery              = getOneQuery;
            this.getDTsQuery              = getDTsQuery;
            this.getEsQuery               = getEsQuery;
            this.withoutFileQuery         = withoutFileQuery;
            this.updateFileCommandHandler = updateFileCommandHandler;
            this.deleteDocumentCommand    = deleteDocumentCommand;
            this.sendDocumentNotificationCommandHandler = sendDocmentNotificationCommandHandler;
            this.getDTByUserQuery = getDTByUserQuery;
            //this.sendNotificationCommand = sendNotificationCommand;
        }
Пример #2
0
        public async Task <ActionResult> DownloadFile(
            [FromRoute] DownloadFileQuery query)
        {
            var file = await Mediator.Send(query);

            return(_fileService.GetFileFromStorage(
                       Path.Combine(_filesDirectory.Posts, file.Path), file.Name));
        }
 public void ShouldThrow_WhenFileDoesntExist(DownloadFileQuery query)
 {
     FluentActions.Awaiting(() => SendAsync(query))
     .Should()
     .Throw <ValidationException>()
     .And.Error.Message.Should()
     .Be("File doesn't exist");
 }
Пример #4
0
 public MainViewModel(Model.Model model)
 {
     _model             = model;
     _connectionQuery   = new ConnectionQuery();
     _getFileNamesQuery = new GetFileNamesQuery();
     _downloadFileQuery = new DownloadFileQuery();
     _downloads         = new ObservableCollection <string>();
     _processingInfos   = new ObservableCollection <ProcessingInfo>();
 }
Пример #5
0
        public void Handle_GivenInvalidFileId_ThrowsException()
        {
            var query = new DownloadFileQuery
            {
                FileId = 1007
            };

            var handler = GetNewHandler();

            Assert.ThrowsAsync <NotFoundException>(async() =>
                                                   await handler.Handle(query, CancellationToken.None));
        }
Пример #6
0
        public async Task Handle_ShouldBeReturnFile()
        {
            var query = new DownloadFileQuery
            {
                FileId = DefaultFileIds.First()
            };

            var handler = GetNewHandler();

            var result = await handler.Handle(query, CancellationToken.None);

            Assert.That(result.Name, IsNotNullOrEmpty);
            Assert.That(result.Path, IsNotNullOrEmpty);
        }
Пример #7
0
        private static ITaskExecutor ToDownloadFileExecutor(DownloadFileRequest request)
        {
            if (ConnectionsStorage.Instanse.Contains(request.SessionId))
            {
                var query = new DownloadFileQuery(request.ResponseEndPoint)
                {
                    Id           = request.Id,
                    FileFullName = request.FileFullName
                };

                return(new DownloadFileExecutor(query));
            }

            return(null);
        }
        public async Task HandleShouldSucceed()
        {
            //Arrange
            var blobStorageMock = new Mock <IBlobStorage>();

            blobStorageMock.Setup(x => x.DownloadFileAsync(It.IsAny <string>())).Returns(Task.FromResult(new FileDownloadDto()));
            var blobStorage = blobStorageMock.Object;
            var mapperMock  = new Mock <IMapper>().Object;
            var query       = new DownloadFileQuery("test");

            //Act
            var handler = new DownloadFileQueryHandler(blobStorage, mapperMock);
            var result  = await handler.Handle(query, CancellationToken.None);

            //Assert
            result.Should().NotBeNull();
        }
Пример #9
0
 public SearchController(
     GetAllDocumentTypesQuery getAllDTQuery,
     GetAllEntitiesQuery getAllETQuery,
     SearchCountQuery searchCountQuery,
     SearchDocumentsQuery searchDocumentsQuery,
     DownloadFileQuery downloadFileQuery,
     GetAllAnnotationTypesQuery getAllATQuery,
     GetDocumentAnnotationsQuery getDocAnnotationsQuery,
     GetOneDocumentQuery getOneDocumentQuery
     )
 {
     this.getAllDTQuery          = getAllDTQuery;
     this.getAllEQuery           = getAllETQuery;
     this.searchCountQuery       = searchCountQuery;
     this.searchDocumentsQuery   = searchDocumentsQuery;
     this.downloadFileQuery      = downloadFileQuery;
     this.getAllATQuery          = getAllATQuery;
     this.getDocAnnotationsQuery = getDocAnnotationsQuery;
     this.getOneDocumentQuery    = getOneDocumentQuery;
 }
        public async Task HandleShouldReturnFailWhenExceptionThrown()
        {
            //Arrange
            var blobStorageMock = new Mock <IBlobStorage>();

            blobStorageMock.Setup(x => x.DownloadFileAsync(It.IsAny <string>())).Throws(new Exception("Test"));
            var blobStorage   = blobStorageMock.Object;
            var mapperMock    = new Mock <IMapper>().Object;
            var query         = new DownloadFileQuery("test");
            var expectedError = new CustomFault
            {
                Message = CustomFailures.DownloadFileFailure
            };

            //Act
            var handler = new DownloadFileQueryHandler(blobStorage, mapperMock);
            var result  = await handler.Handle(query, CancellationToken.None);

            //Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().ContainEquivalentOf(expectedError);
        }
        public async Task HandleShouldReturnFailIfFileNotFound()
        {
            //Arrange
            var blobStorageMock = new Mock <IBlobStorage>();

            blobStorageMock.Setup(x => x.DownloadFileAsync(It.IsAny <string>())).Throws(new BlobNotFoundException(new Exception("test")));
            var blobStorage   = blobStorageMock.Object;
            var mapperMock    = new Mock <IMapper>().Object;
            var query         = new DownloadFileQuery("test");
            var expectedError = new HandlerFault()
            {
                Code    = HandlerFaultCode.NotFound.Name,
                Message = string.Format(HandlerFailures.NotFound, "File"),
                Target  = "file"
            };

            //Act
            var handler = new DownloadFileQueryHandler(blobStorage, mapperMock);
            var result  = await handler.Handle(query, CancellationToken.None);

            //Assert
            result.IsFailure.Should().BeTrue();
            result.Failures.Should().ContainEquivalentOf(expectedError);
        }
Пример #12
0
 public DownloadFileExecutor(DownloadFileQuery query)
 {
     _query = query;
     Id     = Guid.NewGuid();
 }
Пример #13
0
 public DownloadFileExecutor CreateDownloadFileExecutor(DownloadFileQuery query)
 {
     return(new DownloadFileExecutor(query, _itemsFactory));
 }
Пример #14
0
        public async Task <IActionResult> Download([FromRoute] DownloadFileQuery request)
        {
            var fileVm = await this.Mediator.Send(request);

            return(this.File(fileVm.Contents.ToArray(), "application/octet-stream", fileVm.FileName));
        }
Пример #15
0
        public DownloadFileQuery Map(DownloadFileRequest request)
        {
            var result = new DownloadFileQuery(request.File);

            return(result);
        }