Merge branch 'master' of git://github.com/kayone/NzbDrone

Conflicts:
	NzbDrone.Web/Controllers/AddSeriesController.cs
	NzbDrone.Web/Controllers/SeriesController.cs
pull/7/merge
Mark McDowall 14 years ago
commit 6e5328a877

@ -1,12 +1,15 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
using AutoMoq.Unity;
using Microsoft.Practices.Unity;
using Moq;
using Moq.Language.Flow;
[assembly: InternalsVisibleTo("AutoMoq.Tests")]
namespace AutoMoq
{
public class AutoMoqer
@ -38,18 +41,18 @@ namespace AutoMoq
return TheRegisteredMockForThisType<T>(type);
}
public virtual void SetConstant<T>(T instance) where T : class
{
container.RegisterInstance(instance);
SetMock(instance.GetType(), null);
}
internal virtual void SetMock(Type type, Mock mock)
{
if (registeredMocks.ContainsKey(type) == false)
registeredMocks.Add(type, mock);
}
public virtual void SetConstant<T>(T instance) where T : class
{
container.RegisterInstance(instance);
SetMock(instance.GetType(), null);
}
#region private methods
private void SetupAutoMoqer(IUnityContainer container)

@ -67,8 +67,8 @@ namespace NzbDrone.Core.Test
//Setup
var season = new Mock<ISeasonProvider>();
var series = new Mock<ISeriesProvider>();
var history = new Mock<IHistoryProvider>();
var quality = new Mock<IQualityProvider>();
//var history = new Mock<IHistoryProvider>();
//var quality = new Mock<IQualityProvider>();
var repo = new Mock<IRepository>();
var epInDb = new Episode

@ -9,7 +9,7 @@ namespace Ninject.Moq
/// <summary>
/// Creates mocked instances via Moq.
/// </summary>
public class MockProvider : IProvider
public class MockProvider : IProvider
{
private static readonly Dictionary<Type, ConstructorInjector> _injectors = new Dictionary<Type, ConstructorInjector>();

@ -85,9 +85,13 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="AutoMoq\AutoMoq.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs" />
<Compile Include="AutoMoq\AutoMoqer.cs" />
<Compile Include="AutoMoq\Unity\AutoMockingBuilderStrategy.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="AutoMoq\Unity\AutoMockingContainerExtension.cs">
<SubType>Code</SubType>
</Compile>
<Compile Include="RssProviderTest.cs" />
<Compile Include="HistoryProviderTest.cs" />
<Compile Include="MediaFileProviderTests.cs" />

@ -65,18 +65,16 @@ namespace NzbDrone.Core.Test
[Test]
public void Add_new_series()
{
var repo = MockLib.GetEmptyRepository();
var kernel = new MockingKernel();
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
kernel.Bind<IRepository>().ToConstant(repo);
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
string path = "C:\\Test\\";
int tvDbId = 1234;
int qualityProfileId = 2;
//Act
var seriesProvider = kernel.Get<ISeriesProvider>();
var seriesProvider = mocker.Resolve<SeriesProvider>();
seriesProvider.AddSeries(path, tvDbId, qualityProfileId);
@ -107,24 +105,23 @@ namespace NzbDrone.Core.Test
[Test]
public void Test_is_monitored()
{
var kernel = new MockingKernel();
var repo = MockLib.GetEmptyRepository();
kernel.Bind<IRepository>().ToConstant(repo);
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
var mocker = new AutoMoqer();
repo.Add(Builder<Series>.CreateNew()
mocker.SetConstant(MockLib.GetEmptyRepository());
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
.With(c => c.Monitored = true)
.With(c => c.SeriesId = 12)
.Build());
repo.Add(Builder<Series>.CreateNew()
mocker.Resolve<IRepository>().Add(Builder<Series>.CreateNew()
.With(c => c.Monitored = false)
.With(c => c.SeriesId = 11)
.Build());
//Act, Assert
var provider = kernel.Get<ISeriesProvider>();
var provider = mocker.Resolve<SeriesProvider>();
Assert.IsTrue(provider.IsMonitored(12));
Assert.IsFalse(provider.IsMonitored(11));
Assert.IsFalse(provider.IsMonitored(1));
@ -141,32 +138,31 @@ namespace NzbDrone.Core.Test
[Row(12, QualityTypes.WEBDL, false)]
public void QualityWanted(int seriesId, QualityTypes qualityTypes, Boolean result)
{
var kernel = new MockingKernel();
var repo = MockLib.GetEmptyRepository();
kernel.Bind<IRepository>().ToConstant(repo);
kernel.Bind<ISeriesProvider>().To<SeriesProvider>();
var quality = Builder<QualityProfile>.CreateNew()
.With(q => q.Allowed = new List<QualityTypes>() { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV })
.With(q => q.Cutoff = QualityTypes.DVD)
.Build();
.With(q => q.Allowed = new List<QualityTypes>() { QualityTypes.BDRip, QualityTypes.DVD, QualityTypes.TV })
.With(q => q.Cutoff = QualityTypes.DVD)
.Build();
var qualityProviderMock = new Mock<IQualityProvider>();
qualityProviderMock.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality).Verifiable();
kernel.Bind<IQualityProvider>().ToConstant(qualityProviderMock.Object);
var series = Builder<Series>.CreateNew()
.With(c => c.SeriesId = 12)
.With(c => c.QualityProfileId = quality.QualityProfileId)
.Build();
var mocker = new AutoMoqer();
var emptyRepository = MockLib.GetEmptyRepository();
mocker.SetConstant(emptyRepository);
repo.Add(Builder<Series>.CreateNew()
.With(c => c.SeriesId = 12)
.With(c => c.QualityProfileId = quality.QualityProfileId)
.Build());
//Act
var needed = kernel.Get<ISeriesProvider>().QualityWanted(seriesId, qualityTypes);
mocker.GetMock<QualityProvider>()
.Setup(c => c.Find(quality.QualityProfileId)).Returns(quality);
Assert.AreEqual(result, needed);
emptyRepository.Add(series);
//Act
var needed = mocker.Resolve<SeriesProvider>().QualityWanted(seriesId, qualityTypes);
Assert.AreEqual(result, needed);
}
}
}

@ -4,4 +4,5 @@
<package id="NBuilder" version="2.3.0.0" />
<package id="Moq" version="4.0.10827" />
<package id="Unity" version="2.0" />
<package id="AutoMoq" version="1.3.1.3" />
</packages>

@ -57,17 +57,17 @@ namespace NzbDrone.Core
dbProvider.Log = new NlogWriter();
_kernel.Bind<QualityProvider>().ToSelf();
_kernel.Bind<TvDbProvider>().ToSelf();
_kernel.Bind<HttpProvider>().ToSelf();
_kernel.Bind<ISeriesProvider>().To<SeriesProvider>().InSingletonScope();
_kernel.Bind<IRssSyncProvider>().To<RssSyncProvider>().InSingletonScope();
_kernel.Bind<ISeasonProvider>().To<SeasonProvider>();
_kernel.Bind<IEpisodeProvider>().To<EpisodeProvider>();
_kernel.Bind<IUpcomingEpisodesProvider>().To<UpcomingEpisodesProvider>();
_kernel.Bind<IDiskProvider>().To<DiskProvider>();
_kernel.Bind<TvDbProvider>().To<TvDbProvider>();
_kernel.Bind<IDownloadProvider>().To<SabProvider>();
_kernel.Bind<HttpProvider>().To<HttpProvider>();
_kernel.Bind<IHistoryProvider>().To<HistoryProvider>();
_kernel.Bind<IQualityProvider>().To<QualityProvider>();
_kernel.Bind<IRootDirProvider>().To<RootDirProvider>();
_kernel.Bind<IExtenalNotificationProvider>().To<ExternalNotificationProvider>();
_kernel.Bind<IXbmcProvider>().To<XbmcProvider>();

@ -188,7 +188,6 @@
<Compile Include="Providers\IIndexerProvider.cs" />
<Compile Include="Providers\IndexerProvider.cs" />
<Compile Include="Providers\IPostProcessingProvider.cs" />
<Compile Include="Providers\IQualityProvider.cs" />
<Compile Include="Providers\IRenameProvider.cs" />
<Compile Include="Providers\IRootDirProvider.cs" />
<Compile Include="Providers\IRssSyncProvider.cs" />

@ -18,12 +18,12 @@ namespace NzbDrone.Core.Providers
private readonly ISeasonProvider _seasons;
private readonly TvDbProvider _tvDb;
private readonly IHistoryProvider _history;
private readonly IQualityProvider _quality;
private readonly QualityProvider _quality;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public EpisodeProvider(IRepository sonicRepo, ISeriesProvider seriesProvider,
ISeasonProvider seasonProvider, TvDbProvider tvDbProvider,
IHistoryProvider history, IQualityProvider quality)
IHistoryProvider history, QualityProvider quality)
{
_sonicRepo = sonicRepo;
_series = seriesProvider;

@ -1,17 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NzbDrone.Core.Repository.Quality;
namespace NzbDrone.Core.Providers
{
public interface IQualityProvider
{
void Add(QualityProfile profile);
void Update(QualityProfile profile);
void Delete(int profileId);
List<QualityProfile> GetAllProfiles();
QualityProfile Find(int profileId);
}
}

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using NLog;
@ -8,11 +9,13 @@ using SubSonic.Repository;
namespace NzbDrone.Core.Providers
{
public class QualityProvider : IQualityProvider
public class QualityProvider
{
private IRepository _sonicRepo;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public QualityProvider() { }
public QualityProvider(IRepository sonicRepo)
{
_sonicRepo = sonicRepo;
@ -20,12 +23,12 @@ namespace NzbDrone.Core.Providers
#region IQualityProvider Members
public void Add(QualityProfile profile)
public virtual void Add(QualityProfile profile)
{
_sonicRepo.Add(profile);
}
public void Update(QualityProfile profile)
public virtual void Update(QualityProfile profile)
{
if (!_sonicRepo.Exists<QualityProfile>(q => q.QualityProfileId == profile.QualityProfileId))
{
@ -36,19 +39,19 @@ namespace NzbDrone.Core.Providers
_sonicRepo.Update(profile);
}
public void Delete(int profileId)
public virtual void Delete(int profileId)
{
_sonicRepo.Delete<QualityProfile>(profileId);
}
public List<QualityProfile> GetAllProfiles()
public virtual List<QualityProfile> GetAllProfiles()
{
var profiles = _sonicRepo.All<QualityProfile>().ToList();
return profiles;
}
public QualityProfile Find(int profileId)
public virtual QualityProfile Find(int profileId)
{
return _sonicRepo.Single<QualityProfile>(q => q.QualityProfileId == profileId);
}

@ -22,11 +22,11 @@ namespace NzbDrone.Core.Providers
private readonly IConfigProvider _config;
private readonly IRepository _sonioRepo;
private readonly TvDbProvider _tvDb;
private readonly IQualityProvider _quality;
private readonly QualityProvider _quality;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public SeriesProvider(IConfigProvider configProvider,
IRepository dataRepository, TvDbProvider tvDbProvider, IQualityProvider quality)
IRepository dataRepository, TvDbProvider tvDbProvider, QualityProvider quality)
{
_config = configProvider;
_sonioRepo = dataRepository;

@ -16,12 +16,12 @@ namespace NzbDrone.Web.Controllers
private readonly ISyncProvider _syncProvider;
private readonly IRootDirProvider _rootFolderProvider;
private readonly IConfigProvider _configProvider;
private readonly IQualityProvider _qualityProvider;
private readonly QualityProvider _qualityProvider;
private readonly TvDbProvider _tvDbProvider;
private readonly ISeriesProvider _seriesProvider;
public AddSeriesController(ISyncProvider syncProvider, IRootDirProvider rootFolderProvider, IConfigProvider configProvider,
IQualityProvider qualityProvider, TvDbProvider tvDbProvider, ISeriesProvider seriesProvider)
QualityProvider qualityProvider, TvDbProvider tvDbProvider, ISeriesProvider seriesProvider)
{
ConfigProvider = configProvider;
_syncProvider = syncProvider;

@ -25,23 +25,19 @@ namespace NzbDrone.Web.Controllers
private readonly IEpisodeProvider _episodeProvider;
private readonly ISyncProvider _syncProvider;
private readonly IRssSyncProvider _rssSyncProvider;
private readonly IQualityProvider _qualityProvider;
private readonly QualityProvider _qualityProvider;
private readonly IMediaFileProvider _mediaFileProvider;
private readonly IRenameProvider _renameProvider;
private readonly IRootDirProvider _rootDirProvider;
private readonly TvDbProvider _tvDbProvider;
private readonly IDiskProvider _diskProvider;
private readonly IConfigProvider _configProvider;
//
// GET: /Series/
public SeriesController(ISyncProvider syncProvider, ISeriesProvider seriesProvider,
IEpisodeProvider episodeProvider, IRssSyncProvider rssSyncProvider,
IQualityProvider qualityProvider, IMediaFileProvider mediaFileProvider,
QualityProvider qualityProvider, IMediaFileProvider mediaFileProvider,
IRenameProvider renameProvider, IRootDirProvider rootDirProvider,
TvDbProvider tvDbProvider, IDiskProvider diskProvider,
IConfigProvider configProvider)
TvDbProvider tvDbProvider)
{
_seriesProvider = seriesProvider;
_episodeProvider = episodeProvider;
@ -52,8 +48,6 @@ namespace NzbDrone.Web.Controllers
_renameProvider = renameProvider;
_rootDirProvider = rootDirProvider;
_tvDbProvider = tvDbProvider;
_diskProvider = diskProvider;
_configProvider = configProvider;
}
public ActionResult Index()
@ -62,7 +56,7 @@ namespace NzbDrone.Web.Controllers
return View();
}

@ -21,7 +21,7 @@ namespace NzbDrone.Web.Controllers
{
private IConfigProvider _configProvider;
private IIndexerProvider _indexerProvider;
private IQualityProvider _qualityProvider;
private QualityProvider _qualityProvider;
private IRootDirProvider _rootDirProvider;
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
@ -29,7 +29,7 @@ namespace NzbDrone.Web.Controllers
private const string SETTINGS_FAILED = "Error Saving Settings, please fix any errors";
public SettingsController(IConfigProvider configProvider, IIndexerProvider indexerProvider,
IQualityProvider qualityProvider, IRootDirProvider rootDirProvider)
QualityProvider qualityProvider, IRootDirProvider rootDirProvider)
{
_configProvider = configProvider;
_indexerProvider = indexerProvider;

@ -55,6 +55,7 @@ Global
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x64.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.ActiveCfg = Debug|Any CPU
{43BD3BBD-1531-4D8F-9C08-E1CD544AB2CD}.Debug|x86.Build.0 = Debug|Any CPU

Loading…
Cancel
Save