Exemplo n.º 1
0
 public async void ServiceDown_ExpectServiceException_ConnectionFailure()
 {
     await RunTest_ExpectServiceException(
         mockClient : MockHttpClient.Create(
             throwsException: new HttpRequestException()
             ),
         expectedErrorType : ServiceErrorType.ConnectionFailure
         );
 }
Exemplo n.º 2
0
 public async void Timeout_ExpectServiceException_Timeout()
 {
     await RunTest_ExpectServiceException(
         mockClient : MockHttpClient.Create(
             throwsException: new TaskCanceledException()
             ),
         expectedErrorType : ServiceErrorType.Timeout
         );
 }
Exemplo n.º 3
0
        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"));
        }
Exemplo n.º 4
0
 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
         );
 }
Exemplo n.º 5
0
 public async void ErrorStatusCode_EmptyResponse_ExpectServiceException_ErrorResponse()
 {
     await RunTest_ExpectServiceException(
         mockClient : MockHttpClient.Create(
             responseStatus: HttpStatusCode.NotFound,
             responseContent: null
             ),
         expectedErrorType : ServiceErrorType.ErrorResponse,
         expectedMessage : "Not Found"
         );
 }
Exemplo n.º 6
0
        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
                );
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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)
                );
        }
Exemplo n.º 9
0
        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
                    )
                );
        }
Exemplo n.º 10
0
        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)
                );
        }
Exemplo n.º 11
0
 public void Setup()
 {
     _httpClientMock = MockHttpClient.Create();
     _sut            = new SampleServiceClient(_httpClientMock);
 }