public void ShouldThrowValidationExceptionWhenFileDoesNtoExist() { string location = "testLocation"; domainRepository.Setup(repository => repository.GetDocumentByLocation(location)).ReturnsAsync(() => null); var exception = Assert.ThrowsAsync <ValidationException>(() => handler.Handle(new DeleteDocumentCommand(location), CancellationToken.None)); Assert.That(exception.Message, Is.EqualTo($"Document with Location: {location} doesn't exist.")); }
public async Task Handler_GivenNonExistentFilenameParameters_ReturnsEmptyValue() { var filename = "doesntexist.pdf"; var cancellationToken = new CancellationToken(); var repository = new Mock <IDocumentRepository>(); repository.Setup(x => x.Delete(filename, cancellationToken)).ReturnsAsync(false); var request = new DeleteDocumentCommand(filename); var handler = new DeleteDocumentCommandHandler(repository.Object); var result = await handler.Handle(request, cancellationToken); result.IsSuccessful.ShouldBeFalse(); }
public async Task Handler_GivenValidParameters_ReturnsTrue() { var filename = "example.pdf"; var cancellationToken = new CancellationToken(); var repository = new Mock <IDocumentRepository>(); repository.Setup(x => x.Delete(filename, cancellationToken)).ReturnsAsync(true); var request = new DeleteDocumentCommand(filename); var handler = new DeleteDocumentCommandHandler(repository.Object); var result = await handler.Handle(request, cancellationToken); result.IsSuccessful.ShouldBeTrue(); }