public void ConstructorShouldFailWhenMapperIsNull()
        {
            //Arrange
            var     blobStorageMock = new Mock <IBlobStorage>().Object;
            IMapper mapper          = null;

            //Act
            var handler = new DownloadFileQueryHandler(blobStorageMock, mapper);
        }
        public void ConstructorShouldFailWhenBlobStorageIsNull()
        {
            //Arrange
            IBlobStorage blobStorage = null;
            var          mapperMock  = new Mock <IMapper>().Object;

            //Act
            var handler = new DownloadFileQueryHandler(blobStorage, mapperMock);
        }
        public void ConstructorShouldSucceed()
        {
            //Arrange
            var blobStorageMock = new Mock <IBlobStorage>().Object;
            var mapperMock      = new Mock <IMapper>().Object;

            //Act
            var handler = new DownloadFileQueryHandler(blobStorageMock, mapperMock);

            //Assert
            handler.Should().NotBeNull();
        }
        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();
        }
        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);
        }