PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Events/for_EventSubscriptionManager/when_creating_and_there_is_no_subscription_in_repository_but_one_in_process.cs

#
C# | 41 lines | 34 code | 7 blank | 0 comment | 0 complexity | 576ece3196b5e40efd462a92e12be4c5 MD5 | raw file
 1using System;
 2using Bifrost.Events;
 3using Bifrost.Execution;
 4using Machine.Specifications;
 5using Bifrost.Time;
 6
 7
 8namespace Bifrost.Specs.Events.for_EventSubscriptionManager
 9{
10    public class when_creating_and_there_is_no_subscription_in_repository_but_one_in_process
11    {
12        protected static EventSubscriptionManager event_subscription_manager;
13        protected static Moq.Mock<IEventSubscriptionRepository> event_subscription_repository_mock;
14        protected static Moq.Mock<ITypeDiscoverer> type_discoverer_mock;
15        protected static Moq.Mock<IContainer> container_mock;
16
17        static EventSubscription    expected_subscription;
18        static EventSubscription    actual_subscription;
19
20        Establish context = () => 
21        {
22            event_subscription_repository_mock = new Moq.Mock<IEventSubscriptionRepository>();
23            type_discoverer_mock = new Moq.Mock<ITypeDiscoverer>();
24            container_mock = new Moq.Mock<IContainer>();
25
26            event_subscription_repository_mock.Setup(s=>s.Add(Moq.It.IsAny<EventSubscription>())).Callback((EventSubscription s)=>actual_subscription=s);
27            type_discoverer_mock.Setup(s=>s.FindMultiple<IEventSubscriber>()).Returns(new[] { typeof(SomeEventSubscriber)});
28            expected_subscription = new EventSubscription 
29            {
30                Owner = typeof(SomeEventSubscriber),
31                Method = typeof(SomeEventSubscriber).GetMethod(ProcessMethodInvoker.ProcessMethodName, new[] { typeof(SomeEvent) }),
32                EventType = typeof(SomeEvent),
33                EventName = typeof(SomeEvent).Name
34            };
35        };
36
37        Because of = () => event_subscription_manager = new EventSubscriptionManager(event_subscription_repository_mock.Object, type_discoverer_mock.Object, container_mock.Object);
38
39        It should_add_subscription = () => actual_subscription.ShouldEqual(expected_subscription);
40    }
41}