public async Task ReturnsOkIfPostingCommentSucceeds() { var serviceMock = new Mock <IPostCommentService>(); serviceMock.Setup(x => x.PostCommentAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new PostCommentResult(HttpStatusCode.OK)); var function = new PostCommentToPullRequestFunction(serviceMock.Object); var response = await function.Run(Mock.Of <HttpRequest>(), Mock.Of <ILogger>()).ConfigureAwait(false); Assert.IsType <OkResult>(response); }
public async Task ReturnsRedirectIfPostingCommentSucceedsWithRedirection() { var redirectUri = new Uri("http://www.example.com/"); var serviceMock = new Mock <IPostCommentService>(); serviceMock.Setup(x => x.PostCommentAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new PostCommentResult(HttpStatusCode.Redirect, redirectUri)); var function = new PostCommentToPullRequestFunction(serviceMock.Object); var response = await function.Run(Mock.Of <HttpRequest>(), Mock.Of <ILogger>()).ConfigureAwait(false); Assert.IsType <RedirectResult>(response); Assert.Equal(redirectUri.AbsoluteUri, ((RedirectResult)response).Url); }
public async Task LogsAndReturnsBadRequestIfPostingCommentFails(Exception exception) { var serviceMock = new Mock <IPostCommentService>(); serviceMock.Setup(x => x.PostCommentAsync(It.IsAny <IFormCollection>())) .ReturnsAsync(new PostCommentResult(HttpStatusCode.BadRequest, exception?.Message !, exception !)); var formMock = new Mock <IFormCollection>(); var requestMock = new Mock <HttpRequest>(); requestMock.Setup(x => x.ReadFormAsync(It.IsAny <CancellationToken>())) .ReturnsAsync(formMock.Object); var loggerMock = new Mock <ILogger>(); var function = new PostCommentToPullRequestFunction(serviceMock.Object); var result = await function.Run(requestMock.Object, loggerMock.Object).ConfigureAwait(false); Assert.IsType <BadRequestResult>(result); loggerMock.Verify(x => x.Log(LogLevel.Error, 0, It.IsAny <object>(), exception, It.IsAny <Func <object, Exception, string> >())); }