public void EmitsAnOfflineExceptionIfTheApiClientThrowsAnHttpRequestException() { Exception caughtException = null; var httpRequestException = new HttpRequestException(); apiClient.Send(Arg.Any <Request>()).Returns <IResponse>(_ => throw httpRequestException); var credentials = Credentials.None; var endpoint = Endpoint.Get(BaseUrls.ForApi(ApiEnvironment.Staging), ""); var testApi = new TestApi(endpoint, apiClient, serializer, credentials, endpoint); try { testApi.TestCreateObservable <string>(endpoint, Enumerable.Empty <HttpHeader>(), "") .ToObservable() .Wait(); } catch (Exception e) { caughtException = e; } caughtException.Should().NotBeNull(); caughtException.Should().BeOfType <OfflineException>(); caughtException.InnerException.Should().Be(httpRequestException); }
public async Task CreatesAnObservableThatReturnsASingleValue() { apiClient.Send(Arg.Any <Request>()).Returns(x => new Response("It lives", true, "text/plain", new List <KeyValuePair <string, IEnumerable <string> > >(), OK)); var credentials = Credentials.WithPassword( "*****@*****.**".ToEmail(), "theirobotmoviesucked123".ToPassword()); var endpoint = Endpoint.Get(BaseUrls.ForApi(ApiEnvironment.Staging), ""); var testApi = new TestApi(endpoint, apiClient, serializer, credentials, endpoint); var observable = testApi.TestCreateObservable <string>(endpoint, Enumerable.Empty <HttpHeader>(), ""); await observable.SingleAsync(); }
public void EmitsADeserializationErrorIfTheJsonSerializerThrowsAnException() { const string rawResponse = "It lives"; serializer.Deserialize <string>(Arg.Any <string>()).Returns(_ => throw new Exception()); apiClient.Send(Arg.Any <Request>()).Returns(x => new Response(rawResponse, true, "text/plain", new List <KeyValuePair <string, IEnumerable <string> > >(), OK)); var credentials = Credentials.WithPassword( "*****@*****.**".ToEmail(), "theirobotmoviesucked123".ToPassword()); var endpoint = Endpoint.Get(BaseUrls.ForApi(ApiEnvironment.Staging), ""); var testApi = new TestApi(endpoint, apiClient, serializer, credentials, endpoint); var observable = testApi.TestCreateObservable <string>(endpoint, Enumerable.Empty <HttpHeader>(), ""); Func <Task> theObservableReturnedWhenTheApiFails = async() => await observable; theObservableReturnedWhenTheApiFails .Should().Throw <DeserializationException <string> >() .Which.Json.Should().Be(rawResponse); }