Jump to content

Regex no PactNet 4.0


pmh
 Share

Recommended Posts

Estou a usar o Pact NET, mas não consigo usar o Regex Matcher. Do lado do consumer tenho o seguinte código: 

    [Fact]
    public async void GetProductById_AssuresTheCorrectProductByIdIsRetrieved_CorrectProductIsRetrieved()
    {
        // Arange
        var pact = Pact.V3("ApiClient", "ProductService", PactHelper.GetPactConfiguration());

        // initialize backend
        var pactBuilder = pact.UsingNativeBackend(9000);

        var products = new List<object>()
            {
                new { id = 9, name = "Pants", sku = "SKU9", price = 10.00M },
                new { id = 10, name = "Shirt", sku = Match.Regex("SKU10", "SKU*"), price = 100.00M }
            };

        pactBuilder
            .UponReceiving("Get product with id 10")
            .WithRequest(HttpMethod.Get, "/api/products/10")
            .WillRespond()
            .WithStatus(HttpStatusCode.OK)
            .WithHeader("Content-Type", "application/json; charset=utf-8")
            .WithJsonBody(products[1]);

        var gateway = new ProductGateway(new System.Uri(PactHelper.GetIntegrationData()));

        // Act
        await pactBuilder.VerifyAsync(async ctx =>
        {
            var response = await gateway.GetProductById(10);

            // Assert
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        });
    }

Se remover o sku = Match.Regex("SKU10", "SKU*") e simplesmente usar sku = "SKU10" o pacto é verificado pelo providercom sucesso. Alguém familiarizado com isto sabe se falta alguma coisa ou este Matcher não está disponível para o Pact 4.0? Não é relacionado com regex, porque tentei usar outros Matchers e o pact também não foi verificado.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.