public async Task ValidAuthorizationHeaderValueShouldReturn200() { var httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, " https://jsonplaceholder.typicode.com"); string headerValue = ConfigurationManager.AppSettings["authorizationvalue"]; httpRequestMessage.Headers.Authorization = AuthenticationHeaderValue.Parse(headerValue); var handler = new AuthorizationHeaderHandler() { InnerHandler = new Mock <HttpMessageHandler>(MockBehavior.Loose).Object }; var invoker = new HttpMessageInvoker(handler); // on success we will get a null object back (due to using MockBehavior.Loose) Assert.IsNull(await invoker.SendAsync(httpRequestMessage, new CancellationToken())); }
public async Task ShouldAddBearerTokenToAuthorizationHeader() { // Arrange var accessToken = new AccessToken("MySecretAccessToken", DateTimeOffset.MaxValue); var tokenProvider = A.Fake <ITokenProvider>(); A.CallTo(() => tokenProvider.GetTokenAsync(A <CancellationToken> ._)) .Returns(accessToken); var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost"); var sut = new AuthorizationHeaderHandler(tokenProvider); // Act var result = await InvokeAsync(sut, request); // Assert result.Headers.Authorization.Should().NotBeNull(); result.Headers.Authorization?.Scheme.Should().Be("Bearer"); result.Headers.Authorization?.Parameter.Should().Be(accessToken.Token); }