public void Add_customer() { //Arrange _mockProviderService .Given("There is a service") .UponReceiving("A POST request to create a customer") .With(new ProviderServiceRequest { Method = HttpVerb.Post, Path = "/customers", Query = "", Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new Customer { Firstname = "richard", Surname = "parkins" } }) .WillRespondWith(new ProviderServiceResponse { Status = 201, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" }, { "Location", "http://localhost:5000/customers/richard-parkins" } }, Body = new Customer { Id = "richard-parkins", Firstname = "richard", Surname = "parkins" } }); var consumer = new PactConsumer(_mockProviderServiceBaseUri); //Act var result = consumer.CreateUser("richard", "parkins").Result; //Assert Assert.EndsWith("/customers/richard-parkins", result.ToString()); _mockProviderService.VerifyInteractions(); }
public async Task DoTheThing_Succeeds_WhenProvidedId() { // arrange const string id = "foo"; const string expectedResponse = "bar"; _mockProviderService .Given($"There is a thing with id '{id}'") .UponReceiving("A GET request to retrieve the thing") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/api/theThing/{id}", Headers = new Dictionary <string, object> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> // required { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { Value = expectedResponse } }); var consumer = new PactConsumer(MockProviderServiceBaseUri); // act var result = await consumer.DoTheThingAsync(id); // assert Assert.AreEqual(expectedResponse, result); _mockProviderService.VerifyInteractions(); }