simplified EventAggregator

This commit is contained in:
kay.one
2013-02-23 12:09:44 -08:00
parent b3c6db5997
commit 66972e5bc6
6 changed files with 187 additions and 194 deletions
@@ -0,0 +1,58 @@
using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using NzbDrone.Common.Eventing;
using NzbDrone.Test.Common;
namespace NzbDrone.Common.Test.EventingTests
{
[TestFixture]
public class ServiceNameFixture : TestBase
{
private EventAggregator _aggregator;
[SetUp]
public void Setup()
{
_aggregator = new EventAggregator(TestLogger, null);
}
[Test]
public void should_publish_event_to_handlers()
{
var intHandler = new Mock<IHandle<int>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object });
_aggregator.Publish(12);
intHandler.Verify(c => c.Handle(12), Times.Once());
}
[Test]
public void should_publish_to_more_than_one_handler()
{
var intHandler1 =new Mock<IHandle<int>>();
var intHandler2 = new Mock<IHandle<int>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler1.Object, intHandler2.Object });
_aggregator.Publish(12);
intHandler1.Verify(c => c.Handle(12), Times.Once());
intHandler2.Verify(c => c.Handle(12), Times.Once());
}
[Test]
public void should_not_publish_to_incompatible_handlers()
{
var intHandler = new Mock<IHandle<int>>();
var stringHandler = new Mock<IHandle<string>>();
_aggregator = new EventAggregator(TestLogger, new List<IHandle> { intHandler.Object, stringHandler.Object });
_aggregator.Publish(12);
intHandler.Verify(c => c.Handle(12), Times.Once());
stringHandler.Verify(c => c.Handle(It.IsAny<string>()), Times.Never());
}
}
}
@@ -86,6 +86,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="ConfigFileProviderTest.cs" />
<Compile Include="EventingTests\EventAggregatorTests.cs" />
<Compile Include="ReflectionExtensions.cs" />
<Compile Include="ReportingService_ReportParseError_Fixture.cs" />
<Compile Include="PathExtentionFixture.cs" />