Skip to content

Commit

Permalink
Add tests for culture invariant formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbabcock committed May 3, 2018
1 parent 1e7704a commit 8b42aa2
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
39 changes: 39 additions & 0 deletions OhmGraphite.Test/FormatMetricsTest.cs
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;
}
}
}
}
18 changes: 18 additions & 0 deletions OhmGraphite.Test/OhmGraphite.Test.csproj
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>
10 changes: 8 additions & 2 deletions OhmGraphite.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27004.2005
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OhmGraphite", "OhmGraphite\OhmGraphite.csproj", "{329E2785-6E88-449F-A641-6ACCBFF943CA}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OhmGraphite", "OhmGraphite\OhmGraphite.csproj", "{329E2785-6E88-449F-A641-6ACCBFF943CA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenHardwareMonitorLib", "LibreHardwareMonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenHardwareMonitorLib", "LibreHardwareMonitor\OpenHardwareMonitorLib.csproj", "{B0397530-545A-471D-BB74-027AE456DF1A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OhmGraphite.Test", "OhmGraphite.Test\OhmGraphite.Test.csproj", "{E6C3F138-BED7-4350-B1F0-95AE87640CFB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -21,6 +23,10 @@ Global
{B0397530-545A-471D-BB74-027AE456DF1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0397530-545A-471D-BB74-027AE456DF1A}.Release|Any CPU.Build.0 = Release|Any CPU
{E6C3F138-BED7-4350-B1F0-95AE87640CFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E6C3F138-BED7-4350-B1F0-95AE87640CFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E6C3F138-BED7-4350-B1F0-95AE87640CFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E6C3F138-BED7-4350-B1F0-95AE87640CFB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down

0 comments on commit 8b42aa2

Please sign in to comment.