From c35ac16e19ceab39d6b9e95ca86ad23564f95849 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Mon, 4 Oct 2021 22:37:57 +0100 Subject: [PATCH] test: :white_check_mark: Fixed tests --- .../Engine/MovieRequestLimitsTests.cs | 18 ++++++------- .../Engine/MusicRequestLimitTests.cs | 24 ++++++++--------- .../Engine/TvRequestLimitsTests.cs | 26 +++++++++---------- src/Ombi.Core/Services/RequestLimitService.cs | 4 +-- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs index 9e1f0abaf..6cea851cf 100644 --- a/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs +++ b/src/Ombi.Core.Tests/Engine/MovieRequestLimitsTests.cs @@ -112,7 +112,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = DateTime.Now.AddDays(-1); var log = new List { new RequestLog @@ -145,7 +145,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -220,7 +220,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -253,7 +253,7 @@ namespace Ombi.Core.Tests.Engine Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -286,7 +286,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -325,7 +325,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var lastWeek = new DateTime(2020, 10, 05).FirstDateInWeek().AddDays(-1); // Day before reset + var lastWeek = new DateTime(2020, 09, 05).FirstDateInWeek().AddDays(-1); // Day before reset var log = new List { new RequestLog @@ -428,7 +428,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1); + var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1); var log = new List { new RequestLog @@ -460,7 +460,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var firstDayOfMonth = new DateTime(today.Year, today.Month, 1); var log = new List { @@ -494,7 +494,7 @@ namespace Ombi.Core.Tests.Engine MovieRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var firstDayOfMonth = new DateTime(today.Year, today.Month, 1); var log = new List { diff --git a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs index ac1abae1f..56fed73b5 100644 --- a/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs +++ b/src/Ombi.Core.Tests/Engine/MusicRequestLimitTests.cs @@ -112,7 +112,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = DateTime.UtcNow.AddDays(-1); var log = new List { new RequestLog @@ -145,7 +145,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -220,7 +220,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -253,7 +253,7 @@ namespace Ombi.Core.Tests.Engine Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -286,7 +286,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -325,7 +325,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var lastWeek = new DateTime(2020, 10, 05).FirstDateInWeek().AddDays(-1); // Day before reset + var lastWeek = new DateTime(2020, 09, 05).FirstDateInWeek().AddDays(-1); // Day before reset var log = new List { new RequestLog @@ -390,20 +390,20 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog { UserId = "id1", RequestType = RequestType.Album, - RequestDate = today, + RequestDate = today.AddMinutes(-2), }, new RequestLog { UserId = "id1", RequestType = RequestType.Album, - RequestDate = today, + RequestDate = today.AddMinutes(-1), }, }; var repoMock = _mocker.GetMock>(); @@ -428,7 +428,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1); + var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1); var log = new List { new RequestLog @@ -460,7 +460,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var firstDayOfMonth = new DateTime(today.Year, today.Month, 1); var log = new List { @@ -494,7 +494,7 @@ namespace Ombi.Core.Tests.Engine MusicRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var firstDayOfMonth = new DateTime(today.Year, today.Month, 1); var log = new List { diff --git a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs index 082304462..e601ab84d 100644 --- a/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs +++ b/src/Ombi.Core.Tests/Engine/TvRequestLimitsTests.cs @@ -109,7 +109,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = DateTime.UtcNow.AddDays(-1); var log = new List { new RequestLog @@ -142,7 +142,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimit = 2, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -225,7 +225,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var yesterday = new DateTime(2020, 10, 05).AddDays(-1); + var yesterday = new DateTime(2020, 09, 05).AddDays(-1); var log = new List { new RequestLog @@ -258,7 +258,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -292,7 +292,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -333,7 +333,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Day, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -407,7 +407,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -441,7 +441,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -482,7 +482,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Week, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -523,7 +523,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var lastWeek = new DateTime(2020, 10, 05).AddMonths(-1).AddDays(-1); + var lastWeek = new DateTime(2020, 09, 05).AddMonths(-1).AddDays(-1); var log = new List { new RequestLog @@ -556,7 +556,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -590,7 +590,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog @@ -631,7 +631,7 @@ namespace Ombi.Core.Tests.Engine EpisodeRequestLimitType = RequestLimitType.Month, Id = "id1" }; - var today = new DateTime(2020, 10, 05); + var today = DateTime.UtcNow; var log = new List { new RequestLog diff --git a/src/Ombi.Core/Services/RequestLimitService.cs b/src/Ombi.Core/Services/RequestLimitService.cs index 05032f6f3..ab82aa69e 100644 --- a/src/Ombi.Core/Services/RequestLimitService.cs +++ b/src/Ombi.Core/Services/RequestLimitService.cs @@ -153,7 +153,7 @@ namespace Ombi.Core.Services nextRequest = oldestRequestedAt.AddDays(1).Date; break; case RequestLimitType.Week: - var fdow = DateTime.UtcNow.FirstDateInWeek(); + var fdow = DateTime.UtcNow.FirstDateInWeek().Date; count = limit - await log.CountAsync(x => x.RequestDate >= fdow); oldestRequestedAt = await log.Where(x => x.RequestDate >= fdow) .OrderBy(x => x.RequestDate) @@ -262,7 +262,7 @@ namespace Ombi.Core.Services nextRequest = oldestRequestedAt.AddDays(1).Date; break; case RequestLimitType.Week: - var fdow = now.FirstDateInWeek(); + var fdow = now.FirstDateInWeek().Date; filteredLog = log.Where(x => x.RequestDate >= DateTime.UtcNow.Date.AddDays(-7)); // Needed, due to a bug which would cause all episode counts to be 0 zeroEpisodeCount = await filteredLog.Where(x => x.EpisodeCount == 0).Select(x => x.EpisodeCount).CountAsync();