-
Notifications
You must be signed in to change notification settings - Fork 234
/
Copy pathProviderTests.cs
80 lines (71 loc) · 2.54 KB
/
ProviderTests.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.IO;
using System.Text.Json;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using PactNet;
using PactNet.Infrastructure.Outputters;
using PactNet.Output.Xunit;
using PactNet.Verifier;
using Provider.Orders;
using Xunit;
using Xunit.Abstractions;
namespace Provider.Tests
{
public class ProviderTests : IDisposable
{
private static readonly Uri ProviderUri = new("http://localhost:5000");
private static readonly JsonSerializerOptions Options = new()
{
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
PropertyNameCaseInsensitive = true
};
private readonly IHost server;
private readonly PactVerifier verifier;
public ProviderTests(ITestOutputHelper output)
{
this.server = Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseUrls(ProviderUri.ToString());
webBuilder.UseStartup<TestStartup>();
})
.Build();
this.server.Start();
this.verifier = new PactVerifier("Orders API", new PactVerifierConfig
{
LogLevel = PactLogLevel.Debug,
Outputters = new List<IOutput>
{
new XunitOutput(output)
}
});
}
public void Dispose()
{
this.server.Dispose();
this.verifier.Dispose();
}
[Fact]
public void Verify()
{
string pactPath = Path.Combine("..",
"..",
"..",
"..",
"Consumer.Tests",
"pacts",
"Fulfilment API-Orders API.json");
this.verifier
.WithHttpEndpoint(ProviderUri)
.WithMessages(scenarios =>
{
scenarios.Add("an event indicating that an order has been created", () => new OrderCreatedEvent(1));
}, Options)
.WithFileSource(new FileInfo(pactPath))
.WithProviderStateUrl(new Uri(ProviderUri, "/provider-states"))
.Verify();
}
}
}