Ich versuche, meinen Kopf über PACT zu bekommen, und ich verwende die PACT-Net Bibliothek, um dies zu erreichen.C# PACT - Consumer Driven Contact Test - Schreibgerät Test für Provider
Meine Komponententests auf dem Consumer funktionieren gut, aber ich versuche, die Komponententests auf dem Provider einzurichten. Ich verwende das grundlegende Web-API-Projekt, das geladen wird, wenn Sie die Web-API-Vorlage in Visual Studio verwenden, wodurch der Values-API-Controller erstellt wird. Ich teste gerade die Methode Get IEumerable<string>
als End-to-End-Test des Prozesses. Ich folge auch dem Beispiel auf der Pact-Net github Seite. Hier ist die Unit-Test habe ich bisher:
[Fact]
public void EnsureValuesReturnedFromApi()
{
var config = new PactVerifierConfig
{
Outputters = new List<IOutput>
{
new XUnitOutput(_output)
}
};
using (WebApp.Start<TestStartup>(serviceUri))
{
var pactVerifier = new PactVerifier(config);
pactVerifier.ProviderState($"{serviceUri}/provider-states")
.ServiceProvider("Values API", serviceUri)
.HonoursPactWith("Consumer")
.PactUri("http://localhost:8080/pacts/provider/Values%20API/consumer/Consumer/latest")
.Verify();
}
}
Wann immer ich die Unit-Test betreibe ich die folgende Fehlermeldung erhalten:
Reading pact at http://localhost:8080/pacts/provider/Values%20API/consumer/Consumer/latest
Verifying a pact between Consumer and Values API
Given When I want the values
Getting a list
with GET /api/values
returns a response which
has status code 200 (FAILED - 1)
has a matching body (FAILED - 2)
includes headers
"Accept" with value "application/json" (FAILED - 3)
"Content-Type" with value "application/json" (FAILED - 4)
Failures:
1) Verifying a pact between Consumer and Values API Given When I want the values Getting a list with GET /api/values returns a response which has status code 200
Failure/Error: set_up_provider_state interaction.provider_state, options[:consumer]
Pact::ProviderVerifier::SetUpProviderStateError:
Error setting up provider state 'When I want the values' for consumer 'Consumer' at http://localhost:9222/provider-states. response status=500 response body=
2) Verifying a pact between Consumer and Values API Given When I want the values Getting a list with GET /api/values returns a response which has a matching body
Failure/Error: set_up_provider_state interaction.provider_state, options[:consumer]
Pact::ProviderVerifier::SetUpProviderStateError:
Error setting up provider state 'When I want the values' for consumer 'Consumer' at http://localhost:9222/provider-states. response status=500 response body=
3) Verifying a pact between Consumer and Values API Given When I want the values Getting a list with GET /api/values returns a response which includes headers "Accept" with value "application/json"
Failure/Error: set_up_provider_state interaction.provider_state, options[:consumer]
Pact::ProviderVerifier::SetUpProviderStateError:
Error setting up provider state 'When I want the values' for consumer 'Consumer' at http://localhost:9222/provider-states. response status=500 response body=
4) Verifying a pact between Consumer and Values API Given When I want the values Getting a list with GET /api/values returns a response which includes headers "Content-Type" with value "application/json"
Failure/Error: set_up_provider_state interaction.provider_state, options[:consumer]
Pact::ProviderVerifier::SetUpProviderStateError:
Error setting up provider state 'When I want the values' for consumer 'Consumer' at http://localhost:9222/provider-states. response status=500 response body=
1 interaction, 1 failure
Failed interactions:
* Getting a list given When I want the values
ich meine Frage erraten ist, muss ich tatsächlich den Test HTTP-Aufrufe an/api/values oder fehlt etwas anderes?
Dank