public void ShouldThrowValidationExceptionWhenFileDoesNotExist()
        {
            string location = "testLocation";

            domainRepository.Setup(repository => repository.GetDocumentByLocation(location)).ReturnsAsync(() => null);
            var exception = Assert.ThrowsAsync <ValidationException>(() =>
                                                                     handler.Handle(new DownloadDocumentQuery(location), CancellationToken.None));

            Assert.That(exception.Message, Is.EqualTo($"Document with Location: {location} doesn't exist."));
        }
        public async Task Handler_GivenEmptyFilenameParameters_ReturnsNoValue()
        {
            var filename          = "example.pdf";
            var cancellationToken = new CancellationToken();

            var repository = new Mock <IDocumentRepository>();

            repository.Setup(x => x.GetSingle(filename)).Returns((Document)null);

            var request = new GetDocumentQuery(filename);
            var handler = new GetDocumentQueryHandler(repository.Object);

            var result = await handler.Handle(request, cancellationToken);

            result.IsSuccessful.ShouldBeFalse();
            result.Value.ShouldBeNull();
        }
        public async Task Handler_GivenValidFilename_ReturnsDocument()
        {
            var filename          = "example.pdf";
            var contentType       = "application/pdf";
            var bytes             = 1000;
            var cancellationToken = new CancellationToken();

            var dateCreated = new DateTime(2000, 12, 31, 01, 02, 03);
            var repository  = new Mock <IDocumentRepository>();

            repository.Setup(x => x.GetSingle(filename)).Returns(new Document(filename, bytes, contentType, dateCreated));

            var request = new GetDocumentQuery(filename);
            var handler = new GetDocumentQueryHandler(repository.Object);

            var result = await handler.Handle(request, cancellationToken);

            result.IsSuccessful.ShouldBeTrue();
            result.Value.ContentType.ShouldBe(contentType);
            result.Value.Filename.ShouldBe(filename);
            result.Value.Bytes.ShouldBe(bytes);
            result.Value.DateCreated.ShouldBe(dateCreated);
        }