-
Notifications
You must be signed in to change notification settings - Fork 8
/
ServiceCollectionExtensionsTests.cs
107 lines (85 loc) · 5.69 KB
/
ServiceCollectionExtensionsTests.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
103
104
105
106
107
using System;
using EMG.Utilities.ServiceModel;
using EMG.Utilities.ServiceModel.Configuration;
using EMG.Utilities.ServiceModel.Discovery;
using EMG.Utilities.ServiceModel.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
// ReSharper disable InvokeAsExtensionMethod
// ReSharper disable RedundantTypeArgumentsOfMethod
namespace Tests.ServiceModel
{
[TestFixture]
public class ServiceCollectionExtensionsTests
{
[Test, CustomAutoData]
public void AddWcfService_returns_same_ServiceCollection(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
var result = ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Assert.That(result, Is.SameAs(services));
}
[Test, CustomAutoData]
public void AddWcfService_registers_host_configuration(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IServiceHostConfiguration<TestService>) && d.Lifetime == ServiceLifetime.Singleton)));
}
[Test, CustomAutoData]
public void AddWcfService_registers_host_builder(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IServiceHostBuilder) && d.ImplementationType == typeof(ServiceHostBuilder) && d.Lifetime == ServiceLifetime.Singleton)));
}
[Test, CustomAutoData]
public void AddWcfService_registers_hosted_service_configuration(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(WcfServiceHostedServiceConfiguration<TestService>) && d.Lifetime == ServiceLifetime.Singleton)));
}
[Test, CustomAutoData]
public void AddWcfService_registers_hosted_service(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IHostedService) && d.Lifetime == ServiceLifetime.Singleton)));
}
[Test, CustomAutoData]
public void AddWcfService_registers_announcement_service(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(IAnnouncementService) && d.Lifetime == ServiceLifetime.Singleton)));
}
[Test, CustomAutoData]
public void AddWcfService_registers_service(IServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(d => d.ServiceType == typeof(TestService) && d.ImplementationType == typeof(TestService) && d.Lifetime == lifetime)));
}
[Test, CustomAutoData]
public void AddWcfService_throws_if_same_service_registered_twice(ServiceCollection services, WcfServiceConfigurator<TestService> configurator, ServiceLifetime lifetime)
{
ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime);
Assert.Throws<ArgumentException>(() => ServiceCollectionExtensions.AddWcfService<TestService>(services, configurator, lifetime));
}
[Test, CustomAutoData]
public void AddDiscovery_returns_service_collection(IServiceCollection services, Uri announcementUri, TimeSpan interval, Action<TestHttpBinding> configureBinding)
{
var result = ServiceCollectionExtensions.AddDiscovery(services, announcementUri, interval, configureBinding);
Assert.That(result, Is.SameAs(services));
}
[Test, CustomAutoData]
public void AddDiscovery_register_announcement_service_options(IServiceCollection services, Uri announcementUri, TimeSpan interval, Action<TestBinding> configureBinding)
{
var result = ServiceCollectionExtensions.AddDiscovery(services, announcementUri, interval, configureBinding);
Mock.Get(services).Verify(p => p.Add(It.Is<ServiceDescriptor>(sd => sd.ServiceType == typeof(IConfigureOptions<AnnouncementServiceOptions>))));
}
[Test, CustomAutoData]
public void AddDiscovery_configures_binding_with_delegate(IServiceCollection services, Uri announcementUri, TimeSpan interval, Action<TestBinding> configureBinding)
{
var result = ServiceCollectionExtensions.AddDiscovery(services, announcementUri, interval, configureBinding);
Mock.Get(configureBinding).Verify(p => p(It.IsAny<TestBinding>()));
}
}
}