2011-11-23 08:58:26 +03:00
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
using System;
|
2011-07-08 08:41:08 +03:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2013-01-03 04:09:13 +03:00
|
|
|
using Autofac;
|
2011-07-08 08:41:08 +03:00
|
|
|
using FluentAssertions;
|
|
|
|
using NUnit.Framework;
|
2012-01-25 06:09:49 +03:00
|
|
|
using NzbDrone.Common;
|
2011-12-02 04:33:17 +03:00
|
|
|
using NzbDrone.Core.Jobs;
|
2011-07-08 08:41:08 +03:00
|
|
|
using NzbDrone.Core.Providers;
|
2013-01-03 07:09:37 +03:00
|
|
|
using NzbDrone.Core.Providers.ExternalNotification;
|
2011-07-08 08:41:08 +03:00
|
|
|
using NzbDrone.Core.Providers.Indexer;
|
2013-01-03 07:09:37 +03:00
|
|
|
using NzbDrone.Core.Providers.Metadata;
|
2011-07-08 08:41:08 +03:00
|
|
|
using NzbDrone.Core.Test.Framework;
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Test
|
|
|
|
{
|
|
|
|
[TestFixture]
|
2011-11-13 10:27:16 +03:00
|
|
|
class CentralDispatchFixture : CoreTest
|
2011-07-08 08:41:08 +03:00
|
|
|
{
|
|
|
|
readonly IList<Type> indexers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(IndexerBase))).ToList();
|
|
|
|
readonly IList<Type> jobs = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IJob))).ToList();
|
2013-01-03 07:09:37 +03:00
|
|
|
readonly IList<Type> extNotifications = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(ExternalNotificationBase))).ToList();
|
|
|
|
readonly IList<Type> metadata = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.IsSubclassOf(typeof(MetadataBase))).ToList();
|
2011-07-08 08:41:08 +03:00
|
|
|
|
2013-01-03 04:09:13 +03:00
|
|
|
private IContainer kernel;
|
2011-11-08 23:12:54 +03:00
|
|
|
|
2011-11-17 09:40:54 +03:00
|
|
|
public CentralDispatchFixture()
|
2011-11-08 23:12:54 +03:00
|
|
|
{
|
2011-11-17 09:40:54 +03:00
|
|
|
InitLogging();
|
2013-01-03 04:09:13 +03:00
|
|
|
var dispatch = new CentralDispatch();
|
2013-01-03 06:04:42 +03:00
|
|
|
kernel = dispatch.BuildContainer();
|
2013-01-03 04:09:13 +03:00
|
|
|
|
2011-11-17 09:40:54 +03:00
|
|
|
WebTimer.Stop();
|
2011-11-08 23:12:54 +03:00
|
|
|
}
|
|
|
|
|
2011-07-08 08:41:08 +03:00
|
|
|
[Test]
|
|
|
|
public void InitAppTest()
|
|
|
|
{
|
2011-11-17 09:40:54 +03:00
|
|
|
kernel.Should().NotBeNull();
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void Resolve_all_providers()
|
|
|
|
{
|
|
|
|
var providers = typeof(CentralDispatch).Assembly.GetTypes().Where(t => t.Name.EndsWith("Provider")).ToList();
|
|
|
|
|
|
|
|
providers.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
foreach (var provider in providers)
|
|
|
|
{
|
|
|
|
Console.WriteLine("Resolving " + provider.Name);
|
2013-01-03 04:09:13 +03:00
|
|
|
kernel.Resolve(provider).Should().NotBeNull();
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void All_jobs_should_be_registered()
|
|
|
|
{
|
|
|
|
//Assert
|
|
|
|
|
2013-01-03 04:09:13 +03:00
|
|
|
var registeredJobs = kernel.Resolve<IEnumerable<IJob>>();
|
2011-07-08 08:41:08 +03:00
|
|
|
|
|
|
|
jobs.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
registeredJobs.Should().HaveSameCount(jobs);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void All_indexers_should_be_registered()
|
|
|
|
{
|
|
|
|
//Assert
|
|
|
|
|
2013-01-03 04:09:13 +03:00
|
|
|
var registeredIndexers = kernel.Resolve<IEnumerable<IndexerBase>>();
|
2011-07-08 08:41:08 +03:00
|
|
|
|
|
|
|
indexers.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
registeredIndexers.Should().HaveSameCount(indexers);
|
|
|
|
}
|
|
|
|
|
2013-01-03 07:09:37 +03:00
|
|
|
[Test]
|
|
|
|
public void All_externalNotifiers_should_be_registered()
|
|
|
|
{
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
var externalNotificationBases = kernel.Resolve<IEnumerable<ExternalNotificationBase>>();
|
|
|
|
|
|
|
|
extNotifications.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
externalNotificationBases.Should().HaveSameCount(extNotifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void All_metadata_clients_should_be_registered()
|
|
|
|
{
|
|
|
|
//Assert
|
|
|
|
|
|
|
|
var metadataBases = kernel.Resolve<IEnumerable<MetadataBase>>();
|
|
|
|
|
|
|
|
metadata.Should().NotBeEmpty();
|
|
|
|
|
|
|
|
metadataBases.Should().HaveSameCount(metadata);
|
|
|
|
}
|
2011-07-08 08:41:08 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void jobs_are_initialized()
|
|
|
|
{
|
2013-01-03 04:09:13 +03:00
|
|
|
kernel.Resolve<JobProvider>().All().Should().HaveSameCount(jobs);
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void indexers_are_initialized()
|
|
|
|
{
|
2013-01-03 04:09:13 +03:00
|
|
|
kernel.Resolve<IndexerProvider>().All().Should().HaveSameCount(indexers);
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
|
|
|
|
2013-01-03 07:09:37 +03:00
|
|
|
[Test]
|
|
|
|
public void externalNotifiers_are_initialized()
|
|
|
|
{
|
|
|
|
kernel.Resolve<ExternalNotificationProvider>().All().Should().HaveSameCount(extNotifications);
|
|
|
|
}
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void metadata_clients_are_initialized()
|
|
|
|
{
|
|
|
|
kernel.Resolve<MetadataProvider>().All().Should().HaveSameCount(metadata);
|
|
|
|
}
|
|
|
|
|
2011-07-08 08:41:08 +03:00
|
|
|
[Test]
|
|
|
|
public void quality_profile_initialized()
|
|
|
|
{
|
2013-01-03 04:09:13 +03:00
|
|
|
kernel.Resolve<QualityProvider>().All().Should().HaveCount(2);
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
2011-10-24 00:53:24 +03:00
|
|
|
|
|
|
|
[Test]
|
|
|
|
public void JobProvider_should_be_singletone()
|
|
|
|
{
|
2013-01-03 04:09:13 +03:00
|
|
|
var first = kernel.Resolve<JobProvider>();
|
|
|
|
var second = kernel.Resolve<JobProvider>();
|
2011-10-24 00:53:24 +03:00
|
|
|
|
|
|
|
first.Should().BeSameAs(second);
|
|
|
|
}
|
2011-07-08 08:41:08 +03:00
|
|
|
}
|
2012-08-14 03:05:01 +03:00
|
|
|
}
|