generated from prom-client-net/prom-client-tmpl
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests and restructured folders (#1)
1. Moved projects to dedicated projects' folder. 2. Updated gitignore 3. Added unit tests
- Loading branch information
1 parent
b62ca0f
commit a7b1ab2
Showing
9 changed files
with
163 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,43 @@ | ||
*.swp | ||
*.*~ | ||
project.lock.json | ||
.DS_Store | ||
*.pyc | ||
nupkg/ | ||
|
||
# Visual Studio Code | ||
.vscode/ | ||
|
||
# Rider | ||
.idea/ | ||
|
||
# Visual Studio | ||
.vs/ | ||
|
||
# Fleet | ||
.fleet/ | ||
|
||
# Code Rush | ||
.cr/ | ||
|
||
# User-specific files | ||
*.suo | ||
*.user | ||
*.opencover.xml | ||
*.orig | ||
*.nupkg | ||
*.snupkg | ||
.idea | ||
bin | ||
obj | ||
BenchmarkDotNet.Artifacts | ||
*.userosscache | ||
*.sln.docstates | ||
|
||
# Build results | ||
[Dd]ebug/ | ||
[Dd]ebugPublic/ | ||
[Rr]elease/ | ||
[Rr]eleases/ | ||
x64/ | ||
x86/ | ||
build/ | ||
bld/ | ||
[Bb]in/ | ||
[Oo]bj/ | ||
[Oo]ut/ | ||
msbuild.log | ||
msbuild.err | ||
msbuild.wrn |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prometheus.Client.MetricPusher.HostedService", "src\Prometheus.Client.MetricPusher.HostedService.csproj", "{C77EB3BB-08D7-4B18-9833-6D5486AA42C8}" | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.7.34003.232 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Prometheus.Client.MetricPusher.HostedService", "src\Prometheus.Client.MetricPusher.HostedService\Prometheus.Client.MetricPusher.HostedService.csproj", "{CD73BF99-211A-496F-983B-A55A22DE4FEE}" | ||
EndProject | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Prometheus.Client.MetricPusher.HostedService.Tests", "src\Prometheus.Client.MetricPusher.HostedService.Tests\Prometheus.Client.MetricPusher.HostedService.Tests.csproj", "{33C6BDD1-6FAF-4EBC-83DE-B10895F69848}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{C77EB3BB-08D7-4B18-9833-6D5486AA42C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{C77EB3BB-08D7-4B18-9833-6D5486AA42C8}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{C77EB3BB-08D7-4B18-9833-6D5486AA42C8}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{C77EB3BB-08D7-4B18-9833-6D5486AA42C8}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{CD73BF99-211A-496F-983B-A55A22DE4FEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{CD73BF99-211A-496F-983B-A55A22DE4FEE}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{CD73BF99-211A-496F-983B-A55A22DE4FEE}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{CD73BF99-211A-496F-983B-A55A22DE4FEE}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{33C6BDD1-6FAF-4EBC-83DE-B10895F69848}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{33C6BDD1-6FAF-4EBC-83DE-B10895F69848}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{33C6BDD1-6FAF-4EBC-83DE-B10895F69848}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{33C6BDD1-6FAF-4EBC-83DE-B10895F69848}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(NestedProjects) = preSolution | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {2A144989-FB17-400D-A3E8-78C7534AF12F} | ||
EndGlobalSection | ||
EndGlobal |
2 changes: 2 additions & 0 deletions
2
src/Prometheus.Client.MetricPusher.HostedService.Tests/GlobalUsings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
global using Xunit; | ||
global using FluentAssertions; |
26 changes: 26 additions & 0 deletions
26
src/Prometheus.Client.MetricPusher.HostedService.Tests/MetricPusherServiceTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Moq; | ||
|
||
namespace Prometheus.Client.MetricPusher.HostedService.Tests | ||
{ | ||
public class MetricPusherServiceTests | ||
{ | ||
[Fact] | ||
public async Task WithGivenInterval_PushMetricPeriodically() | ||
{ | ||
var metricPusherMock = new Moq.Mock<IMetricPusher>(); | ||
var metricPusherService = new MetricPusherService(metricPusherMock.Object, TimeSpan.FromSeconds(1)); | ||
var canellationToken = It.IsAny<CancellationToken>(); | ||
|
||
await metricPusherService.StartAsync(canellationToken); | ||
await Task.Delay(TimeSpan.FromSeconds(1)); | ||
await metricPusherService.StopAsync(canellationToken); | ||
|
||
metricPusherMock.Verify(o => o.PushAsync(), Moq.Times.AtLeast(2)); | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...etricPusher.HostedService.Tests/Prometheus.Client.MetricPusher.HostedService.Tests.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net6.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
<IsTestProject>true</IsTestProject> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CleanMoq" Version="1.0.0" /> | ||
<PackageReference Include="FluentAssertions" Version="6.11.0" /> | ||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" /> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" /> | ||
<PackageReference Include="xunit" Version="2.4.2" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.2.0"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Prometheus.Client.MetricPusher.HostedService\Prometheus.Client.MetricPusher.HostedService.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
42 changes: 42 additions & 0 deletions
42
src/Prometheus.Client.MetricPusher.HostedService.Tests/ServiceCollecttionExtensionsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Hosting; | ||
|
||
namespace Prometheus.Client.MetricPusher.HostedService.Tests | ||
{ | ||
public class ServiceCollecttionExtensionsTests | ||
{ | ||
[Fact] | ||
public void AddMetricPusherService_WithNullMetricPusher_ThrowsArgumentNullException() | ||
{ | ||
IServiceCollection servicesCollection = Moq.Mock.Of<IServiceCollection>(); | ||
|
||
Action act = () => ServiceCollectionExtensions.AddMetricPusherService(servicesCollection, null, TimeSpan.FromSeconds(1)); | ||
|
||
act.Should().Throw<ArgumentNullException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddMetricPusherService_WithZeroTimeInterval_ThrowsArgumentOutOfRangeException() | ||
{ | ||
IServiceCollection servicesCollection = Moq.Mock.Of<IServiceCollection>(); | ||
IMetricPusher metricPusher = Moq.Mock.Of<IMetricPusher>(); | ||
|
||
Action act = () => ServiceCollectionExtensions.AddMetricPusherService(servicesCollection, metricPusher, TimeSpan.Zero); | ||
|
||
act.Should().Throw<ArgumentOutOfRangeException>(); | ||
} | ||
|
||
[Fact] | ||
public void AddMetricPusherService_WithValidParameterValues_AddsMetricPusherServiceInServiceCollection() | ||
{ | ||
IServiceCollection servicesCollection = new ServiceCollection(); | ||
IMetricPusher metricPusher = Moq.Mock.Of<IMetricPusher>(); | ||
|
||
ServiceCollectionExtensions.AddMetricPusherService(servicesCollection, metricPusher, TimeSpan.FromSeconds(1)); | ||
var provider = servicesCollection.BuildServiceProvider(); | ||
var service = provider.GetRequiredService<IHostedService>(); | ||
|
||
service.Should().BeOfType<MetricPusherService>(); | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.