public async Task UsesCachedAuthorization_IfAlreadyAuthorized() { // Arrange var config = StubConfiguration(); var httpMessageHandler = StubHttpCallForAuthorizationToReturn(expected); var httpClient = new HttpClient(httpMessageHandler.Object); // Act var sut = new SpotifyClientCredentialsFlow(config, httpClient); await sut.RequestAsync(); var result = await sut.RequestAsync(); // Assert result.Should().BeEquivalentTo(expected); httpMessageHandler .Protected() .Verify("SendAsync", Times.Once(), ItExpr.IsAny <HttpRequestMessage>(), ItExpr.IsAny <CancellationToken>()); }
public async Task WithValidCredentials() { var config = new TestingConfiguration().Build(); var sut = new SpotifyClientCredentialsFlow(config, new HttpClient()); var result = await sut.RequestAsync(); Assert.AreEqual(3600, result.ExpiresIn); Assert.AreEqual("Bearer", result.TokenType); Assert.IsFalse(string.IsNullOrWhiteSpace(result.AccessToken)); }
public async Task AuthorizesWithSpotify_IfNotAuthorized() { // Arrange var config = StubConfiguration(); var httpMessageHandler = StubHttpCallForAuthorizationToReturn(expected); var httpClient = new HttpClient(httpMessageHandler.Object); // Act var sut = new SpotifyClientCredentialsFlow(config, httpClient); var result = await sut.RequestAsync(); // Assert result.Should().BeEquivalentTo(expected); }
private static async Task <Exception> TryToAuthenticate(IConfiguration config) { Exception thrownEx = null; try { var sut = new SpotifyClientCredentialsFlow(config, new HttpClient()); await sut.RequestAsync(); } catch (Exception ex) { thrownEx = ex; } Assert.IsNotNull(thrownEx); Assert.IsInstanceOfType(thrownEx, typeof(SpotifyAuthorizationException)); return(thrownEx); }