public void MakeAUnSuccessfulPOSTRequestTest() { try { TestRequester testRequester = new TestRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(testRequester, "http://MakeAUnSuccessfulPOSTRequestTest:3000"); } WebRequest.RegisterPrefix("http://MakeAUnSuccessfulPOSTRequestTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.BadRequest); string result = testRequester.POST("/postSuccessFail", "{ }"); Assert.Fail("Excepection should have been thrown"); } catch (PersyErrorResponseException pe) { Assert.IsNotNull(pe.getError); Assert.AreEqual(pe.getError.getStatus, 400); Assert.AreEqual(pe.getError.getMessage, "BadRequest"); } }
public void MakeASuccessfulPOSTRequestTest() { try { TestRequester testRequester = new TestRequester("AC736ca2078721a9a41fb47f07bf40d9e21cb304da", "8e3d1c1c519fc761856f8cc825bcfea94d8c58b5"); Type type = typeof(APIRequester); FieldInfo fieldInfo = type.GetField("persyUrl", BindingFlags.NonPublic | BindingFlags.Instance); if (fieldInfo != null) { fieldInfo.SetValue(testRequester, "http://MakeASuccessfulPOSTRequestTest:3000"); } WebRequest.RegisterPrefix("http://MakeASuccessfulPOSTRequestTest:3000", new TestWebRequestCreate()); TestWebRequestCreate.MockHttpWebRequestWithGivenResponseCode(HttpStatusCode.OK, "{\"value\":\"EXAMPLE\"}"); string result = testRequester.POST("/postSuccess", "{ }"); Assert.AreEqual(result, "{\"value\":\"EXAMPLE\"}"); } catch (PersyException pe) { Assert.Fail(pe.Message); } }