mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 18:57:39 -07:00
added commands.
they can be triggered using the api api/command/
This commit is contained in:
parent
68ee71ea81
commit
182192e0ba
31 changed files with 265 additions and 74 deletions
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Messaging;
|
||||
using NzbDrone.Test.Common;
|
||||
|
||||
namespace NzbDrone.Common.Test.EventingTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class MessageAggregatorCommandTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_publish_command_to_executor()
|
||||
{
|
||||
var commandA = new CommandA();
|
||||
|
||||
var executor = new Mock<IExecute<CommandA>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { executor.Object });
|
||||
aggregator.PublishCommand(commandA);
|
||||
|
||||
executor.Verify(c => c.Execute(commandA), Times.Once());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void should_throw_if_more_than_one_handler()
|
||||
{
|
||||
var commandA = new CommandA();
|
||||
|
||||
var executor1 = new Mock<IExecute<CommandA>>();
|
||||
var executor2 = new Mock<IExecute<CommandA>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { executor1.Object, executor2.Object });
|
||||
|
||||
Assert.Throws<InvalidOperationException>(() => aggregator.PublishCommand(commandA));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_not_publish_to_incompatible_executor()
|
||||
{
|
||||
var commandA = new CommandA();
|
||||
|
||||
var executor1 = new Mock<IExecute<CommandA>>();
|
||||
var executor2 = new Mock<IExecute<CommandB>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { executor1.Object, executor2.Object });
|
||||
|
||||
aggregator.PublishCommand(commandA);
|
||||
|
||||
executor1.Verify(c => c.Execute(commandA), Times.Once());
|
||||
executor2.Verify(c => c.Execute(It.IsAny<CommandB>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void broken_executor_should_throw_the_exception()
|
||||
{
|
||||
var commandA = new CommandA();
|
||||
|
||||
var executor = new Mock<IExecute<CommandA>>();
|
||||
|
||||
executor.Setup(c => c.Execute(It.IsAny<CommandA>()))
|
||||
.Throws(new NotImplementedException());
|
||||
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { executor.Object });
|
||||
Assert.Throws<NotImplementedException>(() => aggregator.PublishCommand(commandA));
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandA : ICommand
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public class CommandB : ICommand
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using NzbDrone.Common.Messaging;
|
||||
|
@ -8,17 +8,17 @@ using NzbDrone.Test.Common;
|
|||
namespace NzbDrone.Common.Test.EventingTests
|
||||
{
|
||||
[TestFixture]
|
||||
public class ServiceNameFixture : TestBase
|
||||
public class MessageAggregatorEventTests : TestBase
|
||||
{
|
||||
[Test]
|
||||
public void should_publish_event_to_handlers()
|
||||
{
|
||||
var eventA = new EventA();
|
||||
|
||||
|
||||
|
||||
var intHandler = new Mock<IHandle<EventA>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { intHandler.Object });
|
||||
aggregator.Publish(eventA);
|
||||
aggregator.PublishEvent(eventA);
|
||||
|
||||
intHandler.Verify(c => c.Handle(eventA), Times.Once());
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace NzbDrone.Common.Test.EventingTests
|
|||
var intHandler1 = new Mock<IHandle<EventA>>();
|
||||
var intHandler2 = new Mock<IHandle<EventA>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { intHandler1.Object, intHandler2.Object });
|
||||
aggregator.Publish(eventA);
|
||||
aggregator.PublishEvent(eventA);
|
||||
|
||||
intHandler1.Verify(c => c.Handle(eventA), Times.Once());
|
||||
intHandler2.Verify(c => c.Handle(eventA), Times.Once());
|
||||
|
@ -46,18 +46,41 @@ namespace NzbDrone.Common.Test.EventingTests
|
|||
var bHandler = new Mock<IHandle<EventB>>();
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { aHandler.Object, bHandler.Object });
|
||||
|
||||
aggregator.Publish(eventA);
|
||||
aggregator.PublishEvent(eventA);
|
||||
|
||||
aHandler.Verify(c => c.Handle(eventA), Times.Once());
|
||||
bHandler.Verify(c => c.Handle(It.IsAny<EventB>()), Times.Never());
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void broken_handler_should_not_effect_others_handler()
|
||||
{
|
||||
var eventA = new EventA();
|
||||
|
||||
var intHandler1 = new Mock<IHandle<EventA>>();
|
||||
var intHandler2 = new Mock<IHandle<EventA>>();
|
||||
var intHandler3 = new Mock<IHandle<EventA>>();
|
||||
|
||||
intHandler2.Setup(c => c.Handle(It.IsAny<EventA>()))
|
||||
.Throws(new NotImplementedException());
|
||||
|
||||
var aggregator = new MessageAggregator(TestLogger, () => new List<IProcessMessage> { intHandler1.Object, intHandler2.Object , intHandler3.Object});
|
||||
aggregator.PublishEvent(eventA);
|
||||
|
||||
intHandler1.Verify(c => c.Handle(eventA), Times.Once());
|
||||
intHandler3.Verify(c => c.Handle(eventA), Times.Once());
|
||||
|
||||
|
||||
ExceptionVerification.ExpectedErrors(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class EventA:IEvent
|
||||
public class EventA : IEvent
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
public class EventB : IEvent
|
|
@ -79,7 +79,8 @@
|
|||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ConfigFileProviderTest.cs" />
|
||||
<Compile Include="EventingTests\EventAggregatorTests.cs" />
|
||||
<Compile Include="EventingTests\MessageAggregatorCommandTests.cs" />
|
||||
<Compile Include="EventingTests\MessageAggregatorEventTests.cs" />
|
||||
<Compile Include="ReflectionExtensions.cs" />
|
||||
<Compile Include="ReportingService_ReportParseError_Fixture.cs" />
|
||||
<Compile Include="PathExtentionFixture.cs" />
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue