public void HandleMalformedJSON() { var res = new MockResponse() { ContentType = "application/json", Code = HttpStatusCode.InternalServerError, Body = @"{ ""mess" }; using (var c = new TestClient(res)) { try { c.Client.GetRawResponse("bad", new NameValueCollection()); Assert.Fail("should throw an exception"); } catch (SlideRoom.API.SlideRoomAPIException e) { Assert.AreEqual("Unterminated string. Expected delimiter: \". Path '', line 1, position 7.", e.Message); Assert.AreEqual(HttpStatusCode.InternalServerError, e.StatusCode); } catch { Assert.Fail("should throw a SlideRoomAPIException"); } } }
public MockServer(MockResponse res, Action<HttpListenerRequest> onRequest = null) { mockResponse = res; Port = _port; OnRequest = onRequest; _port += 1; Run(); }
public TestClient(MockResponse res) { server = new MockServer(res, ctx => Request = ctx); Client = new SlideRoom.API.SlideRoomClient(ApiHashKey, AccessKey, Organization, EmailAddress, "http://localhost:" + server.Port + "/"); }
private static void MockBadResponse(string message, HttpStatusCode code) { var res = new MockResponse() { ContentType = "application/json", Code = code, Body = @"{ ""message"": """ + message + @""" } " }; using (var c = new TestClient(res)) { try { c.Client.GetRawResponse("bad", new NameValueCollection()); Assert.Fail("should throw an exception"); } catch (SlideRoom.API.SlideRoomAPIException e) { Assert.AreEqual(message, e.Message); Assert.AreEqual(code, e.StatusCode); } catch { Assert.Fail("should throw a SlideRoomAPIException"); } } }
public TestClient(MockResponse res) { server = new MockServer(res, ctx => Request = ctx); Client = new SlideRoom.API.SlideRoomClient(ApiHashKey, AccessKey, Organization, EmailAddress, "http://localhost:" + server.Port + "/"); }