public async void ServiceDown_ExpectServiceException_ConnectionFailure() { await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( throwsException: new HttpRequestException() ), expectedErrorType : ServiceErrorType.ConnectionFailure ); }
public async void Timeout_ExpectServiceException_Timeout() { await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( throwsException: new TaskCanceledException() ), expectedErrorType : ServiceErrorType.Timeout ); }
public void GetAsyncWithBadRequest() { var message = "This was bad"; var statusCode = HttpStatusCode.BadRequest; var mockHttp = MockHttpClient.Create(message, statusCode); var apiClient = new ApiClientBase(new Uri("http://example.com/"), mockHttp); Assert.Throws <MastodonApiException>(async() => await apiClient.GetAsync("/test")); }
public async void NoContent_ExpectServiceException_ClientError() { await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.OK, responseContent: null ), expectedErrorType : ServiceErrorType.ClientError, expectedMessage : AuthServiceClient.EMPTY_RESPONSE_ERROR_MESSAGE ); }
public async void ErrorStatusCode_EmptyResponse_ExpectServiceException_ErrorResponse() { await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.NotFound, responseContent: null ), expectedErrorType : ServiceErrorType.ErrorResponse, expectedMessage : "Not Found" ); }
public async void ValidResponse_ExpectSuccess() { const string TEST_TOKEN = "test-token"; await RunTest_ExpectSuccess( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.OK, responseContent: string.Format("{{ \"access_token\": \"{0}\" }}", TEST_TOKEN) ), expectedToken : TEST_TOKEN ); }
public async void GetAsyncWithStatusAndMessage() { var message = "Hello"; var statusCode = HttpStatusCode.OK; var mockHttp = MockHttpClient.Create(message, statusCode); var apiClient = new ApiClientBase(new Uri("http://example.com/"), mockHttp); var response = await apiClient.GetAsync("/test"); Assert.AreEqual(message, await response.Content.ReadAsStringAsync()); Assert.AreEqual(statusCode, response.StatusCode); }
public async void ErrorStatusCodeAndInvalidJson_ExpectServiceException_ErrorResponse() { const string AUTH_RESPONSE_CONTENT = "{ \"invalid\": \"format\" }"; await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.NotFound, responseContent: AUTH_RESPONSE_CONTENT ), expectedErrorType : ServiceErrorType.ErrorResponse, expectedMessage : string.Concat("Not Found: ", AUTH_RESPONSE_CONTENT) ); }
public async void InvalidJson_ExpectServiceException_ClientError() { const string AUTH_RESPONSE_CONTENT = "{ \"invalid\": \"format\" }"; await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.OK, responseContent: AUTH_RESPONSE_CONTENT ), expectedErrorType : ServiceErrorType.ClientError, expectedMessage : string.Concat( AuthServiceClient.INVALID_JSON_ERROR_MESSAGE_PREFIX, AUTH_RESPONSE_CONTENT ) ); }
public async void ErrorStatusCode_ValidErrorObject_ExpectServiceException_ErrorResponse() { const string ERROR_NAME = "TestError"; const string ERROR_DETAIL = "Test error details"; await RunTest_ExpectServiceException( mockClient : MockHttpClient.Create( responseStatus: HttpStatusCode.NotFound, responseContent: string.Format( "{{ \"error\": \"{0}\", \"error_description\": \"{1}\" }}", ERROR_NAME, ERROR_DETAIL ) ), expectedErrorType : ServiceErrorType.ErrorResponse, expectedMessage : string.Concat(ERROR_NAME, ": ", ERROR_DETAIL) ); }
public void Setup() { _httpClientMock = MockHttpClient.Create(); _sut = new SampleServiceClient(_httpClientMock); }