diff --git a/src/Altinn.Auth.AuditLog/Services/PartitionCreationHostedService.cs b/src/Altinn.Auth.AuditLog/Services/PartitionCreationHostedService.cs index 3645a34..bcdf9e8 100644 --- a/src/Altinn.Auth.AuditLog/Services/PartitionCreationHostedService.cs +++ b/src/Altinn.Auth.AuditLog/Services/PartitionCreationHostedService.cs @@ -162,7 +162,7 @@ internal IReadOnlyList GetPartitionsForCurrentAndAdjacentMonths() internal (DateOnly startDate, DateOnly endDate) GetMonthStartAndEndDate(DateOnly date) { DateOnly startDate = new DateOnly(date.Year, date.Month, 1); - DateOnly endDate = startDate.AddMonths(1).AddDays(-1); + DateOnly endDate = startDate.AddMonths(1); return (startDate, endDate); } } diff --git a/test/Altinn.Auth.AuditLog.Tests/PartitionCreationHosterServiceTests.cs b/test/Altinn.Auth.AuditLog.Tests/PartitionCreationHosterServiceTests.cs index 934da50..1118522 100644 --- a/test/Altinn.Auth.AuditLog.Tests/PartitionCreationHosterServiceTests.cs +++ b/test/Altinn.Auth.AuditLog.Tests/PartitionCreationHosterServiceTests.cs @@ -20,15 +20,15 @@ public void GetPartitionsForCurrentAndAdjacentMonths_ReturnsCorrectPartitions() // Assert Assert.Equal(6, partitions.Count); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m09" && p.StartDate == new DateOnly(2023, 9, 1) && p.EndDate == new DateOnly(2023, 9, 30)); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m10" && p.StartDate == new DateOnly(2023, 10, 1) && p.EndDate == new DateOnly(2023, 10, 31)); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m11" && p.StartDate == new DateOnly(2023, 11, 1) && p.EndDate == new DateOnly(2023, 11, 30)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m09" && p.StartDate == new DateOnly(2023, 9, 1) && p.EndDate == new DateOnly(2023, 10, 1)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m10" && p.StartDate == new DateOnly(2023, 10, 1) && p.EndDate == new DateOnly(2023, 11, 1)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m11" && p.StartDate == new DateOnly(2023, 11, 1) && p.EndDate == new DateOnly(2023, 12, 1)); } [Theory] - [InlineData(2023, 10, 15, 2023, 10, 1, 2023, 10, 31)] - [InlineData(2023, 2, 1, 2023, 2, 1, 2023, 2, 28)] - [InlineData(2024, 2, 1, 2024, 2, 1, 2024, 2, 29)] // Leap year + [InlineData(2023, 10, 15, 2023, 10, 1, 2023, 11, 1)] + [InlineData(2023, 2, 1, 2023, 2, 1, 2023, 3, 1)] + [InlineData(2024, 2, 1, 2024, 2, 1, 2024, 3, 1)] public void GetMonthStartAndEndDate_ReturnsCorrectDates(int year, int month, int day, int expectedStartYear, int expectedStartMonth, int expectedStartDay, int expectedEndYear, int expectedEndMonth, int expectedEndDay) { // Arrange @@ -55,8 +55,8 @@ public void GetPartitionsForCurrentAndAdjacentMonths_CrossYearBoundary_ReturnsCo // Assert Assert.Equal(6, partitions.Count); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m11" && p.StartDate == new DateOnly(2023, 11, 1) && p.EndDate == new DateOnly(2023, 11, 30)); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m12" && p.StartDate == new DateOnly(2023, 12, 1) && p.EndDate == new DateOnly(2023, 12, 31)); - Assert.Contains(partitions, p => p.Name == "eventlogv1_y2024m01" && p.StartDate == new DateOnly(2024, 1, 1) && p.EndDate == new DateOnly(2024, 1, 31)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m11" && p.StartDate == new DateOnly(2023, 11, 1) && p.EndDate == new DateOnly(2023, 12, 1)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2023m12" && p.StartDate == new DateOnly(2023, 12, 1) && p.EndDate == new DateOnly(2024, 1, 1)); + Assert.Contains(partitions, p => p.Name == "eventlogv1_y2024m01" && p.StartDate == new DateOnly(2024, 1, 1) && p.EndDate == new DateOnly(2024, 2, 1)); } }