PageRenderTime 27ms CodeModel.GetById 16ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Source/Bifrost.Specs/Events/for_EventRepository/when_getting_unprocessed_events_for_one_subscription_and_there_is_one_event_that_is_unprocessed.cs

#
C# | 69 lines | 55 code | 14 blank | 0 comment | 0 complexity | b0621edb2825288d81139e68b70e8ce6 MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using Bifrost.Entities;
 5using Bifrost.Events;
 6using Bifrost.Fakes.Events;
 7using Bifrost.Time;
 8using Machine.Specifications;
 9using Moq;
10using It = Machine.Specifications.It;
11
12namespace Bifrost.Specs.Events.for_EventRepository
13{
14    public class when_getting_unprocessed_events_for_one_subscription_and_there_is_one_event_that_is_unprocessed
15    {
16        const string EventSourceName = "MyEventSource";
17        static Mock<IEntityContext<EventHolder>>    entity_context_mock;
18        static Mock<IEventConverter> event_converter_mock;
19        static Mock<IEventMigrationHierarchyManager> event_migration_hierarchy_manager_mock;
20        static EventRepository repository;
21        static EventSubscription subscription;
22        static IEnumerable<IEvent> result;
23        static SimpleEvent expected_event;
24        static EventHolder event_holder;
25
26        Establish context = ()=> 
27        {
28            subscription = new EventSubscription
29            {
30                Owner = typeof(Subscribers),
31                Method = typeof(Subscribers).GetMethod(ProcessMethodInvoker.ProcessMethodName, new[] { typeof(SimpleEvent) }),
32                EventType = typeof(SimpleEvent),
33                EventName = typeof(SimpleEvent).Name,
34            };
35            subscription.SetEventSourceVersion(EventSourceName, new EventSourceVersion(1,0));
36
37            expected_event = new SimpleEvent(Guid.NewGuid());
38            expected_event.EventSourceName = EventSourceName;
39            expected_event.Occured = DateTime.Now;
40
41            entity_context_mock = new Mock<IEntityContext<EventHolder>>();
42
43            event_holder = new EventHolder
44            {
45                LogicalEventName = expected_event.GetType().Name,
46                Name = expected_event.GetType().Name,
47                Occured = expected_event.Occured
48            };
49
50            entity_context_mock.Setup(e => e.Entities).Returns(new[] { event_holder }.AsQueryable());
51
52            event_converter_mock = new Mock<IEventConverter>();
53
54            event_converter_mock.Setup(e => e.ToEvent(Moq.It.IsAny<EventHolder>())).Returns(expected_event);
55            event_converter_mock.Setup(e => e.ToEvents(Moq.It.IsAny<IEnumerable<EventHolder>>())).Returns(new[] { expected_event });
56
57            event_migration_hierarchy_manager_mock = new Mock<IEventMigrationHierarchyManager>();
58
59            event_migration_hierarchy_manager_mock.Setup(e => e.GetLogicalTypeFromName(subscription.EventName)).Returns(expected_event.GetType());
60
61            repository = new EventRepository(entity_context_mock.Object, event_converter_mock.Object, event_migration_hierarchy_manager_mock.Object);
62
63        };
64
65        Because of = () => result = repository.GetUnprocessedEventsForSubscriptions(new[] { subscription });
66
67        It should_return_one_event = () => result.Count().ShouldEqual(1);
68    }
69}