PageRenderTime 36ms CodeModel.GetById 11ms RepoModel.GetById 0ms 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
Possible License(s): CC-BY-SA-3.0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Bifrost.Entities;
  5. using Bifrost.Events;
  6. using Bifrost.Fakes.Events;
  7. using Bifrost.Time;
  8. using Machine.Specifications;
  9. using Moq;
  10. using It = Machine.Specifications.It;
  11. namespace Bifrost.Specs.Events.for_EventRepository
  12. {
  13. public class when_getting_unprocessed_events_for_one_subscription_and_there_is_one_event_that_is_unprocessed
  14. {
  15. const string EventSourceName = "MyEventSource";
  16. static Mock<IEntityContext<EventHolder>> entity_context_mock;
  17. static Mock<IEventConverter> event_converter_mock;
  18. static Mock<IEventMigrationHierarchyManager> event_migration_hierarchy_manager_mock;
  19. static EventRepository repository;
  20. static EventSubscription subscription;
  21. static IEnumerable<IEvent> result;
  22. static SimpleEvent expected_event;
  23. static EventHolder event_holder;
  24. Establish context = ()=>
  25. {
  26. subscription = new EventSubscription
  27. {
  28. Owner = typeof(Subscribers),
  29. Method = typeof(Subscribers).GetMethod(ProcessMethodInvoker.ProcessMethodName, new[] { typeof(SimpleEvent) }),
  30. EventType = typeof(SimpleEvent),
  31. EventName = typeof(SimpleEvent).Name,
  32. };
  33. subscription.SetEventSourceVersion(EventSourceName, new EventSourceVersion(1,0));
  34. expected_event = new SimpleEvent(Guid.NewGuid());
  35. expected_event.EventSourceName = EventSourceName;
  36. expected_event.Occured = DateTime.Now;
  37. entity_context_mock = new Mock<IEntityContext<EventHolder>>();
  38. event_holder = new EventHolder
  39. {
  40. LogicalEventName = expected_event.GetType().Name,
  41. Name = expected_event.GetType().Name,
  42. Occured = expected_event.Occured
  43. };
  44. entity_context_mock.Setup(e => e.Entities).Returns(new[] { event_holder }.AsQueryable());
  45. event_converter_mock = new Mock<IEventConverter>();
  46. event_converter_mock.Setup(e => e.ToEvent(Moq.It.IsAny<EventHolder>())).Returns(expected_event);
  47. event_converter_mock.Setup(e => e.ToEvents(Moq.It.IsAny<IEnumerable<EventHolder>>())).Returns(new[] { expected_event });
  48. event_migration_hierarchy_manager_mock = new Mock<IEventMigrationHierarchyManager>();
  49. event_migration_hierarchy_manager_mock.Setup(e => e.GetLogicalTypeFromName(subscription.EventName)).Returns(expected_event.GetType());
  50. repository = new EventRepository(entity_context_mock.Object, event_converter_mock.Object, event_migration_hierarchy_manager_mock.Object);
  51. };
  52. Because of = () => result = repository.GetUnprocessedEventsForSubscriptions(new[] { subscription });
  53. It should_return_one_event = () => result.Count().ShouldEqual(1);
  54. }
  55. }