-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from RagingKore/fix-default-instance-configurat…
…ion-requirement Allow Metrics instance to run without any configuration
- Loading branch information
Showing
7 changed files
with
77 additions
and
12 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
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
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
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
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
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,27 @@ | ||
using System; | ||
using FluentAssertions; | ||
using Xunit; | ||
|
||
namespace Ubiquitous.Metrics.Tests { | ||
public class MetricsInstanceTests { | ||
[Fact] | ||
public void ShouldNotThrowIfMetricsNotConfigured() { | ||
Action captureSomeMetrics = () => TestApplicationMetrics.CountUploads(Guid.NewGuid()); | ||
|
||
captureSomeMetrics.Should().NotThrow<Exception>(); | ||
|
||
TestApplicationMetrics.UploadsCounter.Should().Be(1); | ||
} | ||
} | ||
|
||
static class TestApplicationMetrics { | ||
static ICountMetric UploadsCount { get; } = Metrics.Instance.CreateCount("app_uploads", "Number of uploads", "request_id"); | ||
|
||
public static ulong UploadsCounter { get; private set; } | ||
|
||
public static void CountUploads(Guid requestId) { | ||
UploadsCount.Inc(new[] { requestId.ToString() }); | ||
UploadsCounter++; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
test/Ubiquitous.Metrics.Tests/Ubiquitous.Metrics.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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
|
||
<IsPackable>false</IsPackable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" /> | ||
<PackageReference Include="xunit" Version="2.4.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
<PackageReference Include="coverlet.collector" Version="3.0.2"> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\..\src\Ubiquitous.Metrics\Ubiquitous.Metrics.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |