public async Task TestGetOnRootOfExampleApiReturnsExpectedThing() { _mockProviderService.Given("I just hit controller root") .UponReceiving("A GET request at the root of the controller") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/" }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "text/plain; charset=utf-8" } }, Body = "Ahh OK" }); var consumer = new ExampleApiClient(); var result = await consumer.GetString(_mockProviderServiceBaseUri); Assert.AreEqual("Ahh OK", result); _mockProviderService.VerifyInteractions(); //NOTE: Verifies that interactions registered on the mock provider are called at least once }
public async Task TestGetOnExampleApiWithParamsReturnsExpectedThing() { _mockProviderService.Given("I provide param arguments to a method on the API") .UponReceiving("A GET request to return a populated ExampleObject with params") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = "/Get/1/test/", Headers = new Dictionary <string, object> { { "Host", "localhost:9222" }, { "Version", "HTTP/1.1" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { Id = 1, WhenItHappened = DateTime.Now, ExampleString = "test" } }); var consumer = new ExampleApiClient(); var result = await consumer.GetObject(_mockProviderServiceBaseUri, 1, "test"); Assert.AreEqual(1, result.Item1.Id); Assert.AreEqual("test", result.Item1.ExampleString); _mockProviderService.VerifyInteractions(); //NOTE: Verifies that interactions registered on the mock provider are called at least once }