Fixed up tests

This commit is contained in:
Mark McDowall 2012-09-10 23:35:25 -07:00
parent a4dde81ceb
commit aa282fbd4d
13 changed files with 81 additions and 72 deletions

View File

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

View File

@ -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);
}
}
}

View File

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

View File

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

View File

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

View File

@ -13,6 +13,7 @@ using NzbDrone.Core.Providers;
using NzbDrone.Core.Providers.Core; using NzbDrone.Core.Providers.Core;
using NzbDrone.Core.Repository; using NzbDrone.Core.Repository;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests namespace NzbDrone.Core.Test.JobTests
@ -87,13 +88,13 @@ namespace NzbDrone.Core.Test.JobTests
Mocker.GetMock<EpisodeProvider>() Mocker.GetMock<EpisodeProvider>()
.Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); .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 //Act
Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, null); Mocker.Resolve<RecentBacklogSearchJob>().Start(MockNotification, null);
//Assert //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)); Times.Exactly(40));
} }

View File

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

View File

@ -6,6 +6,7 @@ using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers; using NzbDrone.Core.Providers;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Test.Common;
using NzbDrone.Test.Common.AutoMoq; using NzbDrone.Test.Common.AutoMoq;
namespace NzbDrone.Core.Test.JobTests 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); .Setup(c => c.IsIgnored(It.IsAny<int>(), It.IsAny<int>())).Returns(false);
Mocker.GetMock<SeasonSearchJob>() 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 //Act
Mocker.Resolve<SeriesSearchJob>().Start(notification, new { SeriesId = 1 }); Mocker.Resolve<SeriesSearchJob>().Start(notification, new { SeriesId = 1 });
//Assert //Assert
Mocker.VerifyAllMocks(); 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)); Times.Exactly(seasons.Count));
} }

View File

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

View File

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

View File

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

View File

@ -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);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Reflection; using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
[assembly: AssemblyTitle("NzbDrone.Web")] [assembly: AssemblyTitle("NzbDrone.Web")]
@ -10,4 +11,6 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below: // by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.*")] [assembly: AssemblyVersion("1.0.0.*")]
[assembly: AssemblyFileVersion("1.0.0.*")] [assembly: AssemblyFileVersion("1.0.0.*")]
[assembly: InternalsVisibleTo("NzbDrone.Core")]