failed attempt to write a test for Series Controller
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Moq;
|
||||
using NzbDrone.Core.Controllers;
|
||||
|
||||
namespace NzbDrone.Core.Test
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides the standard Mocks needed for a typical test
|
||||
/// </summary>
|
||||
static class MockLib
|
||||
{
|
||||
public static string[] StandardSeries
|
||||
{
|
||||
get { return new string[] { "C:\\TV\\The Simpsons", "C:\\TV\\Family Guy" }; }
|
||||
}
|
||||
|
||||
|
||||
public static IConfigController StandardConfig
|
||||
{
|
||||
get
|
||||
{
|
||||
var mock = new Mock<IConfigController>();
|
||||
mock.SetupGet(c => c.SeriesRoot).Returns("C:\\");
|
||||
return mock.Object;
|
||||
}
|
||||
}
|
||||
|
||||
public static IDiskController StandardDisk
|
||||
{
|
||||
get
|
||||
{
|
||||
var mock = new Mock<IDiskController>();
|
||||
mock.Setup(c => c.GetDirectories(It.IsAny<String>())).Returns(StandardSeries);
|
||||
mock.Setup(c => c.Exists(It.Is<String>(d => StandardSeries.Contains(d)))).Returns(true);
|
||||
return mock.Object;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,6 +67,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="DbConfigControllerTest.cs" />
|
||||
<Compile Include="MockLib.cs" />
|
||||
<Compile Include="Ninject.Moq\ExtensionsForBindingSyntax.cs" />
|
||||
<Compile Include="Ninject.Moq\MockingKernel.cs" />
|
||||
<Compile Include="Ninject.Moq\MockProvider.cs" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using FizzWare.NBuilder;
|
||||
using Gallio.Framework;
|
||||
@@ -21,6 +22,7 @@ namespace NzbDrone.Core.Test
|
||||
public class SeriesTest
|
||||
{
|
||||
[Test]
|
||||
[Ignore("Can't get it to work")]
|
||||
[Description("This test will confirm that a folder will be skipped if it has been resolved to a series already assigned to another folder")]
|
||||
public void skip_same_series_diffrent_folder()
|
||||
{
|
||||
@@ -35,21 +37,34 @@ namespace NzbDrone.Core.Test
|
||||
.With(f => f.TvdbId = tvDbId.ToString())
|
||||
.Build();
|
||||
|
||||
moqData.Setup(f => f.Single<Series>(tvDbId)).
|
||||
Returns(fakeSeries);
|
||||
moqData.Setup(f => f.Exists<Series>(c => c.TvdbId == tvDbId.ToString())).
|
||||
Returns(true);
|
||||
|
||||
//setup tvdb to return the same show,
|
||||
IList<TvdbSearchResult> fakeSearchResult = Builder<TvdbSearchResult>.CreateListOfSize(4).WhereTheFirst(1).Has(f => f.Id = tvDbId).Build();
|
||||
|
||||
TvdbSeries fakeTvDbSeries = Builder<TvdbSeries>.CreateNew()
|
||||
.With(f => f.Id = tvDbId)
|
||||
.Build();
|
||||
|
||||
moqTvdb.Setup(f => f.GetSeries(It.IsAny<int>(), It.IsAny<TvdbLanguage>())).Returns(fakeTvDbSeries);
|
||||
moqTvdb.Setup(f => f.SearchSeries(It.IsAny<string>())).
|
||||
Returns(fakeSearchResult);
|
||||
Returns(fakeSearchResult);
|
||||
|
||||
var kernel = new MockingKernel();
|
||||
kernel.Bind<IRepository>().ToConstant(moqData.Object);
|
||||
kernel.Bind<ITvDbController>().ToConstant(moqTvdb.Object);
|
||||
kernel.Bind<IConfigController>().ToConstant(MockLib.StandardConfig);
|
||||
kernel.Bind<IDiskController>().ToConstant(MockLib.StandardDisk);
|
||||
kernel.Bind<ISeriesController>().To<SeriesController>();
|
||||
|
||||
|
||||
//Act
|
||||
var seriesController = kernel.Get<ISeriesController>();
|
||||
seriesController.a
|
||||
seriesController.SyncSeriesWithDisk();
|
||||
|
||||
//Assert
|
||||
//Verify that the show was added to the database only once.
|
||||
moqData.Verify(c => c.Add(It.IsAny<Series>()), Times.Once());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user