From 634cc32ad85d8bcb0fbcb813ca4f4993c6ced0c6 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 14 Sep 2013 16:34:21 -0700 Subject: [PATCH] added test for command executed event --- .../NzbDrone.Common.Test.csproj | 3 -- .../CommandEqualityComparerFixture.cs | 2 +- .../Commands}/CommandExecutorFixture.cs | 28 +++++++++++++++++-- .../Messaging/Commands/CommandFixture.cs | 5 ++-- NzbDrone.Core.Test/NzbDrone.Core.Test.csproj | 3 ++ NzbDrone.Core/Jobs/JobRepository.cs | 1 - .../Messaging/Commands/CommandExecutor.cs | 5 ++-- NzbDrone.sln.DotSettings | 1 + 8 files changed, 36 insertions(+), 12 deletions(-) rename {NzbDrone.Common.Test/MessagingTests => NzbDrone.Core.Test/Messaging/Commands}/CommandEqualityComparerFixture.cs (98%) rename {NzbDrone.Common.Test/MessagingTests => NzbDrone.Core.Test/Messaging/Commands}/CommandExecutorFixture.cs (77%) rename NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs => NzbDrone.Core.Test/Messaging/Commands/CommandFixture.cs (80%) diff --git a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj index dc2b6ad13..2347a37bf 100644 --- a/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj +++ b/NzbDrone.Common.Test/NzbDrone.Common.Test.csproj @@ -67,10 +67,7 @@ - - - diff --git a/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs b/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs similarity index 98% rename from NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs rename to NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs index 2f62655ab..f4ffc3614 100644 --- a/NzbDrone.Common.Test/MessagingTests/CommandEqualityComparerFixture.cs +++ b/NzbDrone.Core.Test/Messaging/Commands/CommandEqualityComparerFixture.cs @@ -4,7 +4,7 @@ using NzbDrone.Core.MediaFiles.Commands; using NzbDrone.Core.Messaging.Commands; -namespace NzbDrone.Common.Test.MessagingTests +namespace NzbDrone.Core.Test.Messaging.Commands { [TestFixture] public class CommandEqualityComparerFixture diff --git a/NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs b/NzbDrone.Core.Test/Messaging/Commands/CommandExecutorFixture.cs similarity index 77% rename from NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs rename to NzbDrone.Core.Test/Messaging/Commands/CommandExecutorFixture.cs index 21396dc8e..650f81224 100644 --- a/NzbDrone.Common.Test/MessagingTests/CommandExecutorFixture.cs +++ b/NzbDrone.Core.Test/Messaging/Commands/CommandExecutorFixture.cs @@ -2,12 +2,13 @@ using System.Collections.Generic; using Moq; using NUnit.Framework; -using NzbDrone.Core.Messaging; +using NzbDrone.Common; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Commands.Tracking; +using NzbDrone.Core.Messaging.Events; using NzbDrone.Test.Common; -namespace NzbDrone.Common.Test.MessagingTests +namespace NzbDrone.Core.Test.Messaging.Commands { [TestFixture] public class CommandExecutorFixture : TestBase @@ -77,6 +78,29 @@ public void broken_executor_should_throw_the_exception() Assert.Throws(() => Subject.PublishCommand(commandA)); } + + + [Test] + public void broken_executor_should_publish_executed_event() + { + var commandA = new CommandA(); + + _executorA.Setup(c => c.Execute(It.IsAny())) + .Throws(new NotImplementedException()); + + Assert.Throws(() => Subject.PublishCommand(commandA)); + + VerifyEventPublished(); + } + + [Test] + public void should_publish_executed_event_on_success() + { + var commandA = new CommandA(); + Subject.PublishCommand(commandA); + + VerifyEventPublished(); + } } public class CommandA : Command diff --git a/NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs b/NzbDrone.Core.Test/Messaging/Commands/CommandFixture.cs similarity index 80% rename from NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs rename to NzbDrone.Core.Test/Messaging/Commands/CommandFixture.cs index bca26ed90..a75fc2224 100644 --- a/NzbDrone.Common.Test/MessagingTests/CommandBaseFixture.cs +++ b/NzbDrone.Core.Test/Messaging/Commands/CommandFixture.cs @@ -2,10 +2,10 @@ using NUnit.Framework; using NzbDrone.Core.Update.Commands; -namespace NzbDrone.Common.Test.MessagingTests +namespace NzbDrone.Core.Test.Messaging.Commands { [TestFixture] - public class CommandBaseFixture + public class CommandFixture { [Test] public void default_values() @@ -15,6 +15,5 @@ public void default_values() command.Id.Should().NotBe(0); command.Name.Should().Be("ApplicationUpdate"); } - } } \ No newline at end of file diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj index 2235812d2..38660dd5d 100644 --- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj +++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj @@ -147,6 +147,9 @@ + + + diff --git a/NzbDrone.Core/Jobs/JobRepository.cs b/NzbDrone.Core/Jobs/JobRepository.cs index 726f06963..8e2aa5858 100644 --- a/NzbDrone.Core/Jobs/JobRepository.cs +++ b/NzbDrone.Core/Jobs/JobRepository.cs @@ -1,7 +1,6 @@ using System; using System.Linq; using NzbDrone.Core.Datastore; -using NzbDrone.Core.Messaging; using NzbDrone.Core.Messaging.Events; diff --git a/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs b/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs index db14c7aa2..f54340a9c 100644 --- a/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs +++ b/NzbDrone.Core/Messaging/Commands/CommandExecutor.cs @@ -118,12 +118,13 @@ private void ExecuteCommand(Command command) where TCommand : Command } finally { + _eventAggregator.PublishEvent(new CommandUpdatedEvent(command)); + _eventAggregator.PublishEvent(new CommandExecutedEvent(command)); + if (MappedDiagnosticsContext.Get("CommandId") == command.Id.ToString()) { MappedDiagnosticsContext.Remove("CommandId"); } - _eventAggregator.PublishEvent(new CommandUpdatedEvent(command)); - _eventAggregator.PublishEvent(new CommandExecutedEvent(command)); } _logger.Trace("{0} <- {1} [{2}]", command.GetType().Name, handler.GetType().Name, command.Runtime.ToString("")); diff --git a/NzbDrone.sln.DotSettings b/NzbDrone.sln.DotSettings index 82bd482c5..a7de7ce4f 100644 --- a/NzbDrone.sln.DotSettings +++ b/NzbDrone.sln.DotSettings @@ -11,6 +11,7 @@ WARNING WARNING HINT + Fixture ^(.*)\.Test(\..*)$ <?xml version="1.0" encoding="utf-16"?><Profile name="NzbDrone"><CSArrangeThisQualifier>True</CSArrangeThisQualifier><RemoveCodeRedundancies>True</RemoveCodeRedundancies><CSUseAutoProperty>True</CSUseAutoProperty><CSMakeFieldReadonly>True</CSMakeFieldReadonly><CSUseVar><BehavourStyle>CAN_CHANGE_TO_IMPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_EXCEPT_SIMPLE_TYPES</LocalVariableStyle><ForeachVariableStyle>ALWAYS_IMPLICIT</ForeachVariableStyle></CSUseVar><CSUpdateFileHeader>True</CSUpdateFileHeader><CSOptimizeUsings><OptimizeUsings>True</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSShortenReferences>True</CSShortenReferences><CSReorderTypeMembers>True</CSReorderTypeMembers><XAMLCollapseEmptyTags>False</XAMLCollapseEmptyTags></Profile> NzbDrone