예제 #1
0
        public void MakeAUnSuccessfulDELETERequestTest()
        {
            try
            {
                TestRequester testRequester = new TestRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(testRequester, "http://MakeAUnSuccessfulDELETERequestTest:3000");
                }

                WebRequest.RegisterPrefix("http://MakeAUnSuccessfulDELETERequestTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.BadRequest);

                testRequester.DELETE("/deleteSuccessFail");
                Assert.Fail("Excepection should have been thrown");
            }
            catch (FreeClimbErrorResponseException pe)
            {
                Assert.IsNotNull(pe.getError);
                Assert.AreEqual(pe.getError.getStatus, 400);
                Assert.AreEqual(pe.getError.getMessage, "BadRequest");
            }
        }
예제 #2
0
        public void MakeASuccessfulGETRequestQueryStringTest()
        {
            try
            {
                TestRequester testRequester = new TestRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(testRequester, "http://MakeASuccessfulGETRequestQueryStringTest:3000");
                }

                WebRequest.RegisterPrefix("http://MakeASuccessfulGETRequestQueryStringTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK,
                                                                             "{\"value\":\"EXAMPLE\"}");

                Dictionary <String, String> realQuery = new Dictionary <String, String>();
                realQuery.Add("a", "1");
                realQuery.Add("b", "2");
                realQuery.Add("c", "3");

                string result = testRequester.GET("/getSuccess", realQuery);
                Assert.AreEqual(result, "{\"value\":\"EXAMPLE\"}");
            }
            catch (FreeClimbException pe)
            {
                Assert.Fail(pe.Message);
            }
        }
예제 #3
0
        public void MakeASuccessfulDELETERequestTest()
        {
            try
            {
                TestRequester testRequester = new TestRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5");

                Type      type      = typeof(APIRequester);
                FieldInfo fieldInfo = type.GetField("freeClimbUrl", BindingFlags.NonPublic | BindingFlags.Instance);
                if (fieldInfo != null)
                {
                    fieldInfo.SetValue(testRequester, "http://MakeASuccessfulDELETERequestTest:3000");
                }

                WebRequest.RegisterPrefix("http://MakeASuccessfulDELETERequestTest:3000", new TestWebRequestCreate());

                TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK);

                testRequester.DELETE("/deleteSuccess");
            }
            catch (FreeClimbException pe)
            {
                Assert.Fail(pe.Message);
            }
        }