public void ShouldSeeaStandardIsMissing() { //Arrange const string standardCode = "-1"; MockProviderService .UponReceiving($"a request to retrieve standard with id '{standardCode}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/standards/{standardCode}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 404 }); var consumer = new StandardApiClient(MockProviderServiceBaseUri); //Act Assert.Throws <EntityNotFoundException>(() => consumer.Get(standardCode)); MockProviderService.VerifyInteractions(); }
public void ShouldSeeAFrameworkIsMissing() { //Arrange const string frameworkId = "1-2-3"; MockProviderService .UponReceiving($"a request to retrieve framework with id '{frameworkId}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/frameworks/{frameworkId}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 404 }); var consumer = new FrameworkApiClient(MockProviderServiceBaseUri); //Act Assert.Throws <EntityNotFoundException>(() => consumer.Get(frameworkId)); MockProviderService.VerifyInteractions(); }
public async Task GetEtaForNextTrip_ReturnsExpectedTripInformation() { // /eta/routeName/direction/stopName // Arrange string routeName = "20"; string direction = "Northbound"; string stopName = "Opera"; var busId = 99999; var eta = 5; var busIdRegex = "^[1-9]{1,5}$"; // All positive integers between 1 and 99999 var etaIdRegex = "^[0-9]{0,2}$"; // All positive integers between 0 and 99 var expectedBusInfo = new { busID = Match.Type(busId), eta = Match.Type(eta), }; MockProviderService .Given($"There are buses scheduled for route {routeName} and direction {direction} to arrive at stop {stopName}") // Describe the state the provider needs to setup .UponReceiving($"A request for eta for route {routeName} to {stopName} station") // textual description - business case .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = Uri.EscapeUriString($"/eta/{routeName}/{direction}/{stopName}"), }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = expectedBusInfo }); var consumer = new BusServiceClient(MockServerBaseUri); // Act var result = await consumer.GetBusInfo(routeName, direction, stopName); // Assert Assert.That(result.BusID.ToString(), Does.Match(busIdRegex)); Assert.That(result.Eta.ToString(), Does.Match(etaIdRegex)); // NOTE: Verifies that interactions registered on the mock provider are called at least once MockProviderService.VerifyInteractions(); }
public void ShouldGetFramework() { //Arrange const string frameworkId = "403-2-1"; MockProviderService .UponReceiving($"a request to retrieve framework with id '{frameworkId}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/frameworks/{frameworkId}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { FrameworkId = frameworkId } }); var consumer = new FrameworkApiClient(MockProviderServiceBaseUri); //Act var result = consumer.Get(frameworkId); // TODO is this needed? //Assert Assert.AreEqual(frameworkId, result.FrameworkId); MockProviderService.VerifyInteractions(); }
public void ShouldGetaStandard() { //Arrange const string standardCode = "12"; MockProviderService .UponReceiving($"a request to retrieve standard with id '{standardCode}'") .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = $"/standards/{standardCode}", Headers = new Dictionary <string, string> { { "Accept", "application/json" } } }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, string> { { "Content-Type", "application/json; charset=utf-8" } }, Body = new { StandardId = standardCode } }); var consumer = new StandardApiClient(MockProviderServiceBaseUri); //Act var result = consumer.Get(standardCode); // TODO is this needed? //Assert Assert.AreEqual(standardCode, result.StandardId); MockProviderService.VerifyInteractions(); }
public async Task GetProduct_ReturnsExpectedProduct() { var guidRegex = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}"; var expectedProductId = Guid.Parse("E0C2E684-D83F-45C3-A6E5-D62A6F83A0BD"); var expectedName = "Test"; var expectedProduct = new { id = Match.Regex(expectedProductId.ToString(), $"^{guidRegex}$"), name = Match.Type(expectedName), description = Match.Type("A product for testing"), }; MockProviderService .Given("A Product with expected structure") // Describe the state the provider needs to setup .UponReceiving("a GET request for a single product") // textual description - business case .With(new ProviderServiceRequest { Method = HttpVerb.Get, Path = Match.Regex($"/{expectedProductId}", $"^\\/{guidRegex}$"), }) .WillRespondWith(new ProviderServiceResponse { Status = 200, Headers = new Dictionary <string, object> { { "Content-Type", "application/json; charset=utf-8" } }, Body = expectedProduct }); var consumer = new ProductClient(MockServerBaseUri); var result = await consumer.Get(expectedProductId); Assert.AreEqual(expectedProductId, result.Id); Assert.AreEqual(expectedName, result.Name); MockProviderService.VerifyInteractions(); }
public void VerifyAndClearInteractions() { MockProviderService.VerifyInteractions(); MockProviderService.ClearInteractions(); }