From 034cf768455ee9494f2dc1b63efb0be915b44cbc Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 02:21:39 -0500 Subject: [PATCH 01/11] feature/fix-sonar-issues: Removed dead code and fixed issues pointed by SonarCloud. --- .../DataLatestHbA1cFunc.cs | 10 ++--- .../HbA1cCalcFunc.cs | 6 +-- .../Program.cs | 19 ++++++++- .../ExtensionMethods/LongExtensionsTests.cs | 20 ++++----- .../Entities/HbA1cCalculation.cs | 10 ++--- .../Enums/HbA1cCalculationStatus.cs | 2 +- .../ExtensionMethods/ListExtensions.cs | 42 +++++++++++-------- .../Models/DataLatestHbA1cFuncResponse.cs | 6 +-- .../Models/HbA1cCalculationResponse.cs | 8 ++-- .../GlucoseReadingResponseExtensions.cs | 25 ----------- .../Utils/AppSettings.cs | 2 +- .../Utils/TrendConverter.cs | 24 +---------- 12 files changed, 76 insertions(+), 98 deletions(-) delete mode 100644 Raccoon.Ninja.WForm.GlucoseIcon/ExtensionMethods/GlucoseReadingResponseExtensions.cs diff --git a/Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs b/Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs index 9554d75..917896f 100644 --- a/Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs +++ b/Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs @@ -25,19 +25,19 @@ public static async Task RunAsync( CreateIfNotExists = false, SqlQuery = "SELECT TOP 1 * FROM c WHERE c.docType = 1 and c.status = 1 ORDER BY c.createdAt DESC" )] - IEnumerable latestSuccessCalculations, + IEnumerable latestSuccessCalculations, [CosmosDB(databaseName: "%CosmosDatabaseName%", containerName: "%CosmosAggregateContainerName%", Connection = "CosmosConnectionString", CreateIfNotExists = false, SqlQuery = "SELECT TOP 1 * FROM c WHERE c.docType = 1 and c.status = 2 ORDER BY c.createdAt DESC" )] - IEnumerable latestPartialSuccessCalculations, + IEnumerable latestPartialSuccessCalculations, ILogger log) { log.LogInformation("Data Latest HbA1c API call received. Request by IP: {Ip}", req.HttpContext.Connection.RemoteIpAddress); - HbA1cCalculation latestSuccessful = null; - HbA1cCalculation latestPartialSuccessful = null; + HbA1CCalculation latestSuccessful = null; + HbA1CCalculation latestPartialSuccessful = null; try { @@ -50,7 +50,7 @@ public static async Task RunAsync( if (latestSuccessful is null && latestPartialSuccessful is null) return new NoContentResult(); - return new OkObjectResult(new DataLatestHbA1cFuncResponse + return new OkObjectResult(new DataLatestHbA1CFuncResponse { LatestSuccessful = latestSuccessful, LatestPartialSuccessful = latestPartialSuccessful diff --git a/Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs b/Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs index 7917e5f..7925452 100644 --- a/Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs +++ b/Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs @@ -28,12 +28,12 @@ public static async Task RunAsync( Connection = "CosmosConnectionString", CreateIfNotExists = false, SqlQuery = "SELECT TOP 1 * FROM c WHERE c.docType = 1 ORDER BY c.createdAt DESC" - )] IEnumerable previousCalculations, + )] IEnumerable previousCalculations, [CosmosDB(databaseName: "%CosmosDatabaseName%", containerName: "%CosmosAggregateContainerName%", Connection = "CosmosConnectionString", CreateIfNotExists = false, PartitionKey = "/id" - )]IAsyncCollector calculationsOut, + )]IAsyncCollector calculationsOut, ILogger log) { var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); @@ -42,7 +42,7 @@ public static async Task RunAsync( { var previousCalculation = previousCalculations.FirstOrDefault(); - var hbA1c = readings.CalculateHbA1c(referenceDate); + var hbA1c = readings.CalculateHbA1C(referenceDate); if (previousCalculation is not null) { diff --git a/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Program.cs b/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Program.cs index bd5b82e..735f5b5 100644 --- a/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Program.cs +++ b/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Program.cs @@ -10,9 +10,13 @@ try { Logger.LogTrace("Starting CGM Data Display application"); + + // Construct the fully qualified path to the application + var appFullPath = GetFullPathToApp(appName); + Process.Start(new ProcessStartInfo { - FileName = appName, + FileName = appFullPath, WindowStyle = ProcessWindowStyle.Normal }); } @@ -25,3 +29,16 @@ { Logger.LogTrace("Exiting Launcher"); } + +return; + +static string GetFullPathToApp(string appName) +{ + var assemblyLocation = System.Reflection.Assembly.GetExecutingAssembly().Location; + var assemblyPath = Path.GetDirectoryName(assemblyLocation); + + // Construct the fully qualified path to the application + return string.IsNullOrWhiteSpace(assemblyPath) + ? appName + : Path.Combine(assemblyPath, appName); +} diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs index 5c2c8a2..e4f2f61 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs @@ -29,10 +29,10 @@ public void CalculateHbA1c_WhenListIsNull_ShouldReturnError() IEnumerable list = null; // Act - var result = list.CalculateHbA1c(ReferenceDate); + var result = list.CalculateHbA1C(ReferenceDate); // Assert - result.Status.Should().Be(HbA1cCalculationStatus.Error); + result.Status.Should().Be(HbA1CCalculationStatus.Error); result.Error.Should().Be("No readings to calculate HbA1c"); } @@ -43,10 +43,10 @@ public void CalculateHbA1c_WhenListIsEmpty_ShouldReturnError() var list = new List(); // Act - var result = list.CalculateHbA1c(ReferenceDate); + var result = list.CalculateHbA1C(ReferenceDate); // Assert - result.Status.Should().Be(HbA1cCalculationStatus.Error); + result.Status.Should().Be(HbA1CCalculationStatus.Error); result.Error.Should().Be("No readings returned from Db to calculate HbA1c"); } @@ -58,10 +58,10 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() var readings = Generators.GenerateList(actualReadingCount, 100); // Act - var result = readings.CalculateHbA1c(ReferenceDate); + var result = readings.CalculateHbA1C(ReferenceDate); // Assert - result.Status.Should().Be(HbA1cCalculationStatus.Error); + result.Status.Should().Be(HbA1CCalculationStatus.Error); result.Error.Should().Be($"Too many readings to calculate HbA1c reliably. Expected 33120 but got {actualReadingCount}"); } @@ -70,10 +70,10 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List readings, float expectedResult) { // Arrange & Act - var result = readings.CalculateHbA1c(ReferenceDate); + var result = readings.CalculateHbA1C(ReferenceDate); // Assert - result.Status.Should().Be(HbA1cCalculationStatus.SuccessPartial); + result.Status.Should().Be(HbA1CCalculationStatus.SuccessPartial); result.Value.Should().Be(expectedResult); } @@ -82,10 +82,10 @@ public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(List readings, float expectedResult) { // Arrange & Act - var result = readings.CalculateHbA1c(ReferenceDate); + var result = readings.CalculateHbA1C(ReferenceDate); // Assert - result.Status.Should().Be(HbA1cCalculationStatus.Success); + result.Status.Should().Be(HbA1CCalculationStatus.Success); result.Value.Should().Be(expectedResult); } } \ No newline at end of file diff --git a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs index b0dd580..f29a992 100644 --- a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs +++ b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs @@ -4,12 +4,12 @@ namespace Raccoon.Ninja.Domain.Core.Entities; -public record HbA1cCalculation: BaseEntity +public record HbA1CCalculation: BaseEntity { [JsonProperty("docType")] public AggregateType DocType { get; init; } = AggregateType.HbA1cCalculation; [JsonProperty("referenceDate")] public DateOnly ReferenceDate { get; init; } [JsonProperty("createdAt")] public long CreatedAtUtc { get; init; } = DateTime.UtcNow.ToUnixTimestamp(); - [JsonProperty("status")] public HbA1cCalculationStatus Status { get; init; } + [JsonProperty("status")] public HbA1CCalculationStatus Status { get; init; } [JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)] public string Error { get; init; } /// @@ -18,11 +18,11 @@ public record HbA1cCalculation: BaseEntity /// Error message /// Reference date for the calculation /// Instance configured with error message - public static HbA1cCalculation FromError(string error, DateOnly referenceDate) + public static HbA1CCalculation FromError(string error, DateOnly referenceDate) { - return new HbA1cCalculation + return new HbA1CCalculation { - Status = HbA1cCalculationStatus.Error, + Status = HbA1CCalculationStatus.Error, Error = error, ReferenceDate = referenceDate }; diff --git a/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs b/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs index 4eff48d..b20d586 100644 --- a/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs +++ b/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs @@ -1,6 +1,6 @@ namespace Raccoon.Ninja.Domain.Core.Enums; -public enum HbA1cCalculationStatus +public enum HbA1CCalculationStatus { Success = 1, SuccessPartial = 2, diff --git a/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs b/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs index ddebb4a..7b7d482 100644 --- a/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs +++ b/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs @@ -18,10 +18,10 @@ public static bool HasElements(this ICollection list) return list is not null && list.Count > 0; } - public static HbA1cCalculation CalculateHbA1c(this IEnumerable list, DateOnly referenceDate) + public static HbA1CCalculation CalculateHbA1C(this IEnumerable list, DateOnly referenceDate) { if (list is null) - return HbA1cCalculation.FromError("No readings to calculate HbA1c", referenceDate); + return HbA1CCalculation.FromError("No readings to calculate HbA1c", referenceDate); var count = 0; var sum = 0f; @@ -33,28 +33,34 @@ public static HbA1cCalculation CalculateHbA1c(this IEnumerable l if (count == 0) { - return HbA1cCalculation.FromError("No readings returned from Db to calculate HbA1c", referenceDate); + return HbA1CCalculation.FromError("No readings returned from Db to calculate HbA1c", referenceDate); } var avg = sum / count; - var hbA1c = (avg + 46.7f) / 28.7f; - - //Should never happen, but just in case... -#pragma warning disable S2583 - if (count > ReadingsIn115Days) -#pragma warning restore S2583 - { - return HbA1cCalculation.FromError( - $"Too many readings to calculate HbA1c reliably. Expected {ReadingsIn115Days} but got {count}", referenceDate); - } + var hbA1C = (avg + 46.7f) / 28.7f; - return new HbA1cCalculation + EnsureNumberOfReadingsDidntExceedMax(count); + + return new HbA1CCalculation { - Value = hbA1c, + Value = hbA1C, ReferenceDate = referenceDate, - Status = count == ReadingsIn115Days - ? HbA1cCalculationStatus.Success - : HbA1cCalculationStatus.SuccessPartial + Status = GetStatusByReadingCount(count) }; } + + private static void EnsureNumberOfReadingsDidntExceedMax(int count) + { + if (count <= ReadingsIn115Days) return; + + throw new InvalidOperationException( + $"Too many readings to calculate HbA1c reliably. Expected {ReadingsIn115Days} but got {count}"); + } + + private static HbA1CCalculationStatus GetStatusByReadingCount(int count) + { + return count == ReadingsIn115Days + ? HbA1CCalculationStatus.Success + : HbA1CCalculationStatus.SuccessPartial; + } } \ No newline at end of file diff --git a/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs b/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs index c058704..30eaf61 100644 --- a/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs +++ b/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs @@ -2,11 +2,11 @@ namespace Raccoon.Ninja.Domain.Core.Models; -public record DataLatestHbA1cFuncResponse +public record DataLatestHbA1CFuncResponse { [JsonProperty("latestSuccessful")] - public HbA1cCalculationResponse LatestSuccessful { get; init; } + public HbA1CCalculationResponse LatestSuccessful { get; init; } [JsonProperty("latestPartialSuccessful")] - public HbA1cCalculationResponse LatestPartialSuccessful { get; init; } + public HbA1CCalculationResponse LatestPartialSuccessful { get; init; } }; \ No newline at end of file diff --git a/Raccoon.Ninja.Domain.Core/Models/HbA1cCalculationResponse.cs b/Raccoon.Ninja.Domain.Core/Models/HbA1cCalculationResponse.cs index 50124b9..ff0f61d 100644 --- a/Raccoon.Ninja.Domain.Core/Models/HbA1cCalculationResponse.cs +++ b/Raccoon.Ninja.Domain.Core/Models/HbA1cCalculationResponse.cs @@ -5,7 +5,7 @@ namespace Raccoon.Ninja.Domain.Core.Models; -public record HbA1cCalculationResponse +public record HbA1CCalculationResponse { [JsonProperty("id")] public string Id { get; init; } @@ -17,7 +17,7 @@ public record HbA1cCalculationResponse [JsonProperty("docType")] public AggregateType DocType { get; init; } [JsonProperty("referenceDate")] public DateOnly ReferenceDate { get; init; } [JsonProperty("createdAt")] public long CreatedAtUtc { get; init; } - [JsonProperty("status")] public HbA1cCalculationStatus Status { get; init; } + [JsonProperty("status")] public HbA1CCalculationStatus Status { get; init; } [JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)] public string Error { get; init; } @@ -27,12 +27,12 @@ public record HbA1cCalculationResponse /// [JsonProperty("isStale")] public bool IsStale => DateTime.UtcNow.Date.AddDays(-1) > CreatedAtUtc.ToUtcDateTime().Date; - public static implicit operator HbA1cCalculationResponse(HbA1cCalculation calculation) + public static implicit operator HbA1CCalculationResponse(HbA1CCalculation calculation) { if (calculation is null) return null; - return new HbA1cCalculationResponse + return new HbA1CCalculationResponse { Id = calculation.Id, Value = calculation.Value, diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/ExtensionMethods/GlucoseReadingResponseExtensions.cs b/Raccoon.Ninja.WForm.GlucoseIcon/ExtensionMethods/GlucoseReadingResponseExtensions.cs deleted file mode 100644 index b5b78b5..0000000 --- a/Raccoon.Ninja.WForm.GlucoseIcon/ExtensionMethods/GlucoseReadingResponseExtensions.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Raccoon.Ninja.Domain.Core.Enums; -using Raccoon.Ninja.Domain.Core.Models; - -namespace Raccoon.Ninja.WForm.GlucoseIcon.ExtensionMethods; - -public static class GlucoseReadingResponseExtensions -{ - public static string ToIconText(this GlucoseReadingResponse reading) - { - return reading.Trend switch - { - Trend.TripleUp => "UUU", - Trend.DoubleUp => " UU", - Trend.SingleUp => " U", - Trend.FortyFiveUp => "- -U", - Trend.Flat => "- - -", - Trend.FortyFiveDown => "- -D", - Trend.SingleDown => " D", - Trend.DoubleDown => " DD", - Trend.TripleDown => "DDD", - Trend.NotComputable => "? ?", - _ => throw new ArgumentOutOfRangeException() - }; - } -} \ No newline at end of file diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs index 14bc816..26246de 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs +++ b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs @@ -36,7 +36,7 @@ public static void LoadSettings() if (Config is not null) return; - throw new Exception($"The file {AppSettingsFile} could not be deserialized."); + throw new ApplicationException($"The file {AppSettingsFile} could not be deserialized."); } public static IDataFetcher GetDataFetcherBasedOnSettings() diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/TrendConverter.cs b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/TrendConverter.cs index 062ffc4..59a0ded 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/TrendConverter.cs +++ b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/TrendConverter.cs @@ -18,7 +18,7 @@ public static string ToNotifyIconText(this Trend trend) Trend.DoubleDown => " DD", Trend.TripleDown => "DDD", Trend.NotComputable => "? ?", - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException($"{trend} is not a valid trend.") }; } @@ -36,27 +36,7 @@ public static string ToTaskbarIconText(this Trend trend) Trend.DoubleDown => "\u2193\u2193", Trend.TripleDown => "\u2b07\u2b07\u2b07", Trend.NotComputable => "? ?", - _ => throw new ArgumentOutOfRangeException() - }; - } - - public static Font ToFont(this Trend trend) - { - const string fontFamily = "Arial"; - - return trend switch - { - Trend.TripleUp => new Font(fontFamily, 8), - Trend.DoubleUp => new Font(fontFamily, 10), - Trend.SingleUp => new Font(fontFamily, 12), - Trend.FortyFiveUp => new Font(fontFamily, 12), - Trend.Flat => new Font(fontFamily, 12), - Trend.FortyFiveDown => new Font(fontFamily, 12), - Trend.SingleDown => new Font(fontFamily, 12), - Trend.DoubleDown => new Font(fontFamily, 10), - Trend.TripleDown => new Font(fontFamily, 8), - Trend.NotComputable => new Font(fontFamily, 10), - _ => throw new ArgumentOutOfRangeException() + _ => throw new ArgumentOutOfRangeException($"{trend} is not a valid trend.") }; } } \ No newline at end of file From cbdb4fb128a7a1436c9150658a55e32b731544c1 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 02:25:49 -0500 Subject: [PATCH 02/11] feature/fix-sonar-issues: Fixed Sonar issues. --- .../ExtensionMethods/LongExtensionsTests.cs | 2 +- .../ExtensionMethods/ListExtensions.cs | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs index e4f2f61..e2f173c 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs @@ -62,7 +62,7 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() // Assert result.Status.Should().Be(HbA1CCalculationStatus.Error); - result.Error.Should().Be($"Too many readings to calculate HbA1c reliably. Expected 33120 but got {actualReadingCount}"); + result.Error.Should().Be($"Too many readings to calculate HbA1c reliably. Expected (max) 33120 but got {actualReadingCount}"); } [Theory] diff --git a/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs b/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs index 7b7d482..6641912 100644 --- a/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs +++ b/Raccoon.Ninja.Domain.Core/ExtensionMethods/ListExtensions.cs @@ -39,7 +39,12 @@ public static HbA1CCalculation CalculateHbA1C(this IEnumerable l var avg = sum / count; var hbA1C = (avg + 46.7f) / 28.7f; - EnsureNumberOfReadingsDidntExceedMax(count); + if (HasNumberOfReadingsExceededMax(count)) + { + return HbA1CCalculation.FromError( + $"Too many readings to calculate HbA1c reliably. Expected (max) {ReadingsIn115Days} but got {count}", + referenceDate); + } return new HbA1CCalculation { @@ -49,12 +54,10 @@ public static HbA1CCalculation CalculateHbA1C(this IEnumerable l }; } - private static void EnsureNumberOfReadingsDidntExceedMax(int count) + private static bool HasNumberOfReadingsExceededMax(int count) { - if (count <= ReadingsIn115Days) return; - - throw new InvalidOperationException( - $"Too many readings to calculate HbA1c reliably. Expected {ReadingsIn115Days} but got {count}"); + return count > ReadingsIn115Days; + } private static HbA1CCalculationStatus GetStatusByReadingCount(int count) From ce6f99d4849585db8d77b960188cc19735df1b18 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 02:39:04 -0500 Subject: [PATCH 03/11] feature/fix-sonar-issues: Fixing sonar issues + some tests were in the wrong file. --- .../ExtensionMethods/ListExtensionsTests.cs | 76 ++++++++++++++++++- .../ExtensionMethods/LongExtensionsTests.cs | 67 +--------------- .../Utils/AppSettings.cs | 2 +- 3 files changed, 76 insertions(+), 69 deletions(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs index 3489326..a38ac75 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs @@ -1,10 +1,15 @@ using FluentAssertions; +using Raccoon.Ninja.Domain.Core.Entities; +using Raccoon.Ninja.Domain.Core.Enums; using Raccoon.Ninja.Domain.Core.ExtensionMethods; +using Raccoon.Ninja.TestHelpers; namespace Raccoon.Ninja.Domain.Core.Tests.ExtensionMethods; public class ListExtensionsTests { + private static readonly DateOnly ReferenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + [Fact] public void HasElements_Should_Return_True_When_List_Has_Elements() { @@ -17,7 +22,7 @@ public void HasElements_Should_Return_True_When_List_Has_Elements() //Assert result.Should().BeTrue(); } - + [Fact] public void HasElements_Should_Return_False_When_List_Is_Null() { @@ -30,7 +35,7 @@ public void HasElements_Should_Return_False_When_List_Is_Null() //Assert result.Should().BeFalse(); } - + [Fact] public void HasElements_Should_Return_False_When_List_Is_Empty() { @@ -43,4 +48,71 @@ public void HasElements_Should_Return_False_When_List_Is_Empty() //Assert result.Should().BeFalse(); } + + [Fact] + public void CalculateHbA1c_WhenListIsNull_ShouldReturnError() + { + // Arrange + IEnumerable list = null; + + // Act + var result = list.CalculateHbA1C(ReferenceDate); + + // Assert + result.Status.Should().Be(HbA1CCalculationStatus.Error); + result.Error.Should().Be("No readings to calculate HbA1c"); + } + + [Fact] + public void CalculateHbA1c_WhenListIsEmpty_ShouldReturnError() + { + // Arrange + var list = new List(); + + // Act + var result = list.CalculateHbA1C(ReferenceDate); + + // Assert + result.Status.Should().Be(HbA1CCalculationStatus.Error); + result.Error.Should().Be("No readings returned from Db to calculate HbA1c"); + } + + [Fact] + public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() + { + // Arrange + var actualReadingCount = Constants.ReadingsIn115Days + 1; + var readings = Generators.GenerateList(actualReadingCount, 100); + + // Act + var result = readings.CalculateHbA1C(ReferenceDate); + + // Assert + result.Status.Should().Be(HbA1CCalculationStatus.Error); + result.Error.Should().Be($"Too many readings to calculate HbA1c reliably. Expected (max) 33120 but got {actualReadingCount}"); + } + + [Theory] + [MemberData(nameof(TheoryGenerator.PartiallyValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] + public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List readings, float expectedResult) + { + // Arrange & Act + var result = readings.CalculateHbA1C(ReferenceDate); + + // Assert + result.Status.Should().Be(HbA1CCalculationStatus.SuccessPartial); + result.Value.Should().Be(expectedResult); + } + + [Theory] + [MemberData(nameof(TheoryGenerator.ValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] + public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(List readings, float expectedResult) + { + // Arrange & Act + var result = readings.CalculateHbA1C(ReferenceDate); + + // Assert + result.Status.Should().Be(HbA1CCalculationStatus.Success); + result.Value.Should().Be(expectedResult); + } } \ No newline at end of file diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs index e2f173c..d12c6f8 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/LongExtensionsTests.cs @@ -9,7 +9,7 @@ namespace Raccoon.Ninja.Domain.Core.Tests.ExtensionMethods; public class LongExtensionsTests { private static readonly TimeSpan MillisecondsAccountingFor3FirstPlaces = TimeSpan.FromMilliseconds(100); - private static readonly DateOnly ReferenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + [Theory] [MemberData(nameof(TheoryGenerator.TimeStampAndCorrespondingDateTimes), MemberType = typeof(TheoryGenerator))] @@ -21,71 +21,6 @@ public void ToUtcDateTime_Success(long timestamp, DateTime expected) //Assert actual.Should().BeCloseTo(expected, MillisecondsAccountingFor3FirstPlaces); } - - [Fact] - public void CalculateHbA1c_WhenListIsNull_ShouldReturnError() - { - // Arrange - IEnumerable list = null; - - // Act - var result = list.CalculateHbA1C(ReferenceDate); - - // Assert - result.Status.Should().Be(HbA1CCalculationStatus.Error); - result.Error.Should().Be("No readings to calculate HbA1c"); - } - [Fact] - public void CalculateHbA1c_WhenListIsEmpty_ShouldReturnError() - { - // Arrange - var list = new List(); - - // Act - var result = list.CalculateHbA1C(ReferenceDate); - - // Assert - result.Status.Should().Be(HbA1CCalculationStatus.Error); - result.Error.Should().Be("No readings returned from Db to calculate HbA1c"); - } - - [Fact] - public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() - { - // Arrange - var actualReadingCount = Constants.ReadingsIn115Days + 1; - var readings = Generators.GenerateList(actualReadingCount, 100); - // Act - var result = readings.CalculateHbA1C(ReferenceDate); - - // Assert - result.Status.Should().Be(HbA1CCalculationStatus.Error); - result.Error.Should().Be($"Too many readings to calculate HbA1c reliably. Expected (max) 33120 but got {actualReadingCount}"); - } - - [Theory] - [MemberData(nameof(TheoryGenerator.PartiallyValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] - public void CalculateHbA1c_WhenListHasOneReading_ShouldReturnPartialSuccess(List readings, float expectedResult) - { - // Arrange & Act - var result = readings.CalculateHbA1C(ReferenceDate); - - // Assert - result.Status.Should().Be(HbA1CCalculationStatus.SuccessPartial); - result.Value.Should().Be(expectedResult); - } - - [Theory] - [MemberData(nameof(TheoryGenerator.ValidHb1AcDataSets), MemberType = typeof(TheoryGenerator))] - public void CalculateHbA1c_WhenListHasExactNumberOfReadings_ShouldReturnSuccess(List readings, float expectedResult) - { - // Arrange & Act - var result = readings.CalculateHbA1C(ReferenceDate); - - // Assert - result.Status.Should().Be(HbA1CCalculationStatus.Success); - result.Value.Should().Be(expectedResult); - } } \ No newline at end of file diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs index 26246de..e8263be 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs +++ b/Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs @@ -36,7 +36,7 @@ public static void LoadSettings() if (Config is not null) return; - throw new ApplicationException($"The file {AppSettingsFile} could not be deserialized."); + throw new ArgumentException($"The file {AppSettingsFile} could not be deserialized."); } public static IDataFetcher GetDataFetcherBasedOnSettings() From 4d771ed401b96fc614d86c1a73afebdcd0b92a23 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 12:18:55 -0500 Subject: [PATCH 04/11] feature/fix-sonar-issues: changing template-qa-sonarcloud.yml t okeep track of test coverage correctly. --- .github/workflows/template-qa-sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/template-qa-sonarcloud.yml b/.github/workflows/template-qa-sonarcloud.yml index 42871db..8153823 100644 --- a/.github/workflows/template-qa-sonarcloud.yml +++ b/.github/workflows/template-qa-sonarcloud.yml @@ -93,7 +93,7 @@ jobs: $sonarExclusions = "${{ inputs.sonarExclusions }}" $coverageExclusions = "${{ inputs.coverageExclusions }}" - $sonarBeginCmd = ".\.sonar\scanner\dotnet-sonarscanner begin /k:`"${{ inputs.projectKey }}`" /o:`"${{ inputs.organization }}`" /d:sonar.login=`"${{ secrets.sonarToken }}`" /d:sonar.host.url=`"https://sonarcloud.io`" /d:`"sonar.verbose=$verboseFlag`"" + $sonarBeginCmd = ".\.sonar\scanner\dotnet-sonarscanner begin /k:`"${{ inputs.projectKey }}`" /o:`"${{ inputs.organization }}`" /d:sonar.login=`"${{ secrets.sonarToken }}`" /d:sonar.host.url=`"https://sonarcloud.io`" /d:`"sonar.verbose=$verboseFlag`" /d:sonar.cs.vscoveragexml.reportsPaths=`"coverage.xml`"" if (-not [string]::IsNullOrWhiteSpace($sonarExclusions)) { $sonarBeginCmd += " /d:`"sonar.exclusions=$sonarExclusions`"" } From 0b706692e0dbbc1262d452f26caf4e4c4fac0c0e Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 13:39:21 -0500 Subject: [PATCH 05/11] feature/fix-sonar-issues: Improving test coverage. --- .github/workflows/qa-on-pull-requests.yml | 2 + .../Entities/HbA1CCalculationTests.cs | 115 ++++++++++++++++++ .../ExtensionMethods/ListExtensionsTests.cs | 2 +- .../Models/HbA1CCalculationResponseTests.cs | 107 ++++++++++++++++ Raccoon.Ninja.Domain.Core.Tests/Usings.cs | 5 +- .../Entities/HbA1cCalculation.cs | 2 +- .../Enums/HbA1cCalculationStatus.cs | 1 + .../Models/DataLatestHbA1cFuncResponse.cs | 4 +- Raccoon.Ninja.TestHelpers/Generators.cs | 55 ++++++++- Raccoon.Ninja.TestHelpers/TheoryGenerator.cs | 28 ++--- 10 files changed, 302 insertions(+), 19 deletions(-) create mode 100644 Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs create mode 100644 Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs diff --git a/.github/workflows/qa-on-pull-requests.yml b/.github/workflows/qa-on-pull-requests.yml index e32dfa6..a99c6db 100644 --- a/.github/workflows/qa-on-pull-requests.yml +++ b/.github/workflows/qa-on-pull-requests.yml @@ -14,6 +14,8 @@ jobs: projectKey: 'brenordv_nightscout-companion-apps' organization: 'raccoon-ninja' verbose: true + sonarExclusions: 'Raccoon.Ninja.TestHelpers/*' + coverageExclusions: 'Raccoon.Ninja.TestHelpers/*,**/*Program.cs,Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs,Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs,Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs' secrets: githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs new file mode 100644 index 0000000..61d79bb --- /dev/null +++ b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs @@ -0,0 +1,115 @@ +using Raccoon.Ninja.Domain.Core.Entities; +using Raccoon.Ninja.Domain.Core.Enums; +using Raccoon.Ninja.Domain.Core.ExtensionMethods; + +namespace Raccoon.Ninja.Domain.Core.Tests.Entities; + +public class HbA1CCalculationTests +{ + [Fact] + public void PropInit_ShouldSetPropertiesCorrectly() + { + // Arrange + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; + const string error = "Sample error"; + + // Act + var calculation = new HbA1CCalculation + { + ReferenceDate = referenceDate, + Status = status, + Error = error + }; + + // Assert + calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + calculation.ReferenceDate.Should().Be(referenceDate); + calculation.CreatedAtUtc.Should().BeCloseTo(DateTime.UtcNow.ToUnixTimestamp(), 1000); + calculation.Status.Should().Be(status); + calculation.Error.Should().Be(error); + } + + [Fact] + public void FromError_ShouldCreateErrorInstanceCorrectly() + { + // Arrange + const string error = "Error message"; + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + + // Act + var calculation = HbA1CCalculation.FromError(error, referenceDate); + + // Assert + calculation.Status.Should().Be(HbA1CCalculationStatus.Error); + calculation.Error.Should().Be(error); + calculation.ReferenceDate.Should().Be(referenceDate); + calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + } + + [Fact] + public void Records_WithSameValues_ShouldBeEqual() + { + // Arrange + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; // Assuming Error is a valid enum value + const string error = "Error message"; + + var calculation1 = new HbA1CCalculation + { + ReferenceDate = referenceDate, + Status = status, + Error = error + }; + + var calculation2 = new HbA1CCalculation + { + ReferenceDate = referenceDate, + Status = status, + Error = error + }; + + // Act & Assert + calculation1.Should().BeEquivalentTo(calculation2); + } + + [Fact] + public void GetHashCode_RecordsWithSameValues_ShouldHaveSameHashCode() + { + // Arrange + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; + const string error = "Sample error"; + + var calculation1 = new HbA1CCalculation + { + ReferenceDate = referenceDate, + Status = status, + Error = error + }; + + var calculation2 = new HbA1CCalculation + { + ReferenceDate = referenceDate, + Status = status, + Error = error + }; + + // Act & Assert + calculation1.GetHashCode().Should().Be(calculation2.GetHashCode()); + } + + [Fact] + public void Constructor_WithNoArguments_ShouldSetDefaultValues() + { + // Act + var calculation = new HbA1CCalculation(); + + // Assert + calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + calculation.CreatedAtUtc.Should().BeCloseTo(DateTime.UtcNow.ToUnixTimestamp(), 1000); + calculation.Status.Should().Be(HbA1CCalculationStatus.NotCalculated); + calculation.Error.Should().BeNull(); + calculation.ReferenceDate.Should().Be(default); + } +} diff --git a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs index a38ac75..440ec90 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/ExtensionMethods/ListExtensionsTests.cs @@ -82,7 +82,7 @@ public void CalculateHbA1c_WhenListHasMoreThanExpected_ShouldReturnError() { // Arrange var actualReadingCount = Constants.ReadingsIn115Days + 1; - var readings = Generators.GenerateList(actualReadingCount, 100); + var readings = Generators.GlucoseReadingMockList(actualReadingCount, 100); // Act var result = readings.CalculateHbA1C(ReferenceDate); diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs new file mode 100644 index 0000000..fe4590a --- /dev/null +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -0,0 +1,107 @@ +using Raccoon.Ninja.Domain.Core.Entities; +using Raccoon.Ninja.Domain.Core.Enums; +using Raccoon.Ninja.Domain.Core.ExtensionMethods; +using Raccoon.Ninja.Domain.Core.Models; +using Raccoon.Ninja.TestHelpers; + +namespace Raccoon.Ninja.Domain.Core.Tests.Models; + +public class HbA1CCalculationResponseTests +{ + [Fact] + public void PropInit_ShouldSetPropertiesCorrectly() + { + // Arrange + const float value = 5.5f; + const float delta = 0.5f; + const AggregateType docType = AggregateType.HbA1cCalculation; + const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; + const string error = "No error"; + + var id = Guid.NewGuid().ToString(); + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + var createdAtUtc = DateTimeExtensions.ToUnixTimestamp(DateTime.UtcNow); + + // Act + var response = new HbA1CCalculationResponse + { + Id = id, + Value = value, + Delta = delta, + DocType = docType, + ReferenceDate = referenceDate, + CreatedAtUtc = createdAtUtc, + Status = status, + Error = error + }; + + // Assert + response.Id.Should().Be(id); + response.Value.Should().Be(value); + response.Delta.Should().Be(delta); + response.DocType.Should().Be(docType); + response.ReferenceDate.Should().Be(referenceDate); + response.CreatedAtUtc.Should().Be(createdAtUtc); + response.Status.Should().Be(status); + response.Error.Should().Be(error); + } + + [Fact] + public void IsStale_ShouldBeTrue_IfMoreThanADayOld() + { + // Arrange + var response = new HbA1CCalculationResponse + { + CreatedAtUtc = DateTimeExtensions.ToUnixTimestamp(DateTime.UtcNow.AddDays(-2)) + }; + + // Act & Assert + response.IsStale.Should().BeTrue(); + } + + [Fact] + public void IsStale_ShouldBeFalse_IfLessThanADayOld() + { + // Arrange + var response = new HbA1CCalculationResponse + { + CreatedAtUtc = DateTimeExtensions.ToUnixTimestamp(DateTime.UtcNow) // Now + }; + + // Act & Assert + response.IsStale.Should().BeFalse(); + } + + [Fact] + public void ImplicitOperator_ShouldConvertCorrectly_FromHbA1CCalculation() + { + // Arrange + var calculation = Generators.HbA1CCalculationMockSingle(); + + // Act + HbA1CCalculationResponse response = calculation; // Implicit conversion + + // Assert + response.Id.Should().Be(calculation.Id); + response.Value.Should().Be(calculation.Value); + response.Delta.Should().Be(calculation.Delta); + response.DocType.Should().Be(calculation.DocType); + response.ReferenceDate.Should().Be(calculation.ReferenceDate); + response.CreatedAtUtc.Should().Be(calculation.CreatedAtUtc); + response.Status.Should().Be(calculation.Status); + response.Error.Should().Be(calculation.Error); + } + + [Fact] + public void ImplicitOperator_ShouldConvertCorrectly_FromNullHbA1CCalculation() + { + // Arrange + HbA1CCalculation calculation = null; + + // Act + HbA1CCalculationResponse response = calculation; // Implicit conversion + + // Assert + response.Should().BeNull(); + } +} diff --git a/Raccoon.Ninja.Domain.Core.Tests/Usings.cs b/Raccoon.Ninja.Domain.Core.Tests/Usings.cs index 8c927eb..bc3a47a 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Usings.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Usings.cs @@ -1 +1,4 @@ -global using Xunit; \ No newline at end of file +global using Xunit; +global using FluentAssertions; +global using Newtonsoft.Json; +global using System; \ No newline at end of file diff --git a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs index f29a992..b116c3f 100644 --- a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs +++ b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs @@ -9,7 +9,7 @@ public record HbA1CCalculation: BaseEntity [JsonProperty("docType")] public AggregateType DocType { get; init; } = AggregateType.HbA1cCalculation; [JsonProperty("referenceDate")] public DateOnly ReferenceDate { get; init; } [JsonProperty("createdAt")] public long CreatedAtUtc { get; init; } = DateTime.UtcNow.ToUnixTimestamp(); - [JsonProperty("status")] public HbA1CCalculationStatus Status { get; init; } + [JsonProperty("status")] public HbA1CCalculationStatus Status { get; init; } = HbA1CCalculationStatus.NotCalculated; [JsonProperty("error", NullValueHandling = NullValueHandling.Ignore)] public string Error { get; init; } /// diff --git a/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs b/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs index b20d586..5ef83df 100644 --- a/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs +++ b/Raccoon.Ninja.Domain.Core/Enums/HbA1cCalculationStatus.cs @@ -2,6 +2,7 @@ public enum HbA1CCalculationStatus { + NotCalculated = 0, Success = 1, SuccessPartial = 2, Error = 3 diff --git a/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs b/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs index 30eaf61..f3771e1 100644 --- a/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs +++ b/Raccoon.Ninja.Domain.Core/Models/DataLatestHbA1cFuncResponse.cs @@ -1,7 +1,9 @@ -using Newtonsoft.Json; +using System.Diagnostics.CodeAnalysis; +using Newtonsoft.Json; namespace Raccoon.Ninja.Domain.Core.Models; +[ExcludeFromCodeCoverage] public record DataLatestHbA1CFuncResponse { [JsonProperty("latestSuccessful")] diff --git a/Raccoon.Ninja.TestHelpers/Generators.cs b/Raccoon.Ninja.TestHelpers/Generators.cs index 434fd0f..d399675 100644 --- a/Raccoon.Ninja.TestHelpers/Generators.cs +++ b/Raccoon.Ninja.TestHelpers/Generators.cs @@ -1,12 +1,13 @@ using Bogus; using Raccoon.Ninja.Domain.Core.Entities; using Raccoon.Ninja.Domain.Core.Enums; +using Raccoon.Ninja.Domain.Core.Models; namespace Raccoon.Ninja.TestHelpers; public static class Generators { - public static List GenerateList(int qty, float value) + public static IList GlucoseReadingMockList(int qty, float value) { var faker = new Faker() .RuleFor(x => x.Id, f => f.Random.Guid().ToString()) @@ -16,4 +17,56 @@ public static List GenerateList(int qty, float value) return faker.Generate(qty); } + + public static IList HbA1CCalculationResponseMockList(int qty, float? value = null, + float? delta = null, HbA1CCalculationStatus? status = null, string error = null) + { + var faker = new Faker() + .RuleFor(x => x.Id, f => f.Random.Guid().ToString()) + .RuleFor(x => x.Value, f => value ?? f.Random.Float(4, 8)) + .RuleFor(x => x.Delta, f => delta ?? f.Random.Float(-1, 2)) + .RuleFor(x => x.DocType, f => AggregateType.HbA1cCalculation) + .RuleFor(x => x.ReferenceDate, f => DateOnly.FromDateTime(f.Date.Past())) + .RuleFor(x => x.CreatedAtUtc, f => f.Date.Past().ToUnixTimestamp()) + .RuleFor(x => x.Status, f => GetRandomHbA1CCalculationStatusWithinReason(f, status, error)) + .RuleFor(x => x.Error, f => error); + + return faker.Generate(qty); + } + + public static HbA1CCalculationResponse HbA1CCalculationResponseMockSingle(float? value = null, + float? delta = null, HbA1CCalculationStatus? status = null, string error = null) + { + return HbA1CCalculationResponseMockList(1, value, delta, status, error)[0]; + } + + public static IList HbA1CCalculationMockList(int qty, HbA1CCalculationStatus? status = null, + string error = null) + { + var faker = new Faker() + .RuleFor(x => x.Id, f => f.Random.Guid().ToString()) + .RuleFor(x => x.ReferenceDate, f => DateOnly.FromDateTime(f.Date.Past())) + .RuleFor(x => x.CreatedAtUtc, f => f.Date.Past().ToUnixTimestamp()) + .RuleFor(x => x.Status, f => GetRandomHbA1CCalculationStatusWithinReason(f, status, error)) + .RuleFor(x => x.Error, f => error); + + return faker.Generate(qty); + } + + public static HbA1CCalculation HbA1CCalculationMockSingle(HbA1CCalculationStatus? status = null, + string error = null) + { + return HbA1CCalculationMockList(1, status, error)[0]; + } + + private static HbA1CCalculationStatus GetRandomHbA1CCalculationStatusWithinReason(Faker f, HbA1CCalculationStatus? inputStatus, + string error) + { + if (inputStatus.HasValue) + return inputStatus.Value; + + return string.IsNullOrWhiteSpace(error) + ? f.Random.Enum() + : HbA1CCalculationStatus.Error; + } } \ No newline at end of file diff --git a/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs b/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs index 9d37f10..dbc8e28 100644 --- a/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs +++ b/Raccoon.Ninja.TestHelpers/TheoryGenerator.cs @@ -51,24 +51,24 @@ public static IEnumerable TimeStampAndCorrespondingDateTimes() public static IEnumerable ValidHb1AcDataSets() { - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 80), 4.4146338f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 100), 5.111498f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 150), 6.853658f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 170), 7.5505223f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 210), 8.944251f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 300), 12.080139f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn115Days, 400), 15.56446f }; + 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 }; } public static IEnumerable PartiallyValidHb1AcDataSets() { - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 80), 4.4146338f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 100), 5.111498f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 150), 6.853658f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 170), 7.5505223f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 210), 8.944251f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 300), 12.080139f }; - yield return new object[] { Generators.GenerateList(Constants.ReadingsIn1Day, 400), 15.56446f }; + 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 }; } From 6a9f4d7a3f7f4d093457b4bbae862b23dbbe25b4 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 14:17:10 -0500 Subject: [PATCH 06/11] feature/fix-sonar-issues: Improving test coverage. --- .github/workflows/qa-on-pull-requests.yml | 4 +- .../Entities/HbA1CCalculationTests.cs | 37 +++++++++++++++++-- .../Models/HbA1CCalculationResponseTests.cs | 20 +++++++++- .../Entities/HbA1cCalculation.cs | 2 +- .../Enums/AggregateType.cs | 3 +- Raccoon.Ninja.TestHelpers/Generators.cs | 2 +- 6 files changed, 59 insertions(+), 9 deletions(-) diff --git a/.github/workflows/qa-on-pull-requests.yml b/.github/workflows/qa-on-pull-requests.yml index a99c6db..f5c39d1 100644 --- a/.github/workflows/qa-on-pull-requests.yml +++ b/.github/workflows/qa-on-pull-requests.yml @@ -14,8 +14,8 @@ jobs: projectKey: 'brenordv_nightscout-companion-apps' organization: 'raccoon-ninja' verbose: true - sonarExclusions: 'Raccoon.Ninja.TestHelpers/*' - coverageExclusions: 'Raccoon.Ninja.TestHelpers/*,**/*Program.cs,Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs,Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs,Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs' + sonarExclusions: '**/*Usings.cs,Raccoon.Ninja.TestHelpers/*' + coverageExclusions: '**/*Usings.cs,Raccoon.Ninja.TestHelpers/*,**/*Program.cs,Raccoon.Ninja.WForm.GlucoseIcon/Utils/AppSettings.cs,Raccoon.Ninja.AzFn.DataApi/DataLatestHbA1cFunc.cs,Raccoon.Ninja.AzFn.DataTransfer/HbA1cCalcFunc.cs' secrets: githubToken: ${{ secrets.GITHUB_TOKEN }} diff --git a/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs index 61d79bb..cc07937 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs @@ -11,19 +11,25 @@ public void PropInit_ShouldSetPropertiesCorrectly() { // Arrange var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + var id = Guid.NewGuid().ToString(); const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; const string error = "Sample error"; + const float value = 5.5f; + const float delta = 0.5f; // Act var calculation = new HbA1CCalculation { + Id = id, + Value = value, + Delta = delta, ReferenceDate = referenceDate, Status = status, Error = error }; // Assert - calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + calculation.DocType.Should().Be(AggregateType.HbA1CCalculation); calculation.ReferenceDate.Should().Be(referenceDate); calculation.CreatedAtUtc.Should().BeCloseTo(DateTime.UtcNow.ToUnixTimestamp(), 1000); calculation.Status.Should().Be(status); @@ -41,10 +47,13 @@ public void FromError_ShouldCreateErrorInstanceCorrectly() var calculation = HbA1CCalculation.FromError(error, referenceDate); // Assert + calculation.Id.Should().NotBeNullOrWhiteSpace(); + calculation.Value.Should().Be(default); + calculation.Delta.Should().BeNull(); calculation.Status.Should().Be(HbA1CCalculationStatus.Error); calculation.Error.Should().Be(error); calculation.ReferenceDate.Should().Be(referenceDate); - calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + calculation.DocType.Should().Be(AggregateType.HbA1CCalculation); } [Fact] @@ -52,11 +61,18 @@ public void Records_WithSameValues_ShouldBeEqual() { // Arrange var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + var id = Guid.NewGuid().ToString(); const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; // Assuming Error is a valid enum value const string error = "Error message"; + const float value = 5.5f; + const float delta = 0.5f; + var calculation1 = new HbA1CCalculation { + Id = id, + Value = value, + Delta = delta, ReferenceDate = referenceDate, Status = status, Error = error @@ -64,6 +80,9 @@ public void Records_WithSameValues_ShouldBeEqual() var calculation2 = new HbA1CCalculation { + Id = id, + Value = value, + Delta = delta, ReferenceDate = referenceDate, Status = status, Error = error @@ -78,11 +97,17 @@ public void GetHashCode_RecordsWithSameValues_ShouldHaveSameHashCode() { // Arrange var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + var id = Guid.NewGuid().ToString(); const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; const string error = "Sample error"; + const float value = 5.5f; + const float delta = 0.5f; var calculation1 = new HbA1CCalculation { + Id = id, + Value = value, + Delta = delta, ReferenceDate = referenceDate, Status = status, Error = error @@ -90,6 +115,9 @@ public void GetHashCode_RecordsWithSameValues_ShouldHaveSameHashCode() var calculation2 = new HbA1CCalculation { + Id = id, + Value = value, + Delta = delta, ReferenceDate = referenceDate, Status = status, Error = error @@ -106,7 +134,10 @@ public void Constructor_WithNoArguments_ShouldSetDefaultValues() var calculation = new HbA1CCalculation(); // Assert - calculation.DocType.Should().Be(AggregateType.HbA1cCalculation); + calculation.Id.Should().NotBeNullOrWhiteSpace(); + calculation.Value.Should().Be(default); + calculation.Delta.Should().BeNull(); + calculation.DocType.Should().Be(AggregateType.HbA1CCalculation); calculation.CreatedAtUtc.Should().BeCloseTo(DateTime.UtcNow.ToUnixTimestamp(), 1000); calculation.Status.Should().Be(HbA1CCalculationStatus.NotCalculated); calculation.Error.Should().BeNull(); diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs index fe4590a..97d3e36 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -14,7 +14,7 @@ public void PropInit_ShouldSetPropertiesCorrectly() // Arrange const float value = 5.5f; const float delta = 0.5f; - const AggregateType docType = AggregateType.HbA1cCalculation; + const AggregateType docType = AggregateType.HbA1CCalculation; const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; const string error = "No error"; @@ -104,4 +104,22 @@ public void ImplicitOperator_ShouldConvertCorrectly_FromNullHbA1CCalculation() // Assert response.Should().BeNull(); } + + [Fact] + public void Constructor_WithNoArguments_ShouldSetDefaultValues() + { + // Act + var response = new HbA1CCalculationResponse(); + + // Assert + response.Id.Should().BeNull(); + response.Value.Should().Be(default); + response.Delta.Should().BeNull(); + response.DocType.Should().Be(AggregateType.Unknown); + response.ReferenceDate.Should().Be(default); + response.CreatedAtUtc.Should().Be(default); + response.Status.Should().Be(HbA1CCalculationStatus.NotCalculated); + response.Error.Should().BeNull(); + response.IsStale.Should().BeTrue(); + } } diff --git a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs index b116c3f..4885930 100644 --- a/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs +++ b/Raccoon.Ninja.Domain.Core/Entities/HbA1cCalculation.cs @@ -6,7 +6,7 @@ namespace Raccoon.Ninja.Domain.Core.Entities; public record HbA1CCalculation: BaseEntity { - [JsonProperty("docType")] public AggregateType DocType { get; init; } = AggregateType.HbA1cCalculation; + [JsonProperty("docType")] public AggregateType DocType { get; init; } = AggregateType.HbA1CCalculation; [JsonProperty("referenceDate")] public DateOnly ReferenceDate { get; init; } [JsonProperty("createdAt")] public long CreatedAtUtc { get; init; } = DateTime.UtcNow.ToUnixTimestamp(); [JsonProperty("status")] public HbA1CCalculationStatus Status { get; init; } = HbA1CCalculationStatus.NotCalculated; diff --git a/Raccoon.Ninja.Domain.Core/Enums/AggregateType.cs b/Raccoon.Ninja.Domain.Core/Enums/AggregateType.cs index b97188b..d1b555d 100644 --- a/Raccoon.Ninja.Domain.Core/Enums/AggregateType.cs +++ b/Raccoon.Ninja.Domain.Core/Enums/AggregateType.cs @@ -2,5 +2,6 @@ public enum AggregateType { - HbA1cCalculation = 1, + Unknown = 0, + HbA1CCalculation = 1, } \ No newline at end of file diff --git a/Raccoon.Ninja.TestHelpers/Generators.cs b/Raccoon.Ninja.TestHelpers/Generators.cs index d399675..49b1f2d 100644 --- a/Raccoon.Ninja.TestHelpers/Generators.cs +++ b/Raccoon.Ninja.TestHelpers/Generators.cs @@ -25,7 +25,7 @@ public static IList HbA1CCalculationResponseMockList(i .RuleFor(x => x.Id, f => f.Random.Guid().ToString()) .RuleFor(x => x.Value, f => value ?? f.Random.Float(4, 8)) .RuleFor(x => x.Delta, f => delta ?? f.Random.Float(-1, 2)) - .RuleFor(x => x.DocType, f => AggregateType.HbA1cCalculation) + .RuleFor(x => x.DocType, f => AggregateType.HbA1CCalculation) .RuleFor(x => x.ReferenceDate, f => DateOnly.FromDateTime(f.Date.Past())) .RuleFor(x => x.CreatedAtUtc, f => f.Date.Past().ToUnixTimestamp()) .RuleFor(x => x.Status, f => GetRandomHbA1CCalculationStatusWithinReason(f, status, error)) From c3508dcaffd4767b94a062165c990493abb99416 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 14:48:36 -0500 Subject: [PATCH 07/11] feature/fix-sonar-issues: Improving test coverage. --- .../Entities/HbA1CCalculationTests.cs | 35 ------------ .../Models/HbA1CCalculationResponseTests.cs | 54 +++++++++++++++++++ 2 files changed, 54 insertions(+), 35 deletions(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs index cc07937..4ef3d50 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Entities/HbA1CCalculationTests.cs @@ -92,41 +92,6 @@ public void Records_WithSameValues_ShouldBeEqual() calculation1.Should().BeEquivalentTo(calculation2); } - [Fact] - public void GetHashCode_RecordsWithSameValues_ShouldHaveSameHashCode() - { - // Arrange - var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); - var id = Guid.NewGuid().ToString(); - const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; - const string error = "Sample error"; - const float value = 5.5f; - const float delta = 0.5f; - - var calculation1 = new HbA1CCalculation - { - Id = id, - Value = value, - Delta = delta, - ReferenceDate = referenceDate, - Status = status, - Error = error - }; - - var calculation2 = new HbA1CCalculation - { - Id = id, - Value = value, - Delta = delta, - ReferenceDate = referenceDate, - Status = status, - Error = error - }; - - // Act & Assert - calculation1.GetHashCode().Should().Be(calculation2.GetHashCode()); - } - [Fact] public void Constructor_WithNoArguments_ShouldSetDefaultValues() { diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs index 97d3e36..3886ab8 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -122,4 +122,58 @@ public void Constructor_WithNoArguments_ShouldSetDefaultValues() response.Error.Should().BeNull(); response.IsStale.Should().BeTrue(); } + + [Fact] + public void EqualityOperator_ShouldReturnFalse_IfNotEqual() + { + // Arrange + var response1 = Generators.HbA1CCalculationResponseMockSingle(); + var response2 = Generators.HbA1CCalculationResponseMockSingle(); + + // Act & Assert + (response1 == response2).Should().BeFalse(); + } + + [Fact] + public void EqualityOperator_ShouldReturnTrue_IfEqual() + { + // Arrange + // Arrange + const float value = 5.5f; + const float delta = 0.5f; + const AggregateType docType = AggregateType.HbA1CCalculation; + const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; + const string error = "No error"; + + var id = Guid.NewGuid().ToString(); + var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); + var createdAtUtc = DateTimeExtensions.ToUnixTimestamp(DateTime.UtcNow); + + var response1 = new HbA1CCalculationResponse + { + Id = id, + Value = value, + Delta = delta, + DocType = docType, + ReferenceDate = referenceDate, + CreatedAtUtc = createdAtUtc, + Status = status, + Error = error + }; + + var response2 = new HbA1CCalculationResponse + { + Id = id, + Value = value, + Delta = delta, + DocType = docType, + ReferenceDate = referenceDate, + CreatedAtUtc = createdAtUtc, + Status = status, + Error = error + }; + + // Act & Assert + (response1 == response2).Should().BeTrue(); + } } From c211d34f482dfd014d062ef6e088a6463478bc19 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 15:00:02 -0500 Subject: [PATCH 08/11] (Trying to) improve test coverage. --- .../Models/HbA1CCalculationResponseTests.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs index 3886ab8..203d3c6 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -137,7 +137,6 @@ public void EqualityOperator_ShouldReturnFalse_IfNotEqual() [Fact] public void EqualityOperator_ShouldReturnTrue_IfEqual() { - // Arrange // Arrange const float value = 5.5f; const float delta = 0.5f; @@ -176,4 +175,17 @@ public void EqualityOperator_ShouldReturnTrue_IfEqual() // Act & Assert (response1 == response2).Should().BeTrue(); } + + [Fact] + public void ToString_ShouldReturnCorrectString() + { + // Arrange + var response = Generators.HbA1CCalculationResponseMockSingle(); + + // Act + var str = response.ToString(); + + // Assert + str.Should().Be($"HbA1CCalculationResponse {{ Id = {response.Id}, Value = {response.Value}, Delta = {response.Delta}, DocType = {response.DocType}, ReferenceDate = {response.ReferenceDate}, CreatedAtUtc = {response.CreatedAtUtc}, Status = {response.Status}, Error = {response.Error}, IsStale = {response.IsStale} }}"); + } } From 74350c8cbab3d63584f92eec9c368e24b158d06b Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 15:42:38 -0500 Subject: [PATCH 09/11] (Trying to) improve test coverage. --- .../Models/HbA1CCalculationResponseTests.cs | 62 +------------------ 1 file changed, 3 insertions(+), 59 deletions(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs index 203d3c6..981a001 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -122,70 +122,14 @@ public void Constructor_WithNoArguments_ShouldSetDefaultValues() response.Error.Should().BeNull(); response.IsStale.Should().BeTrue(); } - - [Fact] - public void EqualityOperator_ShouldReturnFalse_IfNotEqual() - { - // Arrange - var response1 = Generators.HbA1CCalculationResponseMockSingle(); - var response2 = Generators.HbA1CCalculationResponseMockSingle(); - // Act & Assert - (response1 == response2).Should().BeFalse(); - } - [Fact] - public void EqualityOperator_ShouldReturnTrue_IfEqual() + public void HbA1CCalculationResponse_ShouldNotBeAStruct() { // Arrange - const float value = 5.5f; - const float delta = 0.5f; - const AggregateType docType = AggregateType.HbA1CCalculation; - const HbA1CCalculationStatus status = HbA1CCalculationStatus.Error; - const string error = "No error"; - - var id = Guid.NewGuid().ToString(); - var referenceDate = DateOnly.FromDateTime(DateTime.UtcNow); - var createdAtUtc = DateTimeExtensions.ToUnixTimestamp(DateTime.UtcNow); - - var response1 = new HbA1CCalculationResponse - { - Id = id, - Value = value, - Delta = delta, - DocType = docType, - ReferenceDate = referenceDate, - CreatedAtUtc = createdAtUtc, - Status = status, - Error = error - }; - - var response2 = new HbA1CCalculationResponse - { - Id = id, - Value = value, - Delta = delta, - DocType = docType, - ReferenceDate = referenceDate, - CreatedAtUtc = createdAtUtc, - Status = status, - Error = error - }; + var type = typeof(HbA1CCalculationResponse); // Act & Assert - (response1 == response2).Should().BeTrue(); - } - - [Fact] - public void ToString_ShouldReturnCorrectString() - { - // Arrange - var response = Generators.HbA1CCalculationResponseMockSingle(); - - // Act - var str = response.ToString(); - - // Assert - str.Should().Be($"HbA1CCalculationResponse {{ Id = {response.Id}, Value = {response.Value}, Delta = {response.Delta}, DocType = {response.DocType}, ReferenceDate = {response.ReferenceDate}, CreatedAtUtc = {response.CreatedAtUtc}, Status = {response.Status}, Error = {response.Error}, IsStale = {response.IsStale} }}"); + type.IsValueType.Should().BeFalse(); } } From 40cc6fa8bc4218904834c1fd1c0d89252c906d6e Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 15:52:17 -0500 Subject: [PATCH 10/11] Removed a useless task. --- .../Models/HbA1CCalculationResponseTests.cs | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs index 981a001..97d3e36 100644 --- a/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs +++ b/Raccoon.Ninja.Domain.Core.Tests/Models/HbA1CCalculationResponseTests.cs @@ -122,14 +122,4 @@ public void Constructor_WithNoArguments_ShouldSetDefaultValues() response.Error.Should().BeNull(); response.IsStale.Should().BeTrue(); } - - [Fact] - public void HbA1CCalculationResponse_ShouldNotBeAStruct() - { - // Arrange - var type = typeof(HbA1CCalculationResponse); - - // Act & Assert - type.IsValueType.Should().BeFalse(); - } } From cfb4a25a7fb46d9d049c170898c77f317845b149 Mon Sep 17 00:00:00 2001 From: Breno RdV Date: Sun, 4 Feb 2024 15:53:43 -0500 Subject: [PATCH 11/11] Bumping versions. --- Raccoon.Ninja.AzFn.DataApi/Raccoon.Ninja.AzFn.DataApi.csproj | 4 ++-- .../Raccoon.Ninja.AzFn.DataTransfer.csproj | 4 ++-- .../Raccoon.Ninja.Cli.CGMDataDisplayLauncher.csproj | 4 ++-- .../Raccoon.Ninja.WForm.GlucoseIcon.csproj | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Raccoon.Ninja.AzFn.DataApi/Raccoon.Ninja.AzFn.DataApi.csproj b/Raccoon.Ninja.AzFn.DataApi/Raccoon.Ninja.AzFn.DataApi.csproj index 3563f3c..7d5bd64 100644 --- a/Raccoon.Ninja.AzFn.DataApi/Raccoon.Ninja.AzFn.DataApi.csproj +++ b/Raccoon.Ninja.AzFn.DataApi/Raccoon.Ninja.AzFn.DataApi.csproj @@ -2,8 +2,8 @@ net6.0 V4 - 1.1.0 - 1.1.0 + 1.1.1 + 1.1.1 en-US diff --git a/Raccoon.Ninja.AzFn.DataTransfer/Raccoon.Ninja.AzFn.DataTransfer.csproj b/Raccoon.Ninja.AzFn.DataTransfer/Raccoon.Ninja.AzFn.DataTransfer.csproj index b3b88e7..9485528 100644 --- a/Raccoon.Ninja.AzFn.DataTransfer/Raccoon.Ninja.AzFn.DataTransfer.csproj +++ b/Raccoon.Ninja.AzFn.DataTransfer/Raccoon.Ninja.AzFn.DataTransfer.csproj @@ -2,8 +2,8 @@ net6.0 V4 - 1.1.0 - 1.1.0 + 1.1.1 + 1.1.1 en-US diff --git a/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Raccoon.Ninja.Cli.CGMDataDisplayLauncher.csproj b/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Raccoon.Ninja.Cli.CGMDataDisplayLauncher.csproj index 15b73f9..fe1849b 100644 --- a/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Raccoon.Ninja.Cli.CGMDataDisplayLauncher.csproj +++ b/Raccoon.Ninja.Cli.CGMDataDisplayLauncher/Raccoon.Ninja.Cli.CGMDataDisplayLauncher.csproj @@ -5,8 +5,8 @@ net6.0 enable disable - 1.1.0 - 1.1.0 + 1.1.1 + 1.1.1 en-US CGMDataDisplay.Launcher diff --git a/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj b/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj index 99ac477..b82e0dc 100644 --- a/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj +++ b/Raccoon.Ninja.WForm.GlucoseIcon/Raccoon.Ninja.WForm.GlucoseIcon.csproj @@ -5,8 +5,8 @@ disable true enable - 1.1.0 - 1.1.0 + 1.1.1 + 1.1.1 en-US CGMDataDisplay