'Can PactNet be used with MsTest runner?
I have only now started dabbling with PactNet, and I stumbled on the first issue I cannot find any information about.
Can PactNet be used with MsTest runner? All the examples work with xUnit but it is not made clear if this is the only runner that is supported by PactNet.
I tried toying with the demo project and enabling Pact tests on the consumer side there, but when I run the test it does not generate any result and pact file is not created.
Here is what I wrote based on the demo:
[TestClass]
public class ApiMsTest
{
private IPactBuilderV3 pact;
private readonly ApiClient ApiClient;
private readonly int port = 9000;
private readonly List<object> products;
public ApiMsTest()
{
products = new List<object>()
{
new { id = 9, type = "CREDIT_CARD", name = "GEM Visa", version = "v2" },
new { id = 10, type = "CREDIT_CARD", name = "28 Degrees", version = "v1" }
};
var Config = new PactConfig
{
PactDir = Path.Join("..", "..", "..", "..", "..", "pacts"),
LogLevel = PactLogLevel.Debug,
DefaultJsonSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
}
};
pact = Pact.V3("ApiClient", "ProductService", Config).UsingNativeBackend(port);
ApiClient = new ApiClient(new System.Uri($"http://localhost:{port}"));
}
[TestMethod]
public async void GetAllProducts()
{
// Arange
pact.UponReceiving("A valid request for all products")
.Given("products exist")
.WithRequest(HttpMethod.Get, "/api/products")
.WillRespond()
.WithStatus(HttpStatusCode.OK)
.WithHeader("Content-Type", "application/json; charset=utf-8")
.WithJsonBody(new TypeMatcher(products));
await pact.VerifyAsync(async ctx => {
var response = await ApiClient.GetAllProducts();
Assert.Equals(HttpStatusCode.OK, response.StatusCode);
});
}
}
Am I missing anything here? The only field that is missing is outputters, but MsTest does not have this field and Debug.Writeline is used instead, am I right?
AS I wrote this test produces no results whereas XUnit test from demo app produces results.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
