public void ShouldRespondWithStringBasedOnConfiguration() { using (FakeHttpServer server = new FakeHttpServer()) { server.Host = "localhost"; server.Port = 8080; server.Path = "api/v1/accounts"; server.ReturnString("Hello, World!!!"); server.StatusCode = HttpStatusCode.OK; server.StatusDescription = "Okey, Dokey"; server.Headers.Add("When", new DateTime(2014, 06, 16).ToString("MM/dd/yyyy")); StringBodyExtractor extractor = new StringBodyExtractor(); server.UseBodyExtractor(extractor); server.Listen(); WebRequest request = WebRequest.Create("http://localhost:8080/api/v1/accounts"); request.Method = "POST"; using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write("Hello, Universe!!!"); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Assert.AreEqual(server.StatusCode, response.StatusCode, "The wrong status code was returned."); Assert.AreEqual(server.StatusDescription, response.StatusDescription, "The wrong status description was returned."); Assert.AreEqual("06/16/2014", response.Headers["When"], "The wrong header was returned"); string responseText = new StreamReader(response.GetResponseStream()).ReadToEnd(); Assert.AreEqual("Hello, World!!!", responseText); Assert.AreEqual("Hello, Universe!!!", extractor.Content); } } }
public void ShouldRespondWithStringBasedOnConfiguration() { using (FakeHttpServer server = new FakeHttpServer()) { server.Host = "localhost"; server.Port = 8080; server.Path = "api/v1/accounts"; server.ReturnString("Hello, World!!!"); server.StatusCode = HttpStatusCode.OK; server.StatusDescription = "Okey, Dokey"; server.Headers.Add("When", new DateTime(2014, 06, 16).ToString("MM/dd/yyyy")); server.Listen(); WebRequest request = WebRequest.Create("http://localhost:8080/api/v1/accounts"); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { Assert.AreEqual(server.StatusCode, response.StatusCode, "The wrong status code was returned."); Assert.AreEqual(server.StatusDescription, response.StatusDescription, "The wrong status description was returned."); Assert.AreEqual("06/16/2014", response.Headers["When"], "The wrong header was returned"); string responseText = getResponseString(response); Assert.AreEqual("Hello, World!!!", responseText); } } }
public void ShouldGetInt32() { using (FakeHttpServer server = new FakeHttpServer("http://localhost:8080/numbers")) { server.ReturnString("4"); server.Listen(); RestClient client = new RestClient("http://localhost:8080"); var response = client.Get("numbers") .WhenSuccess(r => r.FromString <int>()) .Execute(); Assert.IsTrue(response.IsSuccessStatusCode, "An error occurred getting the number."); Assert.AreEqual(4, response.GetResult <int>()); } }
public void ShouldGetInt32() { using (FakeHttpServer server = new FakeHttpServer("http://localhost:8080/numbers")) { server.ReturnString("4"); server.Listen(); RestClient client = new RestClient("http://localhost:8080"); var response = client.Get("numbers") .WhenSuccess(r => r.FromString<int>()) .Execute(); Assert.IsTrue(response.IsSuccessStatusCode, "An error occurred getting the number."); Assert.AreEqual(4, response.GetResult<int>()); } }