public async Task Handle_WhenRedirectFound_ReturnsSuccessfulResponse() { var expectedUrl = new RedirectUrl { Url = "https://localhost/" }; _redirectRepositoryMock.Setup(m => m.GetByShortenedUrlAsync(It.IsAny <string>(), It.IsAny <string>())) .ReturnsAsync(expectedUrl); var handler = new GetRedirectUrlQueryHandler(_redirectRepositoryMock.Object); var actual = await handler.Handle(new GetRedirectUrlQuery(), CancellationToken.None); Assert.True(actual.IsSuccessful); Assert.Equal(expectedUrl.Url, actual.RedirectUrl); }
public async Task Handle_WhenRedirectNotFound_ReturnsFailedResponse() { const string expectedError = "Expected error message"; const string expectedInnerError = "Expected error message inner"; _redirectRepositoryMock.Setup(m => m.GetByShortenedUrlAsync(It.IsAny <string>(), It.IsAny <string>())) .ThrowsAsync(new InvalidOperationException(expectedError, new Exception(expectedInnerError))); var handler = new GetRedirectUrlQueryHandler(_redirectRepositoryMock.Object); var actual = await handler.Handle(new GetRedirectUrlQuery(), CancellationToken.None); Assert.False(actual.IsSuccessful); Assert.Equal(2, actual.Errors.Count); Assert.Equal(expectedError, actual.Errors[0].Message); Assert.Equal(expectedInnerError, actual.Errors[1].Message); }