title: Rewriting Pact contract test from JavaScript to C#
body: <p>Apologies if this question is greaking the rules.</p>
  <p>I have this <code>js</code> class:</p>
  <p>src/get.js</p>
  <pre class="lang-js prettyprint-override"><code>const { get } = require('axios')
  
  module.exports = function () {
      return get(`http://localhost:1234/token/1234`)
  }
  </code></pre>
  <p>and also this test:</p>
  <p>consumer.pact.js</p>
  <pre class="lang-js prettyprint-override"><code>const path = require(&quot;path&quot;)
  const chai = require(&quot;chai&quot;)
  const { Pact, Matchers } = require(&quot;@pact-foundation/pact&quot;)
  const chaiAsPromised = require(&quot;chai-as-promised&quot;)
  const expect = chai.expect
  chai.use(chaiAsPromised)
  const { string } = Matchers
  const get = require('../src/get')
  
  describe('Consumer Test', () =&gt; {
      const provider = new Pact({
          consumer: &quot;React&quot;,
          provider: &quot;token&quot;,
          port: 1234,
          log: path.resolve(process.cwd(), 'logs', 'pact.log'),
          dir: path.resolve(process.cwd(), 'pacts'),
          logLevel: &quot;INFO&quot;
      });
  
      before(() =&gt; provider.setup()
      .then(() =&gt; provider.addInteraction({
          state: &quot;user token&quot;,
          uponReceiving: &quot;GET user token&quot;,
          withRequest: {
              method: &quot;GET&quot;,
              path: &quot;/token/1234&quot;,
              headers: { Accept: &quot;application/json, text/plain, */*&quot; }
          },
          willRespondWith: {
              headers: { &quot;Content-Type&quot;: &quot;application/json&quot; },
              status: 200,
              body: { &quot;token&quot;: string(&quot;bearer&quot;) }
          }
      })))
  
      it('OK response', () =&gt; {
          get()
          .then((response) =&gt; {
              expect(response.statusText).to.be.equal('OK')
          })
      })
  
      after(() =&gt; provider.finalize())
  })
  </code></pre>
  <p>I'm trying to write the equivalent in C# using the <code>js</code> code and the example <a href="https://github.com/pact-foundation/pact-net" rel="nofollow noreferrer">here</a>. I've done all except the <code>GET</code> and admittedly, what I've done so far might be way off. Here's what I have so far:</p>
  <p>ConsumerTest.cs</p>
  <pre><code>//using NUnit.Framework;
  using System.Collections.Generic;
  using PactNet;
  using PactNet.Mocks.MockHttpService;
  using PactNet.Mocks.MockHttpService.Models;
  using Xunit;
  
  namespace PactTests.PactTests
  {
    public class ConsumerTest : IClassFixture&lt;ConsumerPact&gt;
    {
      private IMockProviderService _mockProviderService;
      private string _mockProviderServiceBaseUri;
  
      public ConsumerTest(ConsumerPact data)
      {
        _mockProviderService = data.MockProviderService;
        _mockProviderService.ClearInteractions(); //NOTE: Clears any previously registered interactions before the test is run
        _mockProviderServiceBaseUri = data.MockProviderServiceBaseUri;
      }
  
      [Fact]
      public void OKResponse()
      {
        //Arrange
        _mockProviderService
          .Given(&quot;user token&quot;)
          .UponReceiving(&quot;GET user token&quot;)
          .With(new ProviderServiceRequest
          {
            Method = HttpVerb.Get,
            Path = &quot;/token/1234&quot;,
            Headers = new Dictionary&lt;string, object&gt;
            {
              { &quot;Accept&quot;, &quot;application/json, text/plain, */*&quot; }
            }
          })
          .WillRespondWith(new ProviderServiceResponse
          {
            Status = 200,
            Headers = new Dictionary&lt;string, object&gt;
            {
              { &quot;Content-Type&quot;, &quot;application/json&quot; }
            },
            Body = new //NOTE: Note the case sensitivity here, the body will be serialised as per the casing defined
            {
              token = &quot;bearer&quot;
            }
          }); //NOTE: WillRespondWith call must come last as it will register the interaction
  
          var consumer = new SomethingApiClient(_mockProviderServiceBaseUri);
  
        //Act
        var result = consumer.GetSomething(&quot;tester&quot;);
  
        //Assert
        Assert.Equal(&quot;tester&quot;, result.id);
  
        _mockProviderService.VerifyInteractions(); //NOTE: Verifies that interactions registered on the mock provider are called at least once
      }
    }
  }
  </code></pre>
  <p>ConsumerPact.cs</p>
  <pre><code>using PactNet;
  using PactNet.Mocks.MockHttpService;
  using System;
  
  namespace PactTests.PactTests
  {
    public class ConsumerPact : IDisposable
    {
      public IPactBuilder PactBuilder { get; private set; }
      public IMockProviderService MockProviderService { get; private set; }
  
      public int MockServerPort { get { return 1234; } }
  
      public string MockProviderServiceBaseUri { get { return String.Format(&quot;http://localhost:{0}&quot;, MockServerPort); } }
  
      public ConsumerPact()
      {
        // Pact configuration
        var pactConfig = new PactConfig
        {
          SpecificationVersion = &quot;2.0.17&quot;,
          PactDir = @&quot;Users/paulcarron/git/pact/pacts&quot;,
          LogDir = @&quot;Users/paulcarron/git/pact/logs&quot;
        };
  
        PactBuilder = new PactBuilder(pactConfig);
  
        PactBuilder
          .ServiceConsumer(&quot;React&quot;)
          .HasPactWith(&quot;token&quot;);
  
        MockProviderService = PactBuilder.MockService(MockServerPort);
  
      }
  
      public void Dispose()
      {
        PactBuilder.Build();
      }
    }
  }
  </code></pre>
  <p>How do I do the <code>GET</code>?</p>