Added unit tests to cover the episode and season availablility checks

pull/3895/head
Jamie Rees 6 years ago
parent 01eb74d90b
commit 5aeb0734b2

@ -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<EpisodeRequests>
{
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<SeasonRequests> { 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<EpisodeRequests>
{
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<SeasonRequests> { 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<EpisodeRequests>
{
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<SeasonRequests> { 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<EpisodeRequests>
{
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<EpisodeRequests>
{
new EpisodeRequests
{
AirDate = DateTime.Now.AddDays(-1), // Yesterday
Available = true
},
};
var model = new SearchTvShowViewModel
{
SeasonRequests = new List<SeasonRequests>
{
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<EpisodeRequests>
{
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<SeasonRequests> { 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<EpisodeRequests>
{
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<SeasonRequests> { new SeasonRequests { Episodes = episodes } }
};
AvailabilityRuleHelper.CheckForUnairedEpisodes(model);
Assert.That(model.FullyAvailable, Is.False);
Assert.That(model.PartlyAvailable, Is.False);
}
}
}

@ -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<IPlexContentRepository>();
Rule = new PlexAvailabilityRule(ContextMock.Object, new Mock<ILogger<PlexAvailabilityRule>>().Object);
}
private PlexAvailabilityRule Rule { get; set; }
private Mock<IPlexContentRepository> ContextMock { get; set; }
[Test]
public async Task ShouldBe_Available_WhenFoundInPlex()
{
ContextMock.Setup(x => x.Get(It.IsAny<string>())).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<string>())).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);
}
}
}
Loading…
Cancel
Save