Skip to content

Step 8 Incorrect expectation, assertion and block layout in Consumer/tests/ApiTest.cs #2

@hwilliams-bod

Description

@hwilliams-bod

Braces are laid out incorrectly
ProductDoesNotExist - Expectation incorrect
GetProductMissingAuthHeader - Assertion incorrect

Consumer/tests/ApiTest.cs:

[Fact]
public async void ProductDoesNotExist()
{
    // Arange
    pact.UponReceiving("A valid request for a product")
            .Given("product with ID 11 does not exist")
            .WithRequest(HttpMethod.Get, "/api/products/11")
            .WithHeader("Authorization", Match.Regex("Bearer 2019-01-14T11:34:18.045Z", "Bearer \\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z"))
        .WillRespond()
            .WithStatus(HttpStatusCode.Unauthorized); 
//Should be  .WithStatus(HttpStatusCode.NotFound);

    await pact.VerifyAsync(async ctx => {
        var response = await ApiClient.GetProduct(11);
        Assert.Equal(HttpStatusCode.NotFound, response.StatusCode);
    });

    [Fact]
    public async void GetProductMissingAuthHeader()
    {
        // Arange
        pact.UponReceiving("A valid request for a product")
                .Given("No auth token is provided")
                .WithRequest(HttpMethod.Get, "/api/products/10")
            .WillRespond()
                .WithStatus(HttpStatusCode.Unauthorized);

        await pact.VerifyAsync(async ctx => {
            var response = await ApiClient.GetProduct(10);
            Assert.Equal(HttpStatusCode.Forbidden, response.StatusCode);
//Should be  Assert.Equal(HttpStatusCode.Unauthorized, response.StatusCode);

        });
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions