Fixed up tests

pull/4/head
Mark McDowall 12 years ago
parent a4dde81ceb
commit aa282fbd4d

@ -61,6 +61,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigFileProviderTest.cs" />
<Compile Include="ReflectionExtensions.cs" />
<Compile Include="ReportingService_ReportParseError_Fixture.cs" />
<Compile Include="PathExtentionFixture.cs" />
<Compile Include="DiskProviderFixture.cs" />

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Common.Test
{
public static class ReflectionExtensions
{
public static T GetPropertyValue<T>(this object obj, string propertyName)
{
return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null);
}
}
}

@ -12,6 +12,7 @@ using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
@ -65,23 +66,19 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.Series = series)
.Build();
WithStrictMocker();
WithEnableBacklogSearching();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, new { EpisodeId = 1 }));
.Setup(s => s.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") == 1)));
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
Times.Never());
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }),
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
Times.Once());
}
@ -101,23 +98,16 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.Series = series)
.Build();
WithStrictMocker();
WithEnableBacklogSearching();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, new { EpisodeId = It.IsAny<int>()})).Verifiable();
//Act
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
Times.Never());
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = 0 }),
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
Times.Exactly(episodes.Count));
}
@ -138,15 +128,11 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.SeasonNumber = 1)
.Build();
WithStrictMocker();
WithEnableBacklogSearching();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, new { EpisodeId = It.IsAny<int>() })).Verifiable();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 });
@ -154,10 +140,7 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
Times.Never());
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }),
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
Times.Exactly(episodes.Count));
}
@ -179,15 +162,11 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.SeasonNumber = 1)
.Build();
WithStrictMocker();
WithEnableBacklogSearching();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<SeasonSearchJob>()
.Setup(s => s.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() })).Verifiable();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList());
@ -195,11 +174,9 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0 &&
d.GetPropertyValue<int>("SeasonNumber") >= 0)),
Times.Once());
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }),
Times.Never());
}
[Test]
@ -227,18 +204,11 @@ namespace NzbDrone.Core.Test.JobTests
.With(e => e.Series = series2)
.Build();
WithStrictMocker();
WithEnableBacklogSearching();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<SeasonSearchJob>()
.Setup(s => s.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() })).Verifiable();
Mocker.GetMock<EpisodeSearchJob>()
.Setup(s => s.Start(notification, new { EpisodeId = It.IsAny<int>() })).Verifiable();
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List<int> { 1, 2, 3, 4, 5 });
@ -246,10 +216,11 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<BacklogSearchJob>().Start(notification, null);
//Assert
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = It.IsAny<int>() }),
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0 &&
d.GetPropertyValue<int>("SeasonNumber") >= 0)),
Times.Once());
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny<int>() }),
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
Times.Exactly(5));
}

@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.GetMock<SeriesProvider>().Setup(s => s.GetSeries(series.SeriesId))
.Returns(series);
Mocker.Resolve<BannerDownloadJob>().Start(_notification, new { SeriesId = 0 });
Mocker.Resolve<BannerDownloadJob>().Start(_notification, new { SeriesId = series.SeriesId });
VerifyDownloadMock(1);
}
}

@ -21,7 +21,7 @@ namespace NzbDrone.Core.Test.JobTests
public class ImportNewSeriesJobTest : CoreTest
{
[Test]
public void import_new_series_succesfull()
public void import_new_series_succesful()
{
var series = Builder<Series>.CreateListOfSize(2)
.All().With(s => s.LastInfoSync = null)
@ -39,23 +39,23 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0}))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
.Callback(() => series[0].LastDiskSync = DateTime.Now);
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
.Callback(() => series[1].LastDiskSync = DateTime.Now);
Mocker.GetMock<BannerDownloadJob>()
.Setup(j => j.Start(notification, new { SeriesId = It.IsAny<int>(), SeasonNumber = 0 }));
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") >= 0)));
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
.Callback(() => series[0].LastInfoSync = DateTime.Now);
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
.Callback(() => series[1].LastInfoSync = DateTime.Now);
Mocker.GetMock<SeriesProvider>()
@ -71,11 +71,11 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
//Assert
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
}
@ -101,19 +101,19 @@ namespace NzbDrone.Core.Test.JobTests
.Returns(series);
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
.Callback(() => series[0].LastInfoSync = DateTime.Now);
Mocker.GetMock<UpdateInfoJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)))
.Throws(new InvalidOperationException());
Mocker.GetMock<DiskScanJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }))
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)))
.Callback(() => series[0].LastDiskSync = DateTime.Now);
Mocker.GetMock<BannerDownloadJob>()
.Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }));
.Setup(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)));
Mocker.GetMock<SeriesProvider>()
.Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]);
@ -125,12 +125,10 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.Resolve<ImportNewSeriesJob>().Start(notification, null);
//Assert
Mocker.VerifyAllMocks();
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[1].SeriesId)), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<UpdateInfoJob>().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0}), Times.Once());
Mocker.GetMock<DiskScanJob>().Verify(j => j.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == series[0].SeriesId)), Times.Once());
ExceptionVerification.ExpectedErrors(1);

@ -13,6 +13,7 @@ using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
@ -87,13 +88,13 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes);
Mocker.GetMock<EpisodeSearchJob>().Setup(c => c.Start(It.IsAny<ProgressNotification>(), new { EpisodeId = It.IsAny<int>() }));
Mocker.GetMock<EpisodeSearchJob>().Setup(c => c.Start(It.IsAny<ProgressNotification>(), It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)));
//Act
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, null);
//Assert
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(It.IsAny<ProgressNotification>(), new { EpisodeId = It.IsAny<int>() }),
Mocker.GetMock<EpisodeSearchJob>().Verify(c => c.Start(It.IsAny<ProgressNotification>(), It.Is<object>(d => d.GetPropertyValue<int>("EpisodeId") >= 0)),
Times.Exactly(40));
}

@ -15,21 +15,20 @@ namespace NzbDrone.Core.Test.JobTests
[TestCase(0)]
[TestCase(-1)]
[TestCase(-100)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
[ExpectedException(typeof(ArgumentException))]
public void start_target_id_less_than_0_throws_exception(int target)
{
WithStrictMocker();
//Mocker.Resolve<EpisodeSearchJob>().Start(new ProgressNotification("Test"), target, 0);
Mocker.Resolve<EpisodeSearchJob>().Start(new ProgressNotification("Test"), new { EpisodeId = target });
}
[TestCase(0)]
[TestCase(-1)]
[TestCase(-100)]
[ExpectedException(typeof(ArgumentOutOfRangeException))]
[ExpectedException(typeof(ArgumentException))]
public void start_secondary_target_id_less_than_0_throws_exception(int target)
{
WithStrictMocker();
//Mocker.Resolve<SeasonSearchJob>().Start(new ProgressNotification("Test"), 0, target);
Mocker.Resolve<SeasonSearchJob>().Start(new ProgressNotification("Test"), new { SeriesId = 1, SeasonNumber = target });
}
}
}

@ -6,6 +6,7 @@ using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests
@ -30,14 +31,14 @@ namespace NzbDrone.Core.Test.JobTests
.Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false);
Mocker.GetMock<SeasonSearchJob>()
.Setup(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny<int>() })).Verifiable();
.Setup(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == 1 && d.GetPropertyValue<int>("SeasonNumber") >= 0))).Verifiable();
//Act
Mocker.Resolve<SeriesSearchJob>().Start(notification, new { SeriesId = 1 });
//Assert
Mocker.VerifyAllMocks();
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny<int>() }),
Mocker.GetMock<SeasonSearchJob>().Verify(c => c.Start(notification, It.Is<object>(d => d.GetPropertyValue<int>("SeriesId") == 1 && d.GetPropertyValue<int>("SeasonNumber") >= 0)),
Times.Exactly(seasons.Count));
}

@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
@ -37,3 +38,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: InternalsVisibleTo("NzbDrone.Core")]

@ -12,6 +12,7 @@ using System.Runtime.InteropServices;
[assembly: Guid("3C29FEF7-4B07-49ED-822E-1C29DC49BFAB")]
[assembly: InternalsVisibleTo("NzbDrone.Core.Test")]
[assembly: InternalsVisibleTo("NzbDrone.Web")]
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:

@ -69,6 +69,7 @@
<Compile Include="ExceptionVerification.cs" />
<Compile Include="LoggingTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReflectionExtensions.cs" />
<Compile Include="TestBase.cs" />
</ItemGroup>
<ItemGroup>

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace NzbDrone.Test.Common
{
public static class ReflectionExtensions
{
public static T GetPropertyValue<T>(this object obj, string propertyName)
{
return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null);
}
}
}

@ -1,4 +1,5 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
[assembly: AssemblyTitle("NzbDrone.Web")]
@ -11,3 +12,5 @@ using System.Runtime.InteropServices;
[assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")]
[assembly: InternalsVisibleTo("NzbDrone.Core")]
Loading…
Cancel
Save