public async void CheckResponseWithStatusOKReturnsSameResponse() { var testResponse = new HttpResponseMessage() { StatusCode = HttpStatusCode.OK }; var result = await ApiClientBase.CheckResponse(testResponse); Assert.AreSame(testResponse, result); }
public void CheckResponseWithFailStatusButNoParsableErrorBodyThrowsMastodonApiExceptionWithBodyInMessage() { var errorMessage = "History eraser button pressed"; var testResponse = new HttpResponseMessage() { StatusCode = HttpStatusCode.BadRequest, Content = new StringContent(errorMessage) }; Assert.That(async() => await ApiClientBase.CheckResponse(testResponse), Throws.Exception.TypeOf <MastodonApiException>() .With.Property("Message").EqualTo($"Unexpected error returned from server: {errorMessage}") .With.Property("StatusCode").EqualTo(HttpStatusCode.BadRequest)); }
public void CheckResponseWithFailStatusAndErrorBodyThrowsMastodonApiExceptionWithParsedError() { var jsonString = TestUtils.GetResource("Mastodon.API.Tests.Resources.get_error.json"); var expectedError = new Error("Record not found"); var testResponse = new HttpResponseMessage() { StatusCode = HttpStatusCode.NotFound, Content = new StringContent(jsonString) }; Assert.That(async() => await ApiClientBase.CheckResponse(testResponse), Throws.Exception.TypeOf <MastodonApiException>() .With.Property("Error").EqualTo(expectedError) .With.Property("StatusCode").EqualTo(HttpStatusCode.NotFound)); }