public void SendRequestToken_ShouldGetTokenFromJsonCorrectly() { Task.Run(async() => { string json = readMockDataFromFile($"/../../../MockData/tokenMock.json"); var client = new Mock <IWebClient>(); var response = new Mock <IApiResponse>(); response.Setup(i => i.IsSuccessful()).Returns(true); response.Setup(i => i.ReadContentAsync()).ReturnsAsync(json); client.Setup(i => i.RequestAccessTokenAsync()).ReturnsAsync(response.Object); var reader = new ApiReader(defaultConfig, client.Object); try { string token = await reader.SendTokenRequest(); token.Should().Be("TOKENGOESHERE"); } catch { Assert.Fail(); } }).GetAwaiter().GetResult(); }
public void SendTokenRequest_ShouldThrowWhenNotSuccessful() { Task.Run(async() => { var client = new Mock <IWebClient>(); var response = new Mock <IApiResponse>(); response.Setup(i => i.IsSuccessful()).Returns(false); client.Setup(i => i.RequestAccessTokenAsync()).ReturnsAsync(response.Object); var reader = new ApiReader(defaultConfig, client.Object); try { await reader.SendTokenRequest(); Assert.Fail(); } catch (HttpRequestException ex) { } catch { Assert.Fail(); } }).GetAwaiter().GetResult(); }