Sonarr/NzbDrone.Core.Test/CentralDispatchFixture.cs

114 lines
2.9 KiB
C#
Raw Normal View History

2011-07-08 05:41:08 +00:00
using System;
using System.Collections.Generic;
using System.IO;
2011-07-08 05:41:08 +00:00
using System.Linq;
using FluentAssertions;
2011-11-13 07:27:16 +00:00
using NLog;
2011-07-08 05:41:08 +00:00
using NUnit.Framework;
using NzbDrone.Common;
2011-07-08 05:41:08 +00:00
using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Indexer;
using NzbDrone.Core.Providers.Jobs;
using NzbDrone.Core.Test.Framework;
using Ninject;
namespace NzbDrone.Core.Test
{
[TestFixture]
// ReSharper disable InconsistentNaming
2011-11-13 07:27:16 +00:00
class CentralDispatchFixture : CoreTest
2011-07-08 05:41:08 +00: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();
2011-11-08 20:12:54 +00:00
private CentralDispatch centralDispatch;
[SetUp]
public void Setup()
{
centralDispatch = new CentralDispatch();
}
2011-07-08 05:41:08 +00:00
[Test]
public void InitAppTest()
{
2011-11-08 20:12:54 +00:00
centralDispatch.Kernel.Should().NotBeNull();
2011-07-08 05:41:08 +00: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);
2011-11-08 20:12:54 +00:00
centralDispatch.Kernel.Get(provider).Should().NotBeNull();
2011-07-08 05:41:08 +00:00
}
}
[Test]
public void All_jobs_should_be_registered()
{
//Assert
2011-11-08 20:12:54 +00:00
var registeredJobs = centralDispatch.Kernel.GetAll<IJob>();
2011-07-08 05:41:08 +00:00
jobs.Should().NotBeEmpty();
registeredJobs.Should().HaveSameCount(jobs);
}
[Test]
public void All_indexers_should_be_registered()
{
//Assert
2011-11-08 20:12:54 +00:00
var registeredIndexers = centralDispatch.Kernel.GetAll<IndexerBase>();
2011-07-08 05:41:08 +00:00
indexers.Should().NotBeEmpty();
registeredIndexers.Should().HaveSameCount(indexers);
}
[Test]
public void jobs_are_initialized()
{
2011-11-08 20:12:54 +00:00
centralDispatch.Kernel.Get<JobProvider>().All().Should().HaveSameCount(jobs);
2011-07-08 05:41:08 +00:00
}
[Test]
public void indexers_are_initialized()
{
2011-11-08 20:12:54 +00:00
centralDispatch.Kernel.Get<IndexerProvider>().All().Should().HaveSameCount(indexers);
2011-07-08 05:41:08 +00:00
}
[Test]
public void quality_profile_initialized()
{
2011-11-08 20:12:54 +00:00
centralDispatch.Kernel.Get<QualityProvider>().All().Should().HaveCount(2);
2011-07-08 05:41:08 +00:00
}
[Test]
public void JobProvider_should_be_singletone()
{
2011-11-08 20:12:54 +00:00
var first = centralDispatch.Kernel.Get<JobProvider>();
var second = centralDispatch.Kernel.Get<JobProvider>();
first.Should().BeSameAs(second);
}
2011-11-13 07:27:16 +00:00
[TearDown]
public void TearDownBase()
{
WebTimer.Stop();
2011-11-13 18:16:31 +00:00
2011-11-13 07:27:16 +00:00
}
2011-07-08 05:41:08 +00:00
}
}