mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Merge
--HG-- branch : dev
This commit is contained in:
42
src/Orchard.Tests/Events/EventTests.cs
Normal file
42
src/Orchard.Tests/Events/EventTests.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System.Collections.Generic;
|
||||
using Autofac;
|
||||
using NUnit.Framework;
|
||||
using Orchard.Events;
|
||||
|
||||
namespace Orchard.Tests.Events {
|
||||
[TestFixture]
|
||||
public class EventTests {
|
||||
private IContainer _container;
|
||||
private IEventBus _eventBus;
|
||||
private StubEventBusHandler _eventBusHandler;
|
||||
|
||||
[SetUp]
|
||||
public void Init() {
|
||||
var builder = new ContainerBuilder();
|
||||
_eventBusHandler = new StubEventBusHandler();
|
||||
builder.RegisterInstance(_eventBusHandler).As<IEventBusHandler>();
|
||||
builder.RegisterType<DefaultOrchardEventBus>().As<IEventBus>();
|
||||
_container = builder.Build();
|
||||
_eventBus = _container.Resolve<IEventBus>();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void EventsAreCorrectlyDispatchedToHandlers() {
|
||||
Assert.That(_eventBusHandler.LastMessageName, Is.Null);
|
||||
_eventBus.Notify("Notification", new Dictionary<string, string>());
|
||||
Assert.That(_eventBusHandler.LastMessageName, Is.EqualTo("Notification"));
|
||||
}
|
||||
|
||||
public class StubEventBusHandler : IEventBusHandler {
|
||||
public string LastMessageName { get; set; }
|
||||
|
||||
#region Implementation of IEventBusHandler
|
||||
|
||||
public void Process(string messageName, IDictionary<string, string> eventData) {
|
||||
LastMessageName = messageName;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
@@ -85,6 +85,7 @@
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Data.SQLite, Version=1.0.65.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sqlite\System.Data.SQLite.DLL</HintPath>
|
||||
@@ -104,14 +105,13 @@
|
||||
<Reference Include="System.Web.Routing">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.XML" />
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="Yaml, Version=1.0.3370.39839, Culture=neutral, PublicKeyToken=187a3d240e44a135, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\yaml\Yaml.dll</HintPath>
|
||||
@@ -167,6 +167,7 @@
|
||||
<Compile Include="Environment\TestDependencies\TestDependency.cs" />
|
||||
<Compile Include="Environment\Topology\DefaultTopologyDescriptorCacheTests.cs" />
|
||||
<Compile Include="EventsTests.cs" />
|
||||
<Compile Include="Events\EventTests.cs" />
|
||||
<Compile Include="Extensions\ExtensionFoldersTests.cs" />
|
||||
<Compile Include="Extensions\ExtensionManagerTests.cs" />
|
||||
<Compile Include="Extensions\ExtensionTypes\StubTypes.cs" />
|
||||
|
23
src/Orchard/Events/DefaultOrchardEventBus.cs
Normal file
23
src/Orchard/Events/DefaultOrchardEventBus.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Logging;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public class DefaultOrchardEventBus : IEventBus {
|
||||
private readonly IEnumerable<IEventBusHandler> _handlers;
|
||||
|
||||
public DefaultOrchardEventBus(IEnumerable<IEventBusHandler> handlers) {
|
||||
_handlers = handlers;
|
||||
Logger = NullLogger.Instance;
|
||||
}
|
||||
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
#region Implementation of IEventBus
|
||||
|
||||
public void Notify(string messageName, IDictionary<string, string> eventData) {
|
||||
_handlers.Invoke(handler => handler.Process(messageName, eventData), Logger);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
7
src/Orchard/Events/IEventBus.cs
Normal file
7
src/Orchard/Events/IEventBus.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public interface IEventBus : IDependency {
|
||||
void Notify(string messageName, IDictionary<string, string> eventData);
|
||||
}
|
||||
}
|
7
src/Orchard/Events/IEventBusHandler.cs
Normal file
7
src/Orchard/Events/IEventBusHandler.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Orchard.Events {
|
||||
public interface IEventBusHandler : IEvents {
|
||||
void Process(string messageName, IDictionary<string, string> eventData);
|
||||
}
|
||||
}
|
@@ -178,6 +178,9 @@
|
||||
<Compile Include="Environment\ShellBuilders\SafeModeShellContainerFactory.cs" />
|
||||
<Compile Include="Environment\Configuration\ShellSettings.cs" />
|
||||
<Compile Include="Environment\StandaloneEnvironment.cs" />
|
||||
<Compile Include="Events\DefaultOrchardEventBus.cs" />
|
||||
<Compile Include="Events\IEventBus.cs" />
|
||||
<Compile Include="Events\IEventBusHandler.cs" />
|
||||
<Compile Include="Extensions\AreaFolders.cs" />
|
||||
<Compile Include="Extensions\ExtensionFolders.cs" />
|
||||
<Compile Include="Extensions\FeatureDescriptor.cs" />
|
||||
|
Reference in New Issue
Block a user