diff --git a/src/Ombi.Core.Tests/Rule/Search/AvailabilityRuleHelperTests.cs b/src/Ombi.Core.Tests/Rule/Search/AvailabilityRuleHelperTests.cs new file mode 100644 index 000000000..7580ed9c8 --- /dev/null +++ b/src/Ombi.Core.Tests/Rule/Search/AvailabilityRuleHelperTests.cs @@ -0,0 +1,201 @@ +using System; +using System.Collections.Generic; +using NUnit.Framework; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Rules.Search; +using Ombi.Store.Repository.Requests; + +namespace Ombi.Core.Tests.Rule.Search +{ + public class AvailabilityRuleHelperTests + { + + + [Test] + public void Is_Available_When_All_We_Have_All_Aired_Episodes() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = true + }, + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(1), // Tomorrow! + Available = false + } + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List { new SeasonRequests { Episodes = episodes } } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.True); + } + + [Test] + public void Is_Available_When_All_We_Have_All_Aired_Episodes_With_Unknown_Dates() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = true + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, // Unknown date! + Available = false + } + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List { new SeasonRequests { Episodes = episodes } } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.True); + } + + [Test] + public void Is_PartlyAvailable_When_All_We_Have_Some_Aired_Episodes() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = true + }, + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-14), // Yesterday + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, // Unknown date! + Available = false + } + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List { new SeasonRequests { Episodes = episodes } } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.False); + Assert.That(model.PartlyAvailable, Is.True); + } + + [Test] + public void Is_SeasonAvailable_When_All_We_Have_All_Aired_Episodes_In_A_Season() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = true + }, + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-14), // Yesterday + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, // Unknown date! + Available = false + } + }; + + var availableEpisodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = true + }, + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List + { + new SeasonRequests { Episodes = episodes }, + new SeasonRequests { Episodes = availableEpisodes }, + } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.False); + Assert.That(model.PartlyAvailable, Is.True); + Assert.That(model.SeasonRequests[1].SeasonAvailable, Is.True); + } + + [Test] + public void Is_NotAvailable_When_All_We_Have_No_Aired_Episodes() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-1), // Yesterday + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.Now.AddDays(-14), + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, // Unknown date! + Available = false + } + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List { new SeasonRequests { Episodes = episodes } } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.False); + Assert.That(model.PartlyAvailable, Is.False); + } + [Test] + public void Is_NotAvailable_When_All_Episodes_Are_Unknown() + { + var episodes = new List + { + new EpisodeRequests + { + AirDate = DateTime.MinValue, + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, + Available = false + }, + new EpisodeRequests + { + AirDate = DateTime.MinValue, // Unknown date! + Available = false + } + }; + + var model = new SearchTvShowViewModel + { + SeasonRequests = new List { new SeasonRequests { Episodes = episodes } } + }; + AvailabilityRuleHelper.CheckForUnairedEpisodes(model); + Assert.That(model.FullyAvailable, Is.False); + Assert.That(model.PartlyAvailable, Is.False); + } + } +} \ No newline at end of file diff --git a/src/Ombi.Core.Tests/Rule/Search/PlexAvailabilityRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/PlexAvailabilityRuleTests.cs deleted file mode 100644 index 5bd35473c..000000000 --- a/src/Ombi.Core.Tests/Rule/Search/PlexAvailabilityRuleTests.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.Threading.Tasks; -using Microsoft.Extensions.Logging; -using Moq; -using NUnit.Framework; -using Ombi.Core.Models.Search; -using Ombi.Core.Rule.Rules.Search; -using Ombi.Store.Entities; -using Ombi.Store.Repository; - -namespace Ombi.Core.Tests.Rule.Search -{ - public class PlexAvailabilityRuleTests - { - [SetUp] - public void Setup() - { - ContextMock = new Mock(); - Rule = new PlexAvailabilityRule(ContextMock.Object, new Mock>().Object); - } - - private PlexAvailabilityRule Rule { get; set; } - private Mock ContextMock { get; set; } - - [Test] - public async Task ShouldBe_Available_WhenFoundInPlex() - { - ContextMock.Setup(x => x.Get(It.IsAny())).ReturnsAsync(new PlexServerContent - { - Url = "TestUrl", - ImdbId = "132" - }); - - var search = new SearchMovieViewModel - { - ImdbId = "123", - }; - var result = await Rule.Execute(search); - - Assert.True(result.Success); - Assert.AreEqual("TestUrl", search.PlexUrl); - Assert.True(search.Available); - } - - [Test] - public async Task ShouldBe_NotAvailable_WhenNotFoundInPlex() - { - ContextMock.Setup(x => x.Get(It.IsAny())).Returns(Task.FromResult(default(PlexServerContent))); - var search = new SearchMovieViewModel(); - var result = await Rule.Execute(search); - - Assert.True(result.Success); - Assert.Null(search.PlexUrl); - Assert.False(search.Available); - } - } -} \ No newline at end of file