mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-13 01:56:55 -07:00
Added happy path tests for the Checker
This commit is contained in:
parent
64125cc44c
commit
d6763bf435
2 changed files with 104 additions and 8 deletions
|
@ -284,8 +284,7 @@ namespace PlexRequests.Services.Tests
|
||||||
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
[Ignore("Need to work out Plex Directory vs Video objects")]
|
public void CheckAndUpdateRequestsThatDoNotExistInPlexTest()
|
||||||
public void CheckAndUpdateRequestsTest()
|
|
||||||
{
|
{
|
||||||
|
|
||||||
var requests = new List<RequestedModel> {
|
var requests = new List<RequestedModel> {
|
||||||
|
@ -315,7 +314,26 @@ namespace PlexRequests.Services.Tests
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var search = new PlexSearch { };
|
var search = new PlexSearch
|
||||||
|
{
|
||||||
|
Video = new List<Video>
|
||||||
|
{
|
||||||
|
new Video
|
||||||
|
{
|
||||||
|
Title = "Title4",
|
||||||
|
Year = "2012"
|
||||||
|
},
|
||||||
|
new Video
|
||||||
|
{
|
||||||
|
Title = "Title2",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Directory = new Directory1
|
||||||
|
{
|
||||||
|
Title = "Title9",
|
||||||
|
Year = "1978"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
var settingsMock = new Mock<ISettingsService<PlexSettings>>();
|
||||||
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
var authMock = new Mock<ISettingsService<AuthenticationSettings>>();
|
||||||
|
@ -324,14 +342,88 @@ namespace PlexRequests.Services.Tests
|
||||||
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "192.168.1.1" });
|
settingsMock.Setup(x => x.GetSettings()).Returns(new PlexSettings { Ip = "192.168.1.1" });
|
||||||
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
authMock.Setup(x => x.GetSettings()).Returns(new AuthenticationSettings { PlexAuthToken = "abc" });
|
||||||
requestMock.Setup(x => x.GetAll()).Returns(requests);
|
requestMock.Setup(x => x.GetAll()).Returns(requests);
|
||||||
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(search);
|
||||||
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
||||||
|
|
||||||
Checker.CheckAndUpdateAll(1);
|
Checker.CheckAndUpdateAll(1);
|
||||||
|
|
||||||
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Never);
|
||||||
requestMock.Verify(x => x.Get(It.IsAny<int>()), 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);
|
plexMock.Verify(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>()), Times.Exactly(3));
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void CheckAndUpdateRequestsAllRequestsTest()
|
||||||
|
{
|
||||||
|
|
||||||
|
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 = "Hi",
|
||||||
|
Available = false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var search = new PlexSearch
|
||||||
|
{
|
||||||
|
Video = new List<Video>
|
||||||
|
{
|
||||||
|
new Video
|
||||||
|
{
|
||||||
|
Title = "title1",
|
||||||
|
Year = "2012"
|
||||||
|
},
|
||||||
|
new Video
|
||||||
|
{
|
||||||
|
Title = "Title3",
|
||||||
|
}
|
||||||
|
,
|
||||||
|
new Video
|
||||||
|
{
|
||||||
|
Title = "Hi",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Directory = new Directory1
|
||||||
|
{
|
||||||
|
Title = "missingTitle",
|
||||||
|
Year = "1978"
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
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);
|
||||||
|
plexMock.Setup(x => x.SearchContent(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<Uri>())).Returns(search);
|
||||||
|
Checker = new PlexAvailabilityChecker(settingsMock.Object, authMock.Object, requestMock.Object, plexMock.Object);
|
||||||
|
|
||||||
|
Checker.CheckAndUpdateAll(1);
|
||||||
|
|
||||||
|
requestMock.Verify(x => x.BatchUpdate(It.IsAny<List<RequestedModel>>()), Times.Once);
|
||||||
|
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.Exactly(4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -66,7 +66,7 @@ namespace PlexRequests.Services
|
||||||
Log.Trace("Getting all the requests");
|
Log.Trace("Getting all the requests");
|
||||||
var requests = RequestService.GetAll();
|
var requests = RequestService.GetAll();
|
||||||
|
|
||||||
var requestedModels = requests as RequestedModel[] ?? requests.ToArray();
|
var requestedModels = requests as RequestedModel[] ?? requests.Where(x => !x.Available).ToArray();
|
||||||
Log.Trace("Requests Count {0}", requestedModels.Length);
|
Log.Trace("Requests Count {0}", requestedModels.Length);
|
||||||
|
|
||||||
if (!ValidateSettings(plexSettings, authSettings) || !requestedModels.Any())
|
if (!ValidateSettings(plexSettings, authSettings) || !requestedModels.Any())
|
||||||
|
@ -107,7 +107,9 @@ namespace PlexRequests.Services
|
||||||
Log.Trace("The result from Plex where the title matches for the video : {0}", videoResult != null);
|
Log.Trace("The result from Plex where the title matches for the video : {0}", videoResult != null);
|
||||||
Log.Trace("The result from Plex where the title matches for the directory : {0}", directoryResult != null);
|
Log.Trace("The result from Plex where the title matches for the directory : {0}", directoryResult != null);
|
||||||
|
|
||||||
if (videoResult != null || directoryResult != null)
|
var directoryResultVal = directoryResult ?? false;
|
||||||
|
|
||||||
|
if (videoResult != null || directoryResultVal)
|
||||||
{
|
{
|
||||||
r.Available = true;
|
r.Available = true;
|
||||||
modifiedModel.Add(r);
|
modifiedModel.Add(r);
|
||||||
|
@ -120,7 +122,9 @@ namespace PlexRequests.Services
|
||||||
Log.Trace("Updating the requests now");
|
Log.Trace("Updating the requests now");
|
||||||
Log.Trace("Requests that will be updates:");
|
Log.Trace("Requests that will be updates:");
|
||||||
Log.Trace(modifiedModel.SelectMany(x => x.Title).DumpJson());
|
Log.Trace(modifiedModel.SelectMany(x => x.Title).DumpJson());
|
||||||
RequestService.BatchUpdate(modifiedModel);
|
|
||||||
|
if(modifiedModel.Any())
|
||||||
|
{ RequestService.BatchUpdate(modifiedModel);}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue