1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-11-25 20:22:37 +01:00

UpcomingEpisodesProvider moved to PetaPoco.

MigrationHelper won't run Subsonic Migrations now.
This commit is contained in:
Mark McDowall 2011-06-17 16:01:09 -07:00
parent 446a939f45
commit 335639fabc
4 changed files with 163 additions and 13 deletions

View File

@ -91,6 +91,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="UpcomingEpisodesProviderTest.cs" />
<Compile Include="MediaFileProvider_ImportNewDownloadTest.cs" />
<Compile Include="MediaFileProvider_GetNewFilenameTest.cs" />
<Compile Include="dbBenchmark.cs" />

View 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);
}
}
}

View File

@ -40,7 +40,7 @@ namespace NzbDrone.Core.Datastore
migrator.MigrateToLastVersion();
ForceSubSonicMigration(Connection.CreateSimpleRepository(connetionString));
//ForceSubSonicMigration(Connection.CreateSimpleRepository(connetionString));
Logger.Info("Database migration completed");

View File

@ -4,25 +4,25 @@ using System.Linq;
using Ninject;
using NzbDrone.Core.Model;
using NzbDrone.Core.Repository;
using PetaPoco;
using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class UpcomingEpisodesProvider
{
private readonly IRepository _repository;
private readonly IDatabase _database;
[Inject]
public UpcomingEpisodesProvider(IRepository repository)
public UpcomingEpisodesProvider(IDatabase database)
{
_repository = repository;
_database = database;
}
public virtual UpcomingEpisodesModel Upcoming()
{
var allEps =
_repository.All<Episode>().Where(
e => e.AirDate >= DateTime.Today.AddDays(-1) && e.AirDate < DateTime.Today.AddDays(8));
var allEps = _database.Fetch<Episode>("WHERE AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(-1),
DateTime.Today.AddDays(8));
var yesterday = allEps.Where(e => e.AirDate == DateTime.Today.AddDays(-1)).ToList();
var today = allEps.Where(e => e.AirDate == DateTime.Today).ToList();
@ -33,24 +33,22 @@ namespace NzbDrone.Core.Providers
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()
{
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()
{
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()
{
return
_repository.All<Episode>().Where(e => e.AirDate > DateTime.Today.AddDays(1) && e.AirDate < DateTime.Today.AddDays(8))
.ToList();
return _database.Fetch<Episode>("WHERE AirDate BETWEEN @0 AND @1", DateTime.Today.AddDays(2), DateTime.Today.AddDays(8));
}
}
}