From 652a9d4a8aa2be6f61dea1c39f666405383d3118 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sun, 14 Apr 2013 22:27:51 -0700 Subject: [PATCH] removed strict mock from test base. --- .../AcceptableSizeSpecificationFixture.cs | 24 +++++++++---------- .../ProviderTests/GrowlProviderTest.cs | 8 +++---- .../ProviderTests/MisnamedProviderTest.cs | 10 ++++---- .../ProviderTests/ProwlProviderTest.cs | 18 +++++++------- .../ProviderTests/XbmcProviderTest.cs | 12 +++++----- NzbDrone.Test.Common/TestBase.cs | 16 ------------- 6 files changed, 35 insertions(+), 53 deletions(-) diff --git a/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs b/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs index 27c46354a..183b70262 100644 --- a/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs +++ b/NzbDrone.Core.Test/DecisionEngineTests/AcceptableSizeSpecificationFixture.cs @@ -96,8 +96,6 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_single_episode_not_first_or_last_30_minute() { - WithStrictMocker(); - parseResultSingle.Series = series30minutes; parseResultSingle.Report.Size = 1.Gigabytes(); @@ -117,7 +115,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_single_episode_not_first_or_last_60_minute() { - WithStrictMocker(); + parseResultSingle.Series = series60minutes; parseResultSingle.Report.Size = 1.Gigabytes(); @@ -138,7 +136,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_multi_episode_not_first_or_last_30_minute() { - WithStrictMocker(); + parseResultMulti.Series = series30minutes; parseResultMulti.Report.Size = 184572800; @@ -159,7 +157,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_multi_episode_not_first_or_last_60_minute() { - WithStrictMocker(); + parseResultMulti.Series = series60minutes; parseResultMulti.Report.Size = 368572800; @@ -180,7 +178,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_multi_episode_not_first_or_last_30_minute() { - WithStrictMocker(); + parseResultMulti.Series = series30minutes; parseResultMulti.Report.Size = 1.Gigabytes(); @@ -201,7 +199,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_multi_episode_not_first_or_last_60_minute() { - WithStrictMocker(); + parseResultMulti.Series = series60minutes; parseResultMulti.Report.Size = 10.Gigabytes(); @@ -222,7 +220,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_single_episode_first_30_minute() { - WithStrictMocker(); + parseResultSingle.Series = series30minutes; parseResultSingle.Report.Size = 184572800; @@ -243,7 +241,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_single_episode_first_60_minute() { - WithStrictMocker(); + parseResultSingle.Series = series60minutes; parseResultSingle.Report.Size = 368572800; @@ -264,7 +262,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_single_episode_first_30_minute() { - WithStrictMocker(); + parseResultSingle.Series = series30minutes; parseResultSingle.Report.Size = 1.Gigabytes(); @@ -285,7 +283,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_false_single_episode_first_60_minute() { - WithStrictMocker(); + parseResultSingle.Series = series60minutes; parseResultSingle.Report.Size = 10.Gigabytes(); @@ -306,7 +304,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_unlimited_30_minute() { - WithStrictMocker(); + parseResultSingle.Series = series30minutes; parseResultSingle.Report.Size = 18457280000; @@ -328,7 +326,7 @@ namespace NzbDrone.Core.Test.DecisionEngineTests [Test] public void IsAcceptableSize_true_unlimited_60_minute() { - WithStrictMocker(); + parseResultSingle.Series = series60minutes; parseResultSingle.Report.Size = 36857280000; diff --git a/NzbDrone.Core.Test/ProviderTests/GrowlProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/GrowlProviderTest.cs index 9efaadc70..7dc91e90a 100644 --- a/NzbDrone.Core.Test/ProviderTests/GrowlProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/GrowlProviderTest.cs @@ -23,7 +23,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Register_should_add_new_application_to_local_growl_instance() { - WithStrictMocker(); + Mocker.Resolve().Register("localhost", 23053, ""); @@ -36,7 +36,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void TestNotification_should_send_a_message_to_local_growl_instance() { - WithStrictMocker(); + Mocker.Resolve().TestNotification("localhost", 23053, ""); @@ -49,7 +49,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void OnGrab_should_send_a_message_to_local_growl_instance() { - WithStrictMocker(); + Mocker.Resolve().SendNotification("Episode Grabbed", "Series Title - 1x05 - Episode Title", "GRAB", "localhost", 23053, ""); @@ -62,7 +62,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void OnDownload_should_send_a_message_to_local_growl_instance() { - WithStrictMocker(); + Mocker.Resolve().SendNotification("Episode Downloaded", "Series Title - 1x05 - Episode Title", "DOWNLOAD", "localhost", 23053, ""); diff --git a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs index e0f4b4cf4..cf5b5a69d 100644 --- a/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/MisnamedProviderTest.cs @@ -44,7 +44,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(e => e.EpisodeFile = episodeFiles[1]) .Build().ToList(); - WithStrictMocker(); + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); @@ -91,7 +91,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(e => e.EpisodeFile = episodeFiles[1]) .Build().ToList(); - WithStrictMocker(); + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); @@ -138,7 +138,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(e => e.EpisodeFile = episodeFiles[1]) .Build().ToList(); - WithStrictMocker(); + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); @@ -187,7 +187,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(e => e.EpisodeFile = episodeFiles[1]) .Build().ToList(); - WithStrictMocker(); + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); @@ -236,7 +236,7 @@ namespace NzbDrone.Core.Test.ProviderTests .With(e => e.EpisodeFile = episodeFiles[1]) .Build().ToList(); - WithStrictMocker(); + Mocker.GetMock() .Setup(c => c.EpisodesWithFiles()).Returns(episodes); diff --git a/NzbDrone.Core.Test/ProviderTests/ProwlProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/ProwlProviderTest.cs index 1d63e8b84..03ae3a293 100644 --- a/NzbDrone.Core.Test/ProviderTests/ProwlProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/ProwlProviderTest.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Verify_should_return_true_for_a_valid_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().Verify(_apiKey); @@ -42,7 +42,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Verify_should_return_false_for_an_invalid_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().Verify(_badApiKey); @@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_return_true_for_a_valid_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey); @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_return_false_for_an_invalid_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _badApiKey); @@ -83,7 +83,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_alert_with_high_priority() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (High)", _apiKey, NotificationPriority.High); @@ -96,7 +96,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_alert_with_VeryLow_priority() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone (VeryLow)", _apiKey, NotificationPriority.VeryLow); @@ -109,7 +109,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_have_a_call_back_url() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey, NotificationPriority.Normal, "http://www.nzbdrone.com"); @@ -122,7 +122,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_return_true_for_two_valid_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _apiKey2); @@ -135,7 +135,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendNotification_should_return_true_for_valid_apiKey_with_bad_apiKey() { - WithStrictMocker(); + var result = Mocker.Resolve().SendNotification("NzbDrone Test", "This is a test message from NzbDrone", _apiKey + ", " + _badApiKey); diff --git a/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs b/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs index 269a4944b..249d84f88 100644 --- a/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/XbmcProviderTest.cs @@ -291,7 +291,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Notify_true() { - WithStrictMocker(); + var header = "NzbDrone Test"; var message = "Test Message!"; @@ -314,7 +314,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void SendCommand() { - WithStrictMocker(); + var host = "localhost:8080"; var command = "ExecBuiltIn(CleanLibrary(video))"; @@ -339,7 +339,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void GetXbmcSeriesPath_true() { - WithStrictMocker(); + var queryResult = @"smb://xbmc:xbmc@HOMESERVER/TV/30 Rock/"; @@ -372,7 +372,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void GetXbmcSeriesPath_false() { - WithStrictMocker(); + var queryResult = @""; @@ -405,7 +405,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void GetXbmcSeriesPath_special_characters() { - WithStrictMocker(); + var queryResult = @"smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/"; @@ -438,7 +438,7 @@ namespace NzbDrone.Core.Test.ProviderTests public void Clean() { - WithStrictMocker(); + var fakeConfig = Mocker.GetMock(); fakeConfig.SetupGet(s => s.XbmcHosts).Returns("localhost:8080"); diff --git a/NzbDrone.Test.Common/TestBase.cs b/NzbDrone.Test.Common/TestBase.cs index 583b07d2d..3aef40160 100644 --- a/NzbDrone.Test.Common/TestBase.cs +++ b/NzbDrone.Test.Common/TestBase.cs @@ -99,20 +99,6 @@ namespace NzbDrone.Test.Common catch (Exception) { } - - } - - [Obsolete("Use Mock.Verify() instead")] - protected void WithStrictMocker() - { - return; - - //TODO: Remove dependency on restrict mocks! - - if (_mocker != null) - throw new InvalidOperationException("Can not switch to a strict container after container has been used. make sure this is the first call in your test."); - - _mocker = new AutoMoqer(MockBehavior.Strict); } protected void WithTempAsAppPath() @@ -127,8 +113,6 @@ namespace NzbDrone.Test.Common return Path.Combine(Directory.GetCurrentDirectory(), "Files", fileName); } - - protected void VerifyEventPublished() where TEvent : IEvent { VerifyEventPublished(Times.Once());