public async Task Then_It_Should_Throw_SpotifyWebApiClientException_When_Request_Is_Invalid(AuthError authError) { // Arrange var error = new StringContent(JsonConvert.SerializeObject(authError), Encoding.UTF8, "application/json"); var fakeHttpMessageHandler = new FakeHttpMessageHandler(error, HttpStatusCode.BadRequest); MockHttpClientFactory.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(new HttpClient(fakeHttpMessageHandler)); _sut = new SpotifyWebApiClient(Mapper, MockHttpClientFactory.Object, MockApiSettings.Object, MockLogger.Object); // Act var ex = await Assert.ThrowsAsync <SpotifyWebApiClientException>(() => _sut.GetTokenAsync()); // Aseert ex.ShouldNotBe(null); }
public async Task Then_It_Should_Return_A_Valid_Token(AuthToken authToken) { // Arrange var token = new StringContent(JsonConvert.SerializeObject(authToken), Encoding.UTF8, "application/json"); var fakeHttpMessageHandler = new FakeHttpMessageHandler(token, HttpStatusCode.OK); MockHttpClientFactory.Setup(x => x.CreateClient(It.IsAny <string>())).Returns(new HttpClient(fakeHttpMessageHandler)); _sut = new SpotifyWebApiClient(Mapper, MockHttpClientFactory.Object, MockApiSettings.Object, MockLogger.Object); // Act var response = await _sut.GetTokenAsync().ConfigureAwait(false); // Aseert response.ShouldNotBe(null); response.AccessToken.ShouldBe("NgCXRK"); response.ExpiresIn.ShouldBe(3600); response.RefreshToken.ShouldBe("NgAagA"); response.TokenType.ShouldBe("Bearer"); }
public SpotifyService(ISpotifyWebApiClient spotifyApiClient) { SpotifyWebApiClient = spotifyApiClient ?? throw new ArgumentNullException(nameof(spotifyApiClient)); }