diff --git a/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs index ed3e60631..132f51e49 100644 --- a/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs +++ b/src/Ombi.Core.Tests/Rule/Search/EmbyAvailabilityRuleTests.cs @@ -115,107 +115,4 @@ namespace Ombi.Core.Tests.Rule.Search Assert.False(search.Available); } } - - public class JellyfinAvailabilityRuleTests - { - [SetUp] - public void Setup() - { - ContextMock = new Mock(); - SettingsMock = new Mock>(); - Rule = new JellyfinAvailabilityRule(ContextMock.Object, SettingsMock.Object); - } - - private JellyfinAvailabilityRule Rule { get; set; } - private Mock ContextMock { get; set; } - private Mock> SettingsMock { get; set; } - - [Test] - public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin() - { - SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings()); - ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent - { - ProviderId = "123" - }); - var search = new SearchMovieViewModel() - { - TheMovieDbId = "123", - }; - var result = await Rule.Execute(search); - - Assert.True(result.Success); - Assert.True(search.Available); - } - - [Test] - public async Task Movie_Has_Custom_Url_When_Specified_In_Settings() - { - SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings - { - Enable = true, - Servers = new List - { - new JellyfinServers - { - ServerHostname = "http://test.com/", - ServerId = "8" - } - } - }); - ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent - { - ProviderId = "123", - JellyfinId = 1.ToString(), - }); - var search = new SearchMovieViewModel() - { - TheMovieDbId = "123", - }; - var result = await Rule.Execute(search); - - Assert.True(result.Success); - Assert.That(search.JellyfinUrl, Is.EqualTo("http://test.com/web/index.html#!/item?id=1&serverId=8")); - } - - [Test] - public async Task Movie_Uses_Default_Url_When() - { - SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings - { - Enable = true, - Servers = new List - { - new JellyfinServers - { - ServerHostname = string.Empty, - ServerId = "8" - } - } - }); - ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent - { - ProviderId = "123", - JellyfinId = 1.ToString() - }); - var search = new SearchMovieViewModel() - { - TheMovieDbId = "123", - }; - var result = await Rule.Execute(search); - - Assert.True(result.Success); - } - - [Test] - public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInJellyfin() - { - ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).Returns(Task.FromResult(default(JellyfinContent))); - var search = new SearchMovieViewModel(); - var result = await Rule.Execute(search); - - Assert.True(result.Success); - Assert.False(search.Available); - } - } } diff --git a/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs b/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs new file mode 100644 index 000000000..5da69a181 --- /dev/null +++ b/src/Ombi.Core.Tests/Rule/Search/JellyfinAvailabilityRuleTests.cs @@ -0,0 +1,117 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Moq; +using NUnit.Framework; +using Ombi.Core.Models.Search; +using Ombi.Core.Rule.Rules.Search; +using Ombi.Core.Settings; +using Ombi.Core.Settings.Models.External; +using Ombi.Store.Entities; +using Ombi.Store.Repository; +using Ombi.Store.Repository.Requests; + +namespace Ombi.Core.Tests.Rule.Search +{ + public class JellyfinAvailabilityRuleTests + { + [SetUp] + public void Setup() + { + ContextMock = new Mock(); + SettingsMock = new Mock>(); + Rule = new JellyfinAvailabilityRule(ContextMock.Object, SettingsMock.Object); + } + + private JellyfinAvailabilityRule Rule { get; set; } + private Mock ContextMock { get; set; } + private Mock> SettingsMock { get; set; } + + [Test] + public async Task Movie_ShouldBe_Available_WhenFoundInJellyfin() + { + SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings()); + ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent + { + ProviderId = "123" + }); + var search = new SearchMovieViewModel() + { + TheMovieDbId = "123", + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.True(search.Available); + } + + [Test] + public async Task Movie_Has_Custom_Url_When_Specified_In_Settings() + { + SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings + { + Enable = true, + Servers = new List + { + new JellyfinServers + { + ServerHostname = "http://test.com/", + ServerId = "8" + } + } + }); + ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent + { + ProviderId = "123", + JellyfinId = 1.ToString(), + }); + var search = new SearchMovieViewModel() + { + TheMovieDbId = "123", + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.That(search.JellyfinUrl, Is.EqualTo("http://test.com/web/index.html#!/details?id=1&serverId=8")); + } + + [Test] + public async Task Movie_Uses_Default_Url_When() + { + SettingsMock.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new JellyfinSettings + { + Enable = true, + Servers = new List + { + new JellyfinServers + { + ServerHostname = string.Empty, + ServerId = "8" + } + } + }); + ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).ReturnsAsync(new JellyfinContent + { + ProviderId = "123", + JellyfinId = 1.ToString() + }); + var search = new SearchMovieViewModel() + { + TheMovieDbId = "123", + }; + var result = await Rule.Execute(search); + + Assert.True(result.Success); + } + + [Test] + public async Task Movie_ShouldBe_NotAvailable_WhenNotFoundInJellyfin() + { + ContextMock.Setup(x => x.GetByTheMovieDbId(It.IsAny())).Returns(Task.FromResult(default(JellyfinContent))); + var search = new SearchMovieViewModel(); + var result = await Rule.Execute(search); + + Assert.True(result.Success); + Assert.False(search.Available); + } + } +} diff --git a/src/Ombi.Helpers.Tests/JellyfinHelperTests.cs b/src/Ombi.Helpers.Tests/JellyfinHelperTests.cs index e2c235443..df3f960d4 100644 --- a/src/Ombi.Helpers.Tests/JellyfinHelperTests.cs +++ b/src/Ombi.Helpers.Tests/JellyfinHelperTests.cs @@ -6,7 +6,7 @@ using System.Text; namespace Ombi.Helpers.Tests { [TestFixture] - public class EmbyHelperTests + public class JellyfinHelperTests { [TestCaseSource(nameof(UrlData))] public string TestUrl(string mediaId, string url, string serverId) @@ -20,9 +20,9 @@ namespace Ombi.Helpers.Tests get { var mediaId = 1; - yield return new TestCaseData(mediaId.ToString(), "http://google.com", "1").Returns($"http://google.com/web/index.html#!/item?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain_WithoutTrailingSlash"); - yield return new TestCaseData(mediaId.ToString(), "http://google.com/", "1").Returns($"http://google.com/web/index.html#!/item?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain"); - yield return new TestCaseData(mediaId.ToString(), "https://google.com/", "1").Returns($"https://google.com/web/index.html#!/item?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain_Https"); + yield return new TestCaseData(mediaId.ToString(), "http://google.com", "1").Returns($"http://google.com/web/index.html#!/details?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain_WithoutTrailingSlash"); + yield return new TestCaseData(mediaId.ToString(), "http://google.com/", "1").Returns($"http://google.com/web/index.html#!/details?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain"); + yield return new TestCaseData(mediaId.ToString(), "https://google.com/", "1").Returns($"https://google.com/web/index.html#!/details?id={mediaId}&serverId=1").SetName("JellyfinHelper_GetMediaUrl_WithCustomDomain_Https"); } } } diff --git a/src/Ombi.Test.Common/MockHelper.cs b/src/Ombi.Test.Common/MockHelper.cs index 00e327abc..8d3f5ce8d 100644 --- a/src/Ombi.Test.Common/MockHelper.cs +++ b/src/Ombi.Test.Common/MockHelper.cs @@ -14,7 +14,7 @@ namespace Ombi.Test.Common { var store = new Mock>(); //var u = new OmbiUserManager(store.Object, null, null, null, null, null, null, null, null,null,null,null,null) - var mgr = new Mock(store.Object, null, null, null, null, null, null, null, null, null, null, null, null); + var mgr = new Mock(store.Object, null, null, null, null, null, null, null, null, null, null, null, null, null, null); mgr.Object.UserValidators.Add(new UserValidator()); mgr.Object.PasswordValidators.Add(new PasswordValidator());