mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-27 01:57:21 +00:00
UpcomingEpisodesProvider moved to PetaPoco.
MigrationHelper won't run Subsonic Migrations now.
This commit is contained in:
parent
446a939f45
commit
335639fabc
4 changed files with 163 additions and 13 deletions
|
@ -91,6 +91,7 @@
|
||||||
</Reference>
|
</Reference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Compile Include="UpcomingEpisodesProviderTest.cs" />
|
||||||
<Compile Include="MediaFileProvider_ImportNewDownloadTest.cs" />
|
<Compile Include="MediaFileProvider_ImportNewDownloadTest.cs" />
|
||||||
<Compile Include="MediaFileProvider_GetNewFilenameTest.cs" />
|
<Compile Include="MediaFileProvider_GetNewFilenameTest.cs" />
|
||||||
<Compile Include="dbBenchmark.cs" />
|
<Compile Include="dbBenchmark.cs" />
|
||||||
|
|
151
NzbDrone.Core.Test/UpcomingEpisodesProviderTest.cs
Normal file
151
NzbDrone.Core.Test/UpcomingEpisodesProviderTest.cs
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
// ReSharper disable RedundantUsingDirective
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using AutoMoq;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
|
using FluentAssertions;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Providers;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
|
using NzbDrone.Core.Repository.Quality;
|
||||||
|
using NzbDrone.Core.Test.Framework;
|
||||||
|
|
||||||
|
namespace NzbDrone.Core.Test
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
// ReSharper disable InconsistentNaming
|
||||||
|
public class UpcomingEpisodesProviderTest : TestBase
|
||||||
|
{
|
||||||
|
private Episode yesterday;
|
||||||
|
private Episode today;
|
||||||
|
private Episode tomorrow;
|
||||||
|
private Episode twoDays;
|
||||||
|
private Episode sevenDays;
|
||||||
|
private Episode eightDays;
|
||||||
|
|
||||||
|
[SetUp]
|
||||||
|
public new void Setup()
|
||||||
|
{
|
||||||
|
yesterday = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today.AddDays(-1))
|
||||||
|
.With(c => c.Title = "Yesterday")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
today = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today)
|
||||||
|
.With(c => c.Title = "Today")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
tomorrow = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today.AddDays(1))
|
||||||
|
.With(c => c.Title = "Tomorrow")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
twoDays = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today.AddDays(2))
|
||||||
|
.With(c => c.Title = "Two Days")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
sevenDays = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today.AddDays(7))
|
||||||
|
.With(c => c.Title = "Seven Days")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
sevenDays = Builder<Episode>.CreateNew()
|
||||||
|
.With(c => c.AirDate = DateTime.Today.AddDays(8))
|
||||||
|
.With(c => c.Title = "Eight Days")
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
base.Setup();
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Get_Yesterday()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var database = MockLib.GetEmptyDatabase();
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
mocker.SetConstant(database);
|
||||||
|
|
||||||
|
database.Insert(yesterday);
|
||||||
|
database.Insert(today);
|
||||||
|
database.Insert(tomorrow);
|
||||||
|
database.Insert(twoDays);
|
||||||
|
database.Insert(sevenDays);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Yesterday();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.AreEqual(1, result.Count);
|
||||||
|
Assert.AreEqual(yesterday.Title, result[0].Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Get_Today()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var database = MockLib.GetEmptyDatabase();
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
mocker.SetConstant(database);
|
||||||
|
|
||||||
|
database.Insert(yesterday);
|
||||||
|
database.Insert(today);
|
||||||
|
database.Insert(tomorrow);
|
||||||
|
database.Insert(twoDays);
|
||||||
|
database.Insert(sevenDays);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Today();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.AreEqual(1, result.Count);
|
||||||
|
Assert.AreEqual(today.Title, result[0].Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Get_Tomorrow()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var database = MockLib.GetEmptyDatabase();
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
mocker.SetConstant(database);
|
||||||
|
|
||||||
|
database.Insert(yesterday);
|
||||||
|
database.Insert(today);
|
||||||
|
database.Insert(tomorrow);
|
||||||
|
database.Insert(twoDays);
|
||||||
|
database.Insert(sevenDays);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Tomorrow();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.AreEqual(1, result.Count);
|
||||||
|
Assert.AreEqual(tomorrow.Title, result[0].Title);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void Get_Week()
|
||||||
|
{
|
||||||
|
//Setup
|
||||||
|
var database = MockLib.GetEmptyDatabase();
|
||||||
|
var mocker = new AutoMoqer();
|
||||||
|
mocker.SetConstant(database);
|
||||||
|
|
||||||
|
database.Insert(yesterday);
|
||||||
|
database.Insert(today);
|
||||||
|
database.Insert(tomorrow);
|
||||||
|
database.Insert(twoDays);
|
||||||
|
database.Insert(sevenDays);
|
||||||
|
|
||||||
|
//Act
|
||||||
|
var result = mocker.Resolve<UpcomingEpisodesProvider>().Week();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
Assert.AreEqual(2, result.Count);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -40,7 +40,7 @@ public static void Run(string connetionString, bool trace)
|
||||||
|
|
||||||
migrator.MigrateToLastVersion();
|
migrator.MigrateToLastVersion();
|
||||||
|
|
||||||
ForceSubSonicMigration(Connection.CreateSimpleRepository(connetionString));
|
//ForceSubSonicMigration(Connection.CreateSimpleRepository(connetionString));
|
||||||
|
|
||||||
Logger.Info("Database migration completed");
|
Logger.Info("Database migration completed");
|
||||||
|
|
||||||
|
|
|
@ -4,25 +4,25 @@
|
||||||
using Ninject;
|
using Ninject;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
using NzbDrone.Core.Repository;
|
using NzbDrone.Core.Repository;
|
||||||
|
using PetaPoco;
|
||||||
using SubSonic.Repository;
|
using SubSonic.Repository;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Providers
|
namespace NzbDrone.Core.Providers
|
||||||
{
|
{
|
||||||
public class UpcomingEpisodesProvider
|
public class UpcomingEpisodesProvider
|
||||||
{
|
{
|
||||||
private readonly IRepository _repository;
|
private readonly IDatabase _database;
|
||||||
|
|
||||||
[Inject]
|
[Inject]
|
||||||
public UpcomingEpisodesProvider(IRepository repository)
|
public UpcomingEpisodesProvider(IDatabase database)
|
||||||
{
|
{
|
||||||
_repository = repository;
|
_database = database;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual UpcomingEpisodesModel Upcoming()
|
public virtual UpcomingEpisodesModel Upcoming()
|
||||||
{
|
{
|
||||||
var allEps =
|
var allEps = _database.Fetch<Episode>("WHERE AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(-1),
|
||||||
_repository.All<Episode>().Where(
|
DateTime.Today.AddDays(8));
|
||||||
e => e.AirDate >= DateTime.Today.AddDays(-1) && e.AirDate < DateTime.Today.AddDays(8));
|
|
||||||
|
|
||||||
var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
|
var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
|
||||||
var today = allEps.Where(e => e.AirDate == DateTime.Today).ToList();
|
var today = allEps.Where(e => e.AirDate == DateTime.Today).ToList();
|
||||||
|
@ -33,24 +33,22 @@ public virtual UpcomingEpisodesModel Upcoming()
|
||||||
|
|
||||||
public virtual List<Episode> Yesterday()
|
public virtual List<Episode> Yesterday()
|
||||||
{
|
{
|
||||||
return _repository.All<Episode>().Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
|
return _database.Fetch<Episode>("WHERE AirDate = @0", DateTime.Today.AddDays(-1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<Episode> Today()
|
public virtual List<Episode> Today()
|
||||||
{
|
{
|
||||||
return _repository.All<Episode>().Where(e => e.AirDate == DateTime.Today).ToList();
|
return _database.Fetch<Episode>("WHERE AirDate = @0", DateTime.Today);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<Episode> Tomorrow()
|
public virtual List<Episode> Tomorrow()
|
||||||
{
|
{
|
||||||
return _repository.All<Episode>().Where(e => e.AirDate == DateTime.Today.AddDays(1)).ToList();
|
return _database.Fetch<Episode>("WHERE AirDate = @0", DateTime.Today.AddDays(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual List<Episode> Week()
|
public virtual List<Episode> Week()
|
||||||
{
|
{
|
||||||
return
|
return _database.Fetch<Episode>("WHERE AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(2), DateTime.Today.AddDays(8));
|
||||||
_repository.All<Episode>().Where(e => e.AirDate > DateTime.Today.AddDays(1) && e.AirDate < DateTime.Today.AddDays(8))
|
|
||||||
.ToList();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue