-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMultipleContractTestFixture.cs
102 lines (91 loc) · 3.2 KB
/
MultipleContractTestFixture.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using Solid.AspNetCore.Extensions.Wcf.Tests.Abstractions;
using Solid.AspNetCore.Extensions.Wcf.Tests.Host;
using Solid.Testing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
namespace Solid.AspNetCore.Extensions.Wcf.Tests
{
public class MultipleContractTestFixture : IDisposable
{
private IEchoContract _echo;
private ICounterContract _counter;
public MultipleContractTestFixture()
{
TestingServer = new TestingServerBuilder()
.AddAspNetCoreHostFactory()
.AddStartup<MulitpleContractTestStartup>()
.Build();
}
public TestingServer TestingServer { get; }
public IEchoContract GetEchoService()
{
if (_echo == null)
{
var url = new Uri(TestingServer.BaseAddress, "multiple/endpoints/echo/endpoint");
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress(url);
var factory = new ChannelFactory<IEchoContract>(binding, endpoint);
var client = factory.CreateChannel();
_echo = client;
var channel = client as ICommunicationObject;
channel.Closed += (sender, args) =>
{
_echo = null;
};
}
return _echo;
}
public IEchoContract GetRedirectedEchoService()
{
if (_echo == null)
{
var url = new Uri(TestingServer.BaseAddress, "replaceecho");
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress(url);
var factory = new ChannelFactory<IEchoContract>(binding, endpoint);
var client = factory.CreateChannel();
_echo = client;
var channel = client as ICommunicationObject;
channel.Closed += (sender, args) =>
{
_echo = null;
};
}
return _echo;
}
public ICounterContract GetCounterService()
{
if (_counter == null)
{
var url = new Uri(TestingServer.BaseAddress, "multiple/endpoints/counter/endpoint");
var binding = new BasicHttpBinding();
var endpoint = new EndpointAddress(url);
var factory = new ChannelFactory<ICounterContract>(binding, endpoint);
var client = factory.CreateChannel();
_counter = client;
var channel = client as ICommunicationObject;
channel.Closed += (sender, args) =>
{
_counter = null;
};
}
return _counter;
}
public void Dispose()
{
Close(_echo);
Close(_counter);
TestingServer.Dispose();
}
private void Close(object service)
{
var channel = service as ICommunicationObject;
if (channel != null)
channel.Close();
}
}
}