diff --git a/OhmGraphite.Test/FormatMetricsTest.cs b/OhmGraphite.Test/FormatMetricsTest.cs new file mode 100644 index 0000000..f9e4136 --- /dev/null +++ b/OhmGraphite.Test/FormatMetricsTest.cs @@ -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; + } + } + } +} diff --git a/OhmGraphite.Test/OhmGraphite.Test.csproj b/OhmGraphite.Test/OhmGraphite.Test.csproj new file mode 100644 index 0000000..9a5b478 --- /dev/null +++ b/OhmGraphite.Test/OhmGraphite.Test.csproj @@ -0,0 +1,18 @@ + + + + net46 + + + + + + + + + + + + + + diff --git a/OhmGraphite.sln b/OhmGraphite.sln index 7fe60d0..9ce5fd5 100644 --- a/OhmGraphite.sln +++ b/OhmGraphite.sln @@ -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 @@ -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