Skip to content

Commit

Permalink
Fixing SonarCloud issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
Breno RdV committed Feb 11, 2024
1 parent e59353d commit 748b2ff
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 55 deletions.
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError()

[Theory]
[MemberData(nameof(TheoryGenerator.PartiallyValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))]
public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List<GlucoseReading> readings, float expectedResult)
public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(IList<GlucoseReading> readings, float expectedResult)
{
// Arrange & Act
var result = readings.CalculateHbA1C(ReferenceDate);
Expand All @@ -106,7 +106,7 @@ public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List

[Theory]
[MemberData(nameof(TheoryGenerator.ValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))]
public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(List<GlucoseReading> readings, float expectedResult)
public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(IList<GlucoseReading> readings, float expectedResult)
{
// Arrange & Act
var result = readings.CalculateHbA1C(ReferenceDate);
Expand Down
1 change: 1 addition & 0 deletions Raccoon.Ninja.TestHelpers/Raccoon.Ninja.TestHelpers.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Bogus" Version="35.4.0" />
<PackageReference Include="xunit.extensibility.core" Version="2.6.6" />
</ItemGroup>
</Project>
109 changes: 63 additions & 46 deletions Raccoon.Ninja.TestHelpers/TheoryGenerator.cs
Original file line number Diff line number Diff line change
@@ -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<object[]> AllTrendsWithExpectedStrings()
public static TheoryData<Trend, string> 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, string>
{
{ 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<object[]> VariantStringsWithCorrespondingTrend()
public static TheoryData<Trend, string> VariantStringsWithCorrespondingTrend()
{
var data = new TheoryData<Trend, string>();

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<object[]> TimeStampAndCorrespondingDateTimes()
public static TheoryData<long, DateTime> TimeStampAndCorrespondingDateTimes()
{
var data = new TheoryData<long, DateTime>();

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<object[]> ValidHb1AcDataSets()
public static TheoryData<IList<GlucoseReading>, 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<IList<GlucoseReading>, 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<object[]> PartiallyValidHb1AcDataSets()
public static TheoryData<IList<GlucoseReading>, 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<IList<GlucoseReading>, 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 },
};
}


}
16 changes: 12 additions & 4 deletions Raccoon.Ninja.WForm.GlucoseIcon/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -146,6 +154,6 @@ private void SetNotificationIcon(DataFetchResult dataFetched)
_notifyIcon.Icon = (Icon)createdIcon.Clone();

Logger.LogTrace("Releasing icon handle");
DestroyIcon(notificationIconHandle);
DestroyIconWrapper(notificationIconHandle);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<FileVersion>2.0.2</FileVersion>
<NeutralLanguage>en-US</NeutralLanguage>
<AssemblyName>CGMDataDisplay</AssemblyName>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MongoDB.Driver" Version="2.23.1" />
Expand Down

0 comments on commit 748b2ff

Please sign in to comment.