-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for culture invariant formatting
- Loading branch information
1 parent
1e7704a
commit 8b42aa2
Showing
3 changed files
with
65 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Threading; | ||
using Xunit; | ||
|
||
namespace OhmGraphite.Test | ||
{ | ||
public class FormatMetricsTest | ||
{ | ||
[Fact] | ||
public void FormatGraphiteIdentifier() | ||
{ | ||
var epoch = new DateTimeOffset(new DateTime(2001, 1, 13)).ToUnixTimeSeconds(); | ||
var sensor = new Sensor("my.cpu.identifier", "voltage", 1.06f); | ||
string actual = MetricTimer.FormatGraphiteData("MY-PC", epoch, sensor); | ||
Assert.Equal("ohm.MY-PC.my.cpu.identifier.voltage 1.06 979365600", actual); | ||
} | ||
|
||
[Fact] | ||
public void FormatCultureInvariant() | ||
{ | ||
CultureInfo original = Thread.CurrentThread.CurrentCulture; | ||
try | ||
{ | ||
// de-DE culture will format 1.06 as 1,06 which graphite doesn't like | ||
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE"); | ||
|
||
var epoch = new DateTimeOffset(new DateTime(2001, 1, 13)).ToUnixTimeSeconds(); | ||
var sensor = new Sensor("my.cpu.identifier", "voltage", 1.06f); | ||
string actual = MetricTimer.FormatGraphiteData("MY-PC", epoch, sensor); | ||
Assert.Equal("ohm.MY-PC.my.cpu.identifier.voltage 1.06 979365600", actual); | ||
} | ||
finally | ||
{ | ||
Thread.CurrentThread.CurrentCulture = original; | ||
} | ||
} | ||
} | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net46</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.6.0" /> | ||
<PackageReference Include="xunit" Version="2.3.1" /> | ||
<PackageReference Include="xunit.runner.visualstudio" Version="2.3.1" /> | ||
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.1" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\OhmGraphite\OhmGraphite.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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