|
|
|
@ -32,12 +32,12 @@ using Moq;
|
|
|
|
|
using NUnit.Framework;
|
|
|
|
|
|
|
|
|
|
using PlexRequests.Api.Interfaces;
|
|
|
|
|
using PlexRequests.Api.Models;
|
|
|
|
|
using PlexRequests.Api.Models.Plex;
|
|
|
|
|
using PlexRequests.Core;
|
|
|
|
|
using PlexRequests.Core.SettingModels;
|
|
|
|
|
using PlexRequests.Helpers.Exceptions;
|
|
|
|
|
using PlexRequests.Services.Interfaces;
|
|
|
|
|
using PlexRequests.Store;
|
|
|
|
|
|
|
|
|
|
namespace PlexRequests.Services.Tests
|
|
|
|
|
{
|
|
|
|
@ -66,7 +66,7 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch {Video = new List<Video> {new Video {Title = "title", Year = "2011"} } };
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "title", Year = "2011" } } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
@ -87,7 +87,7 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Directory = new Directory1 {Title = "title", Year = "2013"} };
|
|
|
|
|
var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title", Year = "2013" } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
@ -100,6 +100,27 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
Assert.That(result, Is.True);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsAvailableDirectoryTitleWithoutYearTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Directory = new Directory1 { Title = "title", } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(searchResult);
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
var result = Checker.IsAvailable("title", null);
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.True);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsNotAvailableTest()
|
|
|
|
|
{
|
|
|
|
@ -108,7 +129,7 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "wrong tistle", Year = "2011"} } };
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "wrong title", Year = "2011" } } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
@ -121,6 +142,27 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
Assert.That(result, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsNotAvailableTestWihtoutYear()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "wrong title" } } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(searchResult);
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
var result = Checker.IsAvailable("title", null);
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void IsYearDoesNotMatchTest()
|
|
|
|
|
{
|
|
|
|
@ -141,5 +183,155 @@ namespace PlexRequests.Services.Tests
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TitleDoesNotMatchTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "title23", Year = "2019" } } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(searchResult);
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
var result = Checker.IsAvailable("title", "2019");
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TitleDoesNotMatchWithoutYearTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
|
|
|
|
|
var searchResult = new PlexSearch { Video = new List<Video> { new Video { Title = "title23" } } };
|
|
|
|
|
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "abc" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(searchResult);
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
var result = Checker.IsAvailable("title", null);
|
|
|
|
|
|
|
|
|
|
Assert.That(result, Is.False);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CheckAndUpdateNoPlexSettingsTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
Checker.CheckAndUpdateAll(1);
|
|
|
|
|
|
|
|
|
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
|
|
|
|
requestMock.Verify(x => x.Get(It.IsAny<int>()), Times.Never);
|
|
|
|
|
plexMock.Verify(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CheckAndUpdateNoAuthSettingsTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "123" });
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
Checker.CheckAndUpdateAll(1);
|
|
|
|
|
|
|
|
|
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
|
|
|
|
requestMock.Verify(x => x.Get(It.IsAny<int>()), Times.Never);
|
|
|
|
|
plexMock.Verify(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void CheckAndUpdateNoRequestsTest()
|
|
|
|
|
{
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "192.168.1.1" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
requestMock.Setup(x => x.GetAll()).Returns(new List<RequestedModel>());
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
Checker.CheckAndUpdateAll(1);
|
|
|
|
|
|
|
|
|
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
|
|
|
|
requestMock.Verify(x => x.Get(It.IsAny<int>()), Times.Never);
|
|
|
|
|
plexMock.Verify(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
[Ignore("Need to work out Plex Directory vs Video objects")]
|
|
|
|
|
public void CheckAndUpdateRequestsTest()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var requests = new List<RequestedModel> {
|
|
|
|
|
new RequestedModel
|
|
|
|
|
{
|
|
|
|
|
Id = 123,
|
|
|
|
|
Title = "title1",
|
|
|
|
|
Available = false,
|
|
|
|
|
},
|
|
|
|
|
new RequestedModel
|
|
|
|
|
{
|
|
|
|
|
Id=222,
|
|
|
|
|
Title = "title3",
|
|
|
|
|
Available = false
|
|
|
|
|
},
|
|
|
|
|
new RequestedModel
|
|
|
|
|
{
|
|
|
|
|
Id = 333,
|
|
|
|
|
Title= "missingTitle",
|
|
|
|
|
Available = false
|
|
|
|
|
},
|
|
|
|
|
new RequestedModel
|
|
|
|
|
{
|
|
|
|
|
Id= 444,
|
|
|
|
|
Title = "already found",
|
|
|
|
|
Available = true
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var search = new PlexSearch { };
|
|
|
|
|
|
|
|
|
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
|
|
|
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
|
|
|
|
var requestMock = new Mock<IRequestService>();
|
|
|
|
|
var plexMock = new Mock<IPlexApi>();
|
|
|
|
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "192.168.1.1" });
|
|
|
|
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
|
|
|
|
requestMock.Setup(x => x.GetAll()).Returns(requests);
|
|
|
|
|
|
|
|
|
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
|
|
|
|
|
|
|
|
|
Checker.CheckAndUpdateAll(1);
|
|
|
|
|
|
|
|
|
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
|
|
|
|
requestMock.Verify(x => x.Get(It.IsAny<int>()), Times.Never);
|
|
|
|
|
plexMock.Verify(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Never);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|