Пример #1
0
        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");
                }
            }
        }
Пример #2
0
        public MockServer(MockResponse res, Action<HttpListenerRequest> onRequest = null)
        {
            mockResponse = res;
            Port = _port;
            OnRequest = onRequest;
            _port += 1;

            Run();
        }
Пример #3
0
 public TestClient(MockResponse res)
 {
     server = new MockServer(res, ctx => Request = ctx);
     Client = new SlideRoom.API.SlideRoomClient(ApiHashKey, AccessKey, Organization, EmailAddress, "http://localhost:" + server.Port + "/");
 }
Пример #4
0
        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");
                }
            }
        }
Пример #5
0
 public TestClient(MockResponse res)
 {
     server = new MockServer(res, ctx => Request = ctx);
     Client = new SlideRoom.API.SlideRoomClient(ApiHashKey, AccessKey, Organization, EmailAddress, "http://localhost:" + server.Port + "/");
 }