|
1 | 1 | using Microsoft.Extensions.DependencyInjection; |
2 | 2 | using Microsoft.Extensions.Hosting; |
3 | 3 |
|
4 | | -namespace Prometheus.Client.MetricPusher.HostedService.Tests |
| 4 | +namespace Prometheus.Client.MetricPusher.HostedService.Tests; |
| 5 | + |
| 6 | +public class ServiceCollecttionExtensionsTests |
5 | 7 | { |
6 | | - public class ServiceCollecttionExtensionsTests |
| 8 | + [Fact] |
| 9 | + public void AddMetricPusherService_WithNullMetricPusher_ThrowsArgumentNullException() |
| 10 | + { |
| 11 | + var servicesCollection = Substitute.For<IServiceCollection>(); |
| 12 | + |
| 13 | + Action act = () => servicesCollection.AddMetricPusherService(null, TimeSpan.FromSeconds(1)); |
| 14 | + |
| 15 | + act.Should().Throw<ArgumentNullException>(); |
| 16 | + } |
| 17 | + |
| 18 | + [Fact] |
| 19 | + public void AddMetricPusherService_WithZeroTimeInterval_ThrowsArgumentOutOfRangeException() |
7 | 20 | { |
8 | | - [Fact] |
9 | | - public void AddMetricPusherService_WithNullMetricPusher_ThrowsArgumentNullException() |
10 | | - { |
11 | | - var servicesCollection = Substitute.For<IServiceCollection>(); |
| 21 | + var servicesCollection = Substitute.For<IServiceCollection>(); |
| 22 | + var metricPusher = Substitute.For<IMetricPusher>(); |
12 | 23 |
|
13 | | - Action act = () => servicesCollection.AddMetricPusherService(null, TimeSpan.FromSeconds(1)); |
| 24 | + Action act = () => servicesCollection.AddMetricPusherService(metricPusher, TimeSpan.Zero); |
14 | 25 |
|
15 | | - act.Should().Throw<ArgumentNullException>(); |
16 | | - } |
| 26 | + act.Should().Throw<ArgumentOutOfRangeException>(); |
| 27 | + } |
17 | 28 |
|
18 | | - [Fact] |
19 | | - public void AddMetricPusherService_WithZeroTimeInterval_ThrowsArgumentOutOfRangeException() |
20 | | - { |
21 | | - var servicesCollection = Substitute.For<IServiceCollection>(); |
22 | | - var metricPusher = Substitute.For<IMetricPusher>(); |
| 29 | + [Fact] |
| 30 | + public void AddMetricPusherService_WithDefaultInterval_AddsMetricPusherServiceInServiceCollection() |
| 31 | + { |
| 32 | + var servicesCollection = new ServiceCollection(); |
| 33 | + var metricPusher = Substitute.For<IMetricPusher>(); |
23 | 34 |
|
24 | | - Action act = () => servicesCollection.AddMetricPusherService(metricPusher, TimeSpan.Zero); |
| 35 | + servicesCollection.AddMetricPusherService(metricPusher); |
| 36 | + var provider = servicesCollection.BuildServiceProvider(); |
| 37 | + var service = provider.GetRequiredService<IHostedService>(); |
25 | 38 |
|
26 | | - act.Should().Throw<ArgumentOutOfRangeException>(); |
27 | | - } |
| 39 | + service.Should().BeOfType<MetricPusherService>(); |
| 40 | + } |
28 | 41 |
|
29 | | - [Fact] |
30 | | - public void AddMetricPusherService_WithValidParameterValues_AddsMetricPusherServiceInServiceCollection() |
31 | | - { |
32 | | - var servicesCollection = new ServiceCollection(); |
33 | | - var metricPusher = Substitute.For<IMetricPusher>(); |
| 42 | + [Fact] |
| 43 | + public void AddMetricPusherService_WithValidParameterValues_AddsMetricPusherServiceInServiceCollection() |
| 44 | + { |
| 45 | + var servicesCollection = new ServiceCollection(); |
| 46 | + var metricPusher = Substitute.For<IMetricPusher>(); |
34 | 47 |
|
35 | | - servicesCollection.AddMetricPusherService(metricPusher, TimeSpan.FromSeconds(1)); |
36 | | - var provider = servicesCollection.BuildServiceProvider(); |
37 | | - var service = provider.GetRequiredService<IHostedService>(); |
| 48 | + servicesCollection.AddMetricPusherService(metricPusher, TimeSpan.FromSeconds(1)); |
| 49 | + var provider = servicesCollection.BuildServiceProvider(); |
| 50 | + var service = provider.GetRequiredService<IHostedService>(); |
38 | 51 |
|
39 | | - service.Should().BeOfType<MetricPusherService>(); |
40 | | - } |
| 52 | + service.Should().BeOfType<MetricPusherService>(); |
41 | 53 | } |
42 | 54 | } |
0 commit comments