Skip to content

Commit d0c95d6

Browse files
committed
Merge branch 'klimisa-master'
2 parents 87ca33e + 10e1281 commit d0c95d6

File tree

10 files changed

+243
-93
lines changed

10 files changed

+243
-93
lines changed

PactNet.Tests/Core/MockProviderHostConfigTests.cs

Lines changed: 60 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ namespace PactNet.Tests.Core
77
{
88
public class MockProviderHostConfigTests
99
{
10-
private IPactCoreHostConfig GetSubject(int port = 2322, bool enableSsl = false, string consumerName = "My Test Consumer", string providerName = "My Test Provider", PactConfig pactConfig = null, IPAddress host = IPAddress.Loopback)
10+
private IPactCoreHostConfig GetSubject(int port = 2322, bool enableSsl = false,
11+
string consumerName = "My Test Consumer", string providerName = "My Test Provider",
12+
PactConfig pactConfig = null, IPAddress host = IPAddress.Loopback, string sslCert = null, string sslKey = null)
1113
{
12-
return new MockProviderHostConfig(port, enableSsl, consumerName, providerName, pactConfig ?? new PactConfig(), host);
14+
return new MockProviderHostConfig(port, enableSsl, consumerName, providerName,
15+
pactConfig ?? new PactConfig(), host, sslCert, sslKey);
1316
}
1417

1518
[Fact]
@@ -32,7 +35,8 @@ public void Ctor_WhenCalled_SetsTheCorrectArgs()
3235

3336
var expectedLogFilePath = BuildExpectedLogFilePath(pactConfig.LogDir, providerName);
3437
var expectedPactDir = BuildExpectedPactDir(pactConfig.PactDir);
35-
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir, pactConfig.SpecificationVersion, consumerName, providerName);
38+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
39+
pactConfig.SpecificationVersion, consumerName, providerName);
3640

3741
Assert.Equal(expectedArguments, config.Arguments);
3842
}
@@ -50,7 +54,31 @@ public void Ctor_WhenCalledWithSsl_SetsTheCorrectArgs()
5054

5155
var expectedLogFilePath = BuildExpectedLogFilePath(pactConfig.LogDir, providerName);
5256
var expectedPactDir = BuildExpectedPactDir(pactConfig.PactDir);
53-
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir, pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
57+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
58+
pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
59+
60+
Assert.Equal(expectedArguments, config.Arguments);
61+
}
62+
63+
[Fact]
64+
public void Ctor_WhenCalledWithCustomSsl_SetsTheCorrectArgs()
65+
{
66+
var port = 9332;
67+
var pactConfig = new PactConfig();
68+
var consumerName = "Cons";
69+
var providerName = "The best one";
70+
var enableSsl = true;
71+
var sslCert = "..\\cert\\localhost.cer";
72+
var sslKey = "..\\cert\\localhost.key";
73+
74+
var config = GetSubject(port, enableSsl, consumerName, providerName, pactConfig, IPAddress.Loopback, sslCert, sslKey);
75+
76+
var expectedLogFilePath = BuildExpectedLogFilePath(pactConfig.LogDir, providerName);
77+
var expectedPactDir = BuildExpectedPactDir(pactConfig.PactDir);
78+
var expectedSslCert = BuildExpectedSslOption(sslCert);
79+
var expectedSslKey = BuildExpectedSslOption(sslKey);
80+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
81+
pactConfig.SpecificationVersion, consumerName, providerName, enableSsl, IPAddress.Loopback, expectedSslCert, expectedSslKey);
5482

5583
Assert.Equal(expectedArguments, config.Arguments);
5684
}
@@ -69,7 +97,8 @@ public void Ctor_WhenCalledWithHost_SetsTheCorrectArgs()
6997

7098
var expectedLogFilePath = BuildExpectedLogFilePath(pactConfig.LogDir, providerName);
7199
var expectedPactDir = BuildExpectedPactDir(pactConfig.PactDir);
72-
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir, pactConfig.SpecificationVersion, consumerName, providerName, enableSsl, host);
100+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
101+
pactConfig.SpecificationVersion, consumerName, providerName, enableSsl, host);
73102

74103
Assert.Equal(expectedArguments, config.Arguments);
75104
}
@@ -79,7 +108,7 @@ public void Ctor_WhenCalledWithNonDefaultLogDirectory_SetsTheCorrectArgs()
79108
{
80109
var port = 9332;
81110
var logDir = "./test";
82-
var pactConfig = new PactConfig { LogDir = logDir };
111+
var pactConfig = new PactConfig {LogDir = logDir};
83112
var consumerName = "Cons";
84113
var providerName = "The best one";
85114
var enableSsl = true;
@@ -88,7 +117,8 @@ public void Ctor_WhenCalledWithNonDefaultLogDirectory_SetsTheCorrectArgs()
88117

89118
var expectedLogFilePath = BuildExpectedLogFilePath(logDir + "\\", providerName);
90119
var expectedPactDir = BuildExpectedPactDir(pactConfig.PactDir);
91-
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir, pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
120+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
121+
pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
92122

93123
Assert.Equal(expectedArguments, config.Arguments);
94124
}
@@ -98,7 +128,7 @@ public void Ctor_WhenCalledWithNonDefaultPactDirectory_SetsTheCorrectArgs()
98128
{
99129
var port = 9332;
100130
var pactDir = "./test";
101-
var pactConfig = new PactConfig { PactDir = pactDir };
131+
var pactConfig = new PactConfig {PactDir = pactDir};
102132
var consumerName = "Cons";
103133
var providerName = "The best one";
104134
var enableSsl = true;
@@ -107,7 +137,8 @@ public void Ctor_WhenCalledWithNonDefaultPactDirectory_SetsTheCorrectArgs()
107137

108138
var expectedLogFilePath = BuildExpectedLogFilePath(pactConfig.LogDir, providerName);
109139
var expectedPactDir = BuildExpectedPactDir(pactDir + "\\");
110-
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir, pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
140+
var expectedArguments = BuildExpectedArguments(port, expectedLogFilePath, expectedPactDir,
141+
pactConfig.SpecificationVersion, consumerName, providerName, enableSsl);
111142

112143
Assert.Equal(expectedArguments, config.Arguments);
113144
}
@@ -129,6 +160,11 @@ private string BuildExpectedPactDir(string pactDir)
129160
{
130161
return pactDir.Replace("\\", "/");
131162
}
163+
164+
private string BuildExpectedSslOption(string fullName)
165+
{
166+
return $"{fullName}".Replace("\\", "/");
167+
}
132168

133169
private string BuildExpectedArguments(
134170
int port,
@@ -138,13 +174,22 @@ private string BuildExpectedArguments(
138174
string consumerName,
139175
string providerName,
140176
bool enableSsl = false,
141-
IPAddress host = IPAddress.Loopback)
177+
IPAddress host = IPAddress.Loopback,
178+
string sslCert = "",
179+
string sslKey = ""
180+
)
142181
{
143-
144182
var sslOption = enableSsl ? " --ssl" : "";
145-
var hostOption = host == IPAddress.Any ? " --host=0.0.0.0" : "";
146-
147-
return $"-p {port} -l \"{logFilePath}\" --pact-dir \"{pactFileDir}\" --pact-specification-version \"{pactSpecificationVersion}\" --consumer \"{consumerName}\" --provider \"{providerName}\"{sslOption}{hostOption}";
183+
var hostOption = host == IPAddress.Any ? " --host=0.0.0.0" : "";
184+
var sslCertOption = !string.IsNullOrEmpty(sslCert) ? $" --sslcert=\"{sslCert}\"" : string.Empty;
185+
var sslKeyOption = !string.IsNullOrEmpty(sslKey) ? $" --sslkey=\"{sslKey}\"" : string.Empty;
186+
187+
return
188+
$"-p {port} -l \"{logFilePath}\" " +
189+
$"--pact-dir \"{pactFileDir}\" " +
190+
$"--pact-specification-version \"{pactSpecificationVersion}\" " +
191+
$"--consumer \"{consumerName}\" " +
192+
$"--provider \"{providerName}\"{sslOption}{hostOption}{sslCertOption}{sslKeyOption}";
148193
}
149194
}
150-
}
195+
}

PactNet.Tests/IntegrationTests/FailureIntegrationTestsMyApiPact.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public FailureIntegrationTestsMyApiPact()
1616
{
1717
var pactConfig = new PactConfig();
1818

19-
PactBuilder = new PactBuilder((port, enableSsl, consumerName, providerName, host, jsonSerializerSettings) =>
20-
new MockProviderService(
21-
baseUri => new RubyHttpHost(baseUri, "MyConsumer", "MyApi", pactConfig, host),
22-
port, enableSsl,
23-
baseUri => new AdminHttpClient(baseUri, jsonSerializerSettings)))
19+
PactBuilder = new PactBuilder(
20+
(port, enableSsl, consumerName, providerName, host, jsonSerializerSettings, sslCert, sslKey) =>
21+
new MockProviderService(
22+
baseUri => new RubyHttpHost(baseUri, "MyConsumer", "MyApi", pactConfig, host),
23+
port, enableSsl,
24+
baseUri => new AdminHttpClient(baseUri, jsonSerializerSettings)))
2425
.ServiceConsumer("FailureIntegrationTests")
2526
.HasPactWith("MyApi");
2627

PactNet.Tests/IntegrationTests/IntegrationTestsMyApiPact.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ public IntegrationTestsMyApiPact()
1616
{
1717
var pactConfig = new PactConfig();
1818

19-
PactBuilder = new PactBuilder((port, enableSsl, consumerName, providerName, host, jsonSerializerSettings) =>
20-
new MockProviderService(
21-
baseUri => new RubyHttpHost(baseUri, "MyConsumer", "MyApi", pactConfig, host),
22-
port, enableSsl,
23-
baseUri => new AdminHttpClient(baseUri, jsonSerializerSettings)))
19+
PactBuilder = new PactBuilder(
20+
(port, enableSsl, consumerName, providerName, host, jsonSerializerSettings, sslCert, sslKey) =>
21+
new MockProviderService(
22+
baseUri => new RubyHttpHost(baseUri, "MyConsumer", "MyApi", pactConfig, host),
23+
port, enableSsl,
24+
baseUri => new AdminHttpClient(baseUri, jsonSerializerSettings)))
2425
.ServiceConsumer("IntegrationTests")
2526
.HasPactWith("MyApi");
2627

0 commit comments

Comments
 (0)