public async Task HandleAsync_WithCorrectCommand_ShouldReturnSuccessResult() { // Arrange Website website = new Website(); _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(website); var handler = new UpdateWebsiteHandler(_repositoryMock.Object, _unitOfWorkMock.Object, _cyhperMock.Object); // Act var command = new Application.Websites.Commands.UpdateWebsite.UpdateWebsite(Guid.Empty, "mySite", "www.mysite.com", new List <string> { "cat1", "cat2" }, new ImageManipulation("myImage.png", "image/png", new byte[1]), "*****@*****.**", "123456"); OperationResult <bool> operationResult = await handler.Handle(command, CancellationToken.None); // Assert _unitOfWorkMock.Verify(x => x.CommitAsync(CancellationToken.None), Times.Once()); operationResult.Should().BeOfType(typeof(OperationResult <bool>)); operationResult.IsSuccessful.Should().BeTrue(); }
public async Task HandleAsync_WhenWebsiteNotFound_ShouldReturnFailureResult() { // Arrange Website website = null; _repositoryMock.Setup(x => x.GetByIdAsync(It.IsAny <Guid>())).ReturnsAsync(website); var handler = new UpdateWebsiteHandler(_repositoryMock.Object, _unitOfWorkMock.Object, _cyhperMock.Object); // Act var command = new Application.Websites.Commands.UpdateWebsite.UpdateWebsite(Guid.Empty, "mySite", "www.mysite.com", new List <string> { "cat1", "cat2" }, new ImageManipulation("myImage.png", "image/png", new byte[1]), "*****@*****.**", "123456"); OperationResult <bool> operationResult = await handler.Handle(command, CancellationToken.None); // Assert operationResult.Should().BeOfType(typeof(OperationResult <bool>)); operationResult.IsSuccessful.Should().BeFalse(); operationResult.Errors.First().Key.Should().Be("WebsiteId"); operationResult.Errors.First().Value.Should().Be(ErrorMessages.WebsiteNotFound); }