Post() public method

The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI.
public Post ( string url ) : UnityAgentRequest
url string The request URL.
return UnityAgentRequest
Esempio n. 1
0
        public void TestApiPostSyncronous()
        {
            UnityAgent agent = new UnityAgent();
            string url = GetTestUrl("post");
            string testString = Guid.NewGuid().ToString();

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

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
            Assert.That(response.Body.Contains(testString));
            StringAssert.AreEqualIgnoringCase((string)response.Json["url"], url);
        }
Esempio n. 2
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);
        }