diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index a0c96e899..f24ba68be 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -61,6 +61,7 @@ + diff --git a/NzbDrone.Common.Test/ReflectionExtensions.cs b/NzbDrone.Common.Test/ReflectionExtensions.cs new file mode 100644 index 000000000..c5aee4d5e --- /dev/null +++ b/NzbDrone.Common.Test/ReflectionExtensions.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(this object obj, string propertyName) + { + return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null); + } + } +} diff --git a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs index 17fd588b0..7362c71d3 100644 --- a/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BacklogSearchJobTest.cs @@ -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() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = 1 })); + .Setup(s => s.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") == 1))); //Act Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), Times.Once()); } @@ -101,23 +98,16 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.Series = series) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny()})).Verifiable(); - //Act Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("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() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }); @@ -154,11 +140,8 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), - Times.Never()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Exactly(episodes.Count)); + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), + Times.Exactly(episodes.Count)); } [Test] @@ -179,15 +162,11 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.SeasonNumber = 1) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(episodes.Select(e => e.EpisodeNumber).ToList()); @@ -195,11 +174,9 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && + d.GetPropertyValue("SeasonNumber") >= 0)), Times.Once()); - - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Never()); } [Test] @@ -227,18 +204,11 @@ namespace NzbDrone.Core.Test.JobTests .With(e => e.Series = series2) .Build(); - WithStrictMocker(); WithEnableBacklogSearching(); Mocker.GetMock() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock() - .Setup(s => s.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() })).Verifiable(); - - Mocker.GetMock() - .Setup(s => s.Start(notification, new { EpisodeId = It.IsAny() })).Verifiable(); - Mocker.GetMock() .Setup(s => s.GetEpisodeNumbersBySeason(1, 1)).Returns(new List { 1, 2, 3, 4, 5 }); @@ -246,11 +216,12 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0 && + d.GetPropertyValue("SeasonNumber") >= 0)), Times.Once()); - Mocker.GetMock().Verify(c => c.Start(notification, new { EpisodeId = It.IsAny() }), - Times.Exactly(5)); + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), + Times.Exactly(5)); } [Test] diff --git a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs index 88b746c8a..768d187be 100644 --- a/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/BannerDownloadJobTest.cs @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock().Setup(s => s.GetSeries(series.SeriesId)) .Returns(series); - Mocker.Resolve().Start(_notification, new { SeriesId = 0 }); + Mocker.Resolve().Start(_notification, new { SeriesId = series.SeriesId }); VerifyDownloadMock(1); } } diff --git a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs index 8b5aa8e4a..46110a053 100644 --- a/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/ImportNewSeriesJobTest.cs @@ -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.CreateListOfSize(2) .All().With(s => s.LastInfoSync = null) @@ -39,23 +39,23 @@ namespace NzbDrone.Core.Test.JobTests Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0})) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Callback(() => series[1].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = It.IsAny(), SeasonNumber = 0 })); + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") >= 0))); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Callback(() => series[1].LastInfoSync = DateTime.Now); Mocker.GetMock() @@ -71,11 +71,11 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); } @@ -101,19 +101,19 @@ namespace NzbDrone.Core.Test.JobTests .Returns(series); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastInfoSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId))) .Throws(new InvalidOperationException()); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })) + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))) .Callback(() => series[0].LastDiskSync = DateTime.Now); Mocker.GetMock() - .Setup(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 })); + .Setup(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId))); Mocker.GetMock() .Setup(s => s.GetSeries(series[0].SeriesId)).Returns(series[0]); @@ -125,12 +125,10 @@ namespace NzbDrone.Core.Test.JobTests Mocker.Resolve().Start(notification, null); //Assert - Mocker.VerifyAllMocks(); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[1].SeriesId)), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0 }), Times.Once()); - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[1].SeriesId, SeasonNumber = 0 }), Times.Once()); - - Mocker.GetMock().Verify(j => j.Start(notification, new { SeriesId = series[0].SeriesId, SeasonNumber = 0}), Times.Once()); + Mocker.GetMock().Verify(j => j.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == series[0].SeriesId)), Times.Once()); ExceptionVerification.ExpectedErrors(1); diff --git a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs index 329d2840c..5a9a814bf 100644 --- a/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/RecentBacklogSearchJobTest.cs @@ -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() .Setup(s => s.EpisodesWithoutFiles(true)).Returns(episodes); - Mocker.GetMock().Setup(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() })); + Mocker.GetMock().Setup(c => c.Start(It.IsAny(), It.Is(d => d.GetPropertyValue("EpisodeId") >= 0))); //Act Mocker.Resolve().Start(MockNotification, null); //Assert - Mocker.GetMock().Verify(c => c.Start(It.IsAny(), new { EpisodeId = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(It.IsAny(), It.Is(d => d.GetPropertyValue("EpisodeId") >= 0)), Times.Exactly(40)); } diff --git a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs index 5ca459f08..e3c6a5a52 100644 --- a/NzbDrone.Core.Test/JobTests/SearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SearchJobTest.cs @@ -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().Start(new ProgressNotification("Test"), target, 0); + Mocker.Resolve().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().Start(new ProgressNotification("Test"), 0, target); + Mocker.Resolve().Start(new ProgressNotification("Test"), new { SeriesId = 1, SeasonNumber = target }); } } } diff --git a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs index 6236f497e..8dc9069b3 100644 --- a/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs +++ b/NzbDrone.Core.Test/JobTests/SeriesSearchJobTest.cs @@ -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(), It.IsAny())).Returns(false); Mocker.GetMock() - .Setup(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() })).Verifiable(); + .Setup(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == 1 && d.GetPropertyValue("SeasonNumber") >= 0))).Verifiable(); //Act Mocker.Resolve().Start(notification, new { SeriesId = 1 }); //Assert Mocker.VerifyAllMocks(); - Mocker.GetMock().Verify(c => c.Start(notification, new { SeriesId = 1, SeasonNumber = It.IsAny() }), + Mocker.GetMock().Verify(c => c.Start(notification, It.Is(d => d.GetPropertyValue("SeriesId") == 1 && d.GetPropertyValue("SeasonNumber") >= 0)), Times.Exactly(seasons.Count)); } diff --git a/NzbDrone.Core.Test/Properties/AssemblyInfo.cs b/NzbDrone.Core.Test/Properties/AssemblyInfo.cs index b3fff6ebe..15b5d7b1f 100644 --- a/NzbDrone.Core.Test/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core.Test/Properties/AssemblyInfo.cs @@ -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 @@ -36,4 +37,6 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.0")] + +[assembly: InternalsVisibleTo("NzbDrone.Core")] \ No newline at end of file diff --git a/NzbDrone.Core/Properties/AssemblyInfo.cs b/NzbDrone.Core/Properties/AssemblyInfo.cs index 9c41cc91f..0445cde9a 100644 --- a/NzbDrone.Core/Properties/AssemblyInfo.cs +++ b/NzbDrone.Core/Properties/AssemblyInfo.cs @@ -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: diff --git a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj index 61264ae1d..d9f881b96 100644 --- a/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj +++ b/NzbDrone.Test.Common/NzbDrone.Test.Common.csproj @@ -69,6 +69,7 @@ + diff --git a/NzbDrone.Test.Common/ReflectionExtensions.cs b/NzbDrone.Test.Common/ReflectionExtensions.cs new file mode 100644 index 000000000..4b32830e2 --- /dev/null +++ b/NzbDrone.Test.Common/ReflectionExtensions.cs @@ -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(this object obj, string propertyName) + { + return (T)obj.GetType().GetProperty(propertyName).GetValue(obj, null); + } + } +} diff --git a/NzbDrone.Web/Properties/AssemblyInfo.cs b/NzbDrone.Web/Properties/AssemblyInfo.cs index f638cd457..9f3959149 100644 --- a/NzbDrone.Web/Properties/AssemblyInfo.cs +++ b/NzbDrone.Web/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; [assembly: AssemblyTitle("NzbDrone.Web")] @@ -10,4 +11,6 @@ using System.Runtime.InteropServices; // by using the '*' as shown below: [assembly: AssemblyVersion("1.0.0.*")] -[assembly: AssemblyFileVersion("1.0.0.*")] \ No newline at end of file +[assembly: AssemblyFileVersion("1.0.0.*")] + +[assembly: InternalsVisibleTo("NzbDrone.Core")] \ No newline at end of file