Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exception when running demo provider test #17

Open
panosru opened this issue Jul 6, 2020 · 0 comments
Open

Exception when running demo provider test #17

panosru opened this issue Jul 6, 2020 · 0 comments

Comments

@panosru
Copy link

panosru commented Jul 6, 2020

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant