public async Task PathOnly_HappyPath() { var serviceMock = new ServiceMock("http://*****:*****@"{ ""someProp"": ""propVal1"", ""someArray"":[""a1"",""a2"",""a3""]}" , Encoding.UTF8, "application/json"); var response = await httpClient.PutAsync("test/id", bodyContent); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The status code is not as expected!"); // Assert.AreEqual("text\\text", response.Headers.) string responseContent = await response.Content.ReadAsStringAsync(); Assert.AreEqual(@"{""status"":0, ""message"":""Test succeeded""}", responseContent, "The response content is not as expected!"); } } finally { await serviceMock.Stop(); } }
public async Task PathOnly_Http403_HappyPath() { var serviceMock = new ServiceMock("http://localhost:8088/"); serviceMock.SetupGet <string, string>("test/path") .ContentType("text\\text") .ResponseStatus(HttpStatusCode.Forbidden) .BodyProcessor(rs => ProcessBasicRequest((string)rs)); serviceMock.Start(); try { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://localhost:8088/"); var response = await httpClient.GetAsync("test/path"); Assert.AreEqual(HttpStatusCode.Forbidden, response.StatusCode, "The status code is not as expected!"); // Assert.AreEqual("text\\text", response.Headers.) string content = await response.Content.ReadAsStringAsync(); Assert.AreEqual("Basic test response!", content, "The response content is not as expected!"); } } finally { await serviceMock.Stop(); } }
public async Task PathAndQueryParam_SimpleSyntax_HappyPath() { var serviceMock = new ServiceMock("http://localhost:8088/"); serviceMock.SetupGet("test/path") .QueryParam("param", "123") .ContentType("text\\text") .BodyProcessor(rs => ProcessBasicRequest((string)rs)); serviceMock.Start(); try { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://localhost:8088/"); var response = await httpClient.GetAsync("test/path?param=123"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The status code is not as expected!"); // Assert.AreEqual("text\\text", response.Headers.) string content = await response.Content.ReadAsStringAsync(); Assert.AreEqual("Basic test response!", content, "The response content is not as expected!"); } } finally { await serviceMock.Stop(); } }
public async Task PathOnly_DynamicResponse_HappyPath() { var serviceMock = new ServiceMock("http://localhost:8088/"); serviceMock.SetupGet <dynamic, dynamic>("test/path") .ContentType("text\\json") .ResponseStatus(HttpStatusCode.OK) .ResponseBody(() => new { SomeValue1 = "SomeValue1", SomeValue2 = "SomeValue2" }); serviceMock.Start(); try { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri("http://localhost:8088/"); var response = await httpClient.GetAsync("test/path"); Assert.AreEqual(HttpStatusCode.OK, response.StatusCode, "The status code is not as expected!"); // Assert.AreEqual("text\\text", response.Headers.) string content = await response.Content.ReadAsStringAsync(); var responseObj = Newtonsoft.Json.Linq.JObject.Parse(content); Assert.AreEqual("SomeValue1", responseObj["SomeValue1"], "The response content is not as expected!"); Assert.AreEqual("SomeValue2", responseObj["SomeValue2"], "The response content is not as expected!"); } } finally { await serviceMock.Stop(); } }