diff --git a/Raccoon.Ninja.Domain.Core.Tests/Converters/EnumConvertersTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Converters/EnumConvertersTests.cs index 382828c..89fbec2 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Converters/EnumConvertersTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Converters/EnumConvertersTests.cs @@ -1,5 +1,4 @@ -using FluentAssertions; -using Raccoon.Ninja.Domain.Core.Converters; +using Raccoon.Ninja.Domain.Core.Converters; using Raccoon.Ninja.Domain.Core.Enums; using Raccoon.Ninja.TestHelpers; diff --git a/Raccoon.Ninja.Domain.Core.Tests/Converters/StringConvertersTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Converters/StringConvertersTests.cs index dce309c..726ba6f 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Converters/StringConvertersTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Converters/StringConvertersTests.cs @@ -9,7 +9,7 @@ public class StringConvertersTests { [Theory] [MemberData(nameof(TheoryGenerator.VariantStringsWithCorrespondingTrend), MemberType = typeof(TheoryGenerator))] - public void ToTrend_Success(string label, Trend expected) + public void ToTrend_Success(Trend expected, string label) { //Arrange var actual = Converter.ToTrend(label); diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs index 440ec90..42d0544 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs @@ -94,7 +94,7 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() [Theory] [MemberData(nameof(TheoryGenerator.PartiallyValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] - public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List readings, float expectedResult) + public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(IList readings, float expectedResult) { // Arrange & Act var result = readings.CalculateHbA1C(ReferenceDate); @@ -106,7 +106,7 @@ public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List [Theory] [MemberData(nameof(TheoryGenerator.ValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] - public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(List readings, float expectedResult) + public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(IList readings, float expectedResult) { // Arrange & Act var result = readings.CalculateHbA1C(ReferenceDate); diff --git a/Raccoon.Ninja.TestHelpers/Raccoon.Ninja.TestHelpers.csproj b/Raccoon.Ninja.TestHelpers/Raccoon.Ninja.TestHelpers.csproj index b5b9e2f..4cfea2c 100644 --- a/Raccoon.Ninja.TestHelpers/Raccoon.Ninja.TestHelpers.csproj +++ b/Raccoon.Ninja.TestHelpers/Raccoon.Ninja.TestHelpers.csproj @@ -10,5 +10,6 @@ + \ No newline at end of file diff --git a/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs b/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs index dbc8e28..b88466a 100644 --- a/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs +++ b/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs @@ -1,75 +1,92 @@ -using Raccoon.Ninja.Domain.Core.Enums; +using Raccoon.Ninja.Domain.Core.Entities; +using Raccoon.Ninja.Domain.Core.Enums; +using Xunit; namespace Raccoon.Ninja.TestHelpers; public static class TheoryGenerator { - - - public static IEnumerable AllTrendsWithExpectedStrings() + public static TheoryData AllTrendsWithExpectedStrings() { - yield return new object[] { Trend.TripleUp, "Zooming Skyward" }; - yield return new object[] { Trend.DoubleUp, "Rapid Ascent" }; - yield return new object[] { Trend.SingleUp, "Steep Climb" }; - yield return new object[] { Trend.FortyFiveUp, "Going Up, Captain" }; - yield return new object[] { Trend.Flat, "Nice and easy" }; - yield return new object[] { Trend.FortyFiveDown, "Descending Swiftly" }; - yield return new object[] { Trend.SingleDown, "Plummet Mode" }; - yield return new object[] { Trend.DoubleDown, "Double the plunge" }; - yield return new object[] { Trend.TripleDown, "Free-fall Frenzy" }; - yield return new object[] { Trend.NotComputable, "Wandering in the Unknown" }; + return new TheoryData + { + { Trend.TripleUp, "Zooming Skyward" }, + { Trend.DoubleUp, "Rapid Ascent" }, + { Trend.SingleUp, "Steep Climb" }, + { Trend.FortyFiveUp, "Going Up, Captain" }, + { Trend.Flat, "Nice and easy" }, + { Trend.FortyFiveDown, "Descending Swiftly" }, + { Trend.SingleDown, "Plummet Mode" }, + { Trend.DoubleDown, "Double the plunge" }, + { Trend.TripleDown, "Free-fall Frenzy" }, + { Trend.NotComputable, "Wandering in the Unknown" }, + }; } - public static IEnumerable VariantStringsWithCorrespondingTrend() + public static TheoryData VariantStringsWithCorrespondingTrend() { + var data = new TheoryData(); + foreach (var valueLabelPair in AllTrendsWithExpectedStrings()) { - var trend = (Trend) valueLabelPair[0]; - var label = (string) valueLabelPair[1]; + var trend = (Trend)valueLabelPair[0]; + var label = (string)valueLabelPair[1]; - yield return new object[] { label, trend }; - yield return new object[] { label.ToLowerInvariant(), trend }; - yield return new object[] { label.ToUpperInvariant(), trend }; + data.Add(trend, label); + data.Add(trend, label.ToLowerInvariant()); + data.Add(trend, label.ToUpperInvariant()); } + + return data; } - public static IEnumerable TimeStampAndCorrespondingDateTimes() + public static TheoryData TimeStampAndCorrespondingDateTimes() { + var data = new TheoryData(); + var testDate = DateTime.MinValue.ToUniversalTime(); - yield return new object[] { testDate.ToUnixTimestamp(), testDate }; - + data.Add(testDate.ToUnixTimestamp(), testDate); + testDate = DateTime.MaxValue.ToUniversalTime(); - yield return new object[] { testDate.ToUnixTimestamp(), testDate }; - + data.Add(testDate.ToUnixTimestamp(), testDate); + testDate = DateTime.UtcNow; - yield return new object[] { testDate.ToUnixTimestamp(), testDate }; - + data.Add(testDate.ToUnixTimestamp(), testDate); + //Leap year day test. testDate = new DateTime(2020, 2, 29, 23, 59, 59, DateTimeKind.Utc); - yield return new object[] { testDate.ToUnixTimestamp(), testDate }; + data.Add(testDate.ToUnixTimestamp(), testDate); + + return data; } - public static IEnumerable ValidHb1AcDataSets() + public static TheoryData, float> ValidHb1AcDataSets() { - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 80), 4.4146338f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 100), 5.111498f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 150), 6.853658f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 170), 7.5505223f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 210), 8.944251f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 300), 12.080139f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 400), 15.56446f }; + var data = new TheoryData, float> + { + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 80), 4.4146338f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 100), 5.111498f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 150), 6.853658f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 170), 7.5505223f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 210), 8.944251f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 300), 12.080139f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn115Days, 400), 15.56446f } + }; + + return data; } - public static IEnumerable PartiallyValidHb1AcDataSets() + public static TheoryData, float> PartiallyValidHb1AcDataSets() { - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 80), 4.4146338f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 100), 5.111498f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 150), 6.853658f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 170), 7.5505223f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 210), 8.944251f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 300), 12.080139f }; - yield return new object[] { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 400), 15.56446f }; + return new TheoryData, float> + { + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 80), 4.4146338f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 100), 5.111498f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 150), 6.853658f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 170), 7.5505223f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 210), 8.944251f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 300), 12.080139f }, + { Generators.GlucoseReadingMockList(Constants.ReadingsIn1Day, 400), 15.56446f }, + }; } - - } \ No newline at end of file diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/MainForm.cs b/Raccoon.Ninja.WForm.GlucoseIcon/MainForm.cs index b394cd5..caa27a0 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/MainForm.cs +++ b/Raccoon.Ninja.WForm.GlucoseIcon/MainForm.cs @@ -16,8 +16,16 @@ public partial class MainForm : Form private IDataFetcher _dataFetcher; // Import the DestroyIcon extern method - [DllImport("user32.dll", CharSet = CharSet.Auto)] - private static extern bool DestroyIcon(IntPtr handle); + [LibraryImport("user32.dll")] + private static partial int DestroyIcon(IntPtr handle); + +// Wrapper method to call the P/Invoke method and convert the return value to bool + private static bool DestroyIconWrapper(IntPtr handle) { + if (DestroyIcon(handle) == 0) return true; + + Logger.LogTrace("DestroyIcon failed with error code: {ErrorCode}", Marshal.GetLastWin32Error()); + return false; + } public MainForm() { @@ -111,7 +119,7 @@ private void SetTaskbarIconOverlay(DataFetchResult dataFetched) Icon = (Icon)createdIcon.Clone(); Logger.LogTrace("Releasing icon handle"); - DestroyIcon(taskbarIconHandle); + DestroyIconWrapper(taskbarIconHandle); } private void SetNotificationIcon(DataFetchResult dataFetched) @@ -146,6 +154,6 @@ private void SetNotificationIcon(DataFetchResult dataFetched) _notifyIcon.Icon = (Icon)createdIcon.Clone(); Logger.LogTrace("Releasing icon handle"); - DestroyIcon(notificationIconHandle); + DestroyIconWrapper(notificationIconHandle); } } diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj b/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj index 41b5e72..d04b223 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj +++ b/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj @@ -9,6 +9,7 @@ 2.0.2 en-US CGMDataDisplay + true