コード例 #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
        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");
                }
            }
        }