snatch-dev / Pactify

Contract testing tool for .NET Core.
MIT License
52 stars 10 forks source link

Exception when running demo provider test #17

Open panosru opened 4 years ago

panosru commented 4 years ago

When I run the demo test project with Pactify library installed from NuGet, I'm getting this:

image

Demo.Test.Integration.Provider.Provider_Should_Meet_Consumers_Expectations

System.ArgumentNullException : Value cannot be null.
Parameter name: source
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
   at Pactify.Verifiers.HttpCouplingVerifier.VerifyAsync(HttpInteractionDefinition definition, PactDefinitionOptions options)
   at Pactify.PactVerifier.VerifyAsync()
   at Demo.Test.Integration.Provider.Provider_Should_Meet_Consumers_Expectations() in /***/Provider.cs:line 15
--- End of stack trace from previous location where exception was thrown ---

When I run the demo test having Pactify cloned from this repo as a reference project, I'm getting this:

image

Demo.Test.Integration.Provider.Provider_Should_Meet_Consumers_Expectations

Pactify.PactifyException : Expected response status code OK, but was NotFound
Expected response header content-Type was not present.
   at Pactify.PactVerifier.VerifyAsync() in /***/Pactify/PactVerifier.cs:line 90
   at Demo.Test.Integration.Provider.Provider_Should_Meet_Consumers_Expectations() in /***/Provider.cs:line 15
--- End of stack trace from previous location where exception was thrown ---

Source code for Consumer.cs:

using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Demo.Test.Integration.Fixtures;
using Pactify;
using Xunit;

namespace Demo.Test.Integration
{
    public class Consumer
    {
        [Fact]
        public async Task Consumer_Should_Create_A_Pact()
        {
            var options = new PactDefinitionOptions  
            {  
                IgnoreContractValues = true,  
                IgnoreCasing = true  
            };  

            await PactMaker  
                .Create(options)  
                .Between("orders", "parcels")  
                .WithHttpInteraction(cb => cb  
                    .Given("There is a parcel with some id")  
                    .UponReceiving("A GET Request to retrieve the parcel")  
                    .With( request => request  
                        .WithMethod(HttpMethod.Get)  
                        .WithPath("api/parcels/1"))  
                    .WillRespondWith(response => response  
                        .WithHeader("Content-Type", "application/json")  
                        .WithStatusCode(HttpStatusCode.OK)  
                        .WithBody<ParcelReadModel>())) 
                .PublishedAsFile(System.IO.Path.Join(
                    (new DirectoryInfo(Environment.CurrentDirectory)).Parent.Parent.Parent.ToString(), "pacts"))
                .MakeAsync();
        }
    }
}

Source code for Provider.cs:

using System;
using System.IO;
using System.Threading.Tasks;
using Demo.Test.Integration.Fixtures;
using Pactify;
using Xunit;

namespace Demo.Test.Integration
{
    public class Provider
    {
        [Fact]
        public async Task Provider_Should_Meet_Consumers_Expectations()
        {
            await PactVerifier
                .CreateFor<Startup>()
                .Between("orders", "parcels")
                .RetrievedFromFile(System.IO.Path.Join(
                    (new DirectoryInfo(Environment.CurrentDirectory)).Parent.Parent.Parent.ToString(), "pacts"))
                .VerifyAsync();
        }
    }
}

Project structure:

Demo.Test.Integration/
    Fixtures/
        ParcelReadModel.cs
        Startup.cs
    pacts/
        orders-parcels.json (generated)
    Consumer.cs
    Provider.cs

The source code for files ParcelReadModel.cs and Startup.cs is untouched, they are exactly as is here. I also tried with netcoreapp2.1 and 3.1, I'm getting exactly the same result.

Thanks!