public async Task GivenABaseApiService_WhenUrlIsNull_ThenGetResponseAsyncThrowsException() { // Arrange var apiService = new StubApiService(); // Act await apiService.GetResponseAsync <StubResponse>(null, CancellationToken.None); }
public void GivenABaseApiService_WhenPathIsNull_ThenBuildRequestUrlThrowsException() { // Arrange var apiService = new StubApiService(); // Act apiService.BuildRequestUrl(null); }
public async Task GivenABaseApiService_WhenGetResponseAsyncReturns404Error_ThenFlurlHttpExceptionThrown() { // Arrange var apiService = new StubApiService(); _httpTest.RespondWith(404, string.Empty); // Act var response = await apiService.GetResponseAsync <StubResponse>(ValidTestUrl, CancellationToken.None); }
public async Task GivenABaseApiService_WhenGetResponseAsyncIsNotOk_ThenSlackApiExceptionIsThrown() { // Arrange var apiService = new StubApiService(); _httpTest.RespondWith(STUB_ERROR_RESPONSE); // Act var response = await apiService.GetResponseAsync <StubResponse>(ValidTestUrl, CancellationToken.None); }
public void GivenABaseApiService_WhenQueryParamsIsNull_ThenBuildRequestUrlAppendsNoParams() { // Arrange var apiService = new StubApiService(); // Act var url = apiService.BuildRequestUrl("test", null); // Assert url.QueryParams.ShouldBeEmpty(); }
public void GivenABaseApiService_WhenPathHasValue_ThenItIsAppendedToUrl() { // Arrange var apiService = new StubApiService(); // Act var url = apiService.BuildRequestUrl("test"); // Assert url.Path.ShouldEqual("https://slack.com/api/test"); }
public async Task GivenABaseApiService_WhenUrlHasValue_ThenGetResponseAsyncDeserializesResponse() { // Arrange var apiService = new StubApiService(); _httpTest.RespondWith(STUB_OK_RESPONSE); // Act var response = await apiService.GetResponseAsync <StubResponse>(ValidTestUrl, CancellationToken.None); // Assert response.Ok.ShouldBeTrue(); }
public async Task GivenABaseApiService_WhenUrlHasValue_ThenGetResponseAsyncMakesGetRequest() { // Arrange var apiService = new StubApiService(); _httpTest.RespondWith(STUB_OK_RESPONSE); // Act var response = await apiService.GetResponseAsync <StubResponse>(ValidTestUrl, CancellationToken.None); // Assert _httpTest.ShouldHaveCalled(BaseApiService.API_URL) .WithVerb(HttpMethod.Get) .Times(1); }
public async Task GivenABaseApiService_WhenGetResponseAsyncIsNotOk_ThenSlackApiExceptionHasErrorSet() { // Arrange var apiService = new StubApiService(); _httpTest.RespondWith(STUB_ERROR_RESPONSE); SlackApiException exception = null; try { // Act var response = await apiService.GetResponseAsync <StubResponse>(ValidTestUrl, CancellationToken.None); } catch (SlackApiException ex) { exception = ex; } // Assert exception.Error.ShouldEqual("channel_not_found"); }