A REST API Client designed with ease of use in mind. Based on SuperAgent
示例#1
0
        public void TestApiDeleteSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("delete");

            var response = agent
                .Delete(url)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
示例#2
0
        public void TestApiHeadSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("get");

            var response = agent
                .Head(url)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.That(response.Body.Length == 0);
        }
示例#3
0
        public void TestApiGzipSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("gzip");

            var response = agent
                .Get(url)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.That((bool)response.Json["gzipped"] == true);
        }
示例#4
0
        public void TestApiGetSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("get");

            var response = agent
                .Get(url)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            StringAssert.AreEqualIgnoringCase((string)response.Json["url"], url);
        }
示例#5
0
        public void TestApiPatchSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("patch");
            string testString = Guid.NewGuid().ToString();

            var response = agent
                .Patch(url)
                .Send(testString)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.That(response.Body.Contains(testString));
            StringAssert.AreEqualIgnoringCase((string)response.Json["url"], url);
        }
示例#6
0
        public void TestApiPostJsonSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("post");
            var testData = new {
                Guid = Guid.NewGuid().ToString(),
                Message = "Hello",
                Number = new Random().Next(),
                EmptyString = String.Empty,
                NestedObj = new {
                    NestedKey = "nested string"
                }
            };

            JsonData sentJsonData = JsonMapper.ToJson(testData);

            var response = agent
                .Post(url)
                .Send(sentJsonData)
                .Begin()
                .Result;

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);

            JsonData recvJsonData = ExtractJsonFromForm(response);

            Assert.AreEqual((string)	recvJsonData["Guid"], 					testData.Guid);
            Assert.AreEqual((string)	recvJsonData["Message"], 				testData.Message);
            Assert.AreEqual((int)		recvJsonData["Number"], 				testData.Number);
            Assert.AreEqual((string)	recvJsonData["EmptyString"], 			String.Empty);
            Assert.AreEqual((string)	recvJsonData["NestedObj"]["NestedKey"], testData.NestedObj.NestedKey);
        }