Ejemplo n.º 1
0
        public async Task DispatcherShouldRegisterPipelineForMultipleEventsAsync()
        {
            var actWrapper = ActWrapper <Event> .From(nopAct);

            var eventTypes = new List <Type> {
                typeof(Event1), typeof(Event2)
            };
            var acts = new ActList {
                actWrapper.Act
            };

            dispatcher.RegisterPipeline(eventTypes, acts);

            Event1 event1 = new Event1 {
                Property = "event1"
            };

            dispatcher.Dispatch(event1);
            await actWrapper.ActTask;

            (actWrapper.Event as Event1).Property.ShouldBeEquivalentTo(event1.Property);

            actWrapper.Rearm();
            Event2 event2 = new Event2 {
                Property = "event2"
            };

            dispatcher.Dispatch(event2);
            await actWrapper.ActTask;

            (actWrapper.Event as Event2).Property.ShouldBeEquivalentTo(event2.Property);
        }
Ejemplo n.º 2
0
        public async Task DispatcherShouldRegisterMultiplePipelinesPerEventAsync()
        {
            var actWrapperForPipe1 = ActWrapper <Event> .From(nopAct);

            var actWrapperForPipe2 = ActWrapper <Event> .From(nopAct);

            var eventTypes = new List <Type> {
                typeof(Event1)
            };
            var actsForPipe1 = new ActList {
                actWrapperForPipe1.Act
            };
            var actsForPipe2 = new ActList {
                actWrapperForPipe2.Act
            };

            dispatcher.RegisterPipeline(eventTypes, actsForPipe1);
            dispatcher.RegisterPipeline(eventTypes, actsForPipe2);

            dispatcher.Dispatch(new Event1());
            await Task.WhenAll(new Task[] { actWrapperForPipe1.ActTask, actWrapperForPipe2.ActTask });

            actWrapperForPipe1.HasBeenCalled.Should().BeTrue();
            actWrapperForPipe2.HasBeenCalled.Should().BeTrue();
        }
Ejemplo n.º 3
0
        public async Task DispatcherShoulDispatchWithReconciliation()
        {
            var resolvedEvent = new ReconciliationEvent {
                Id = Guid.NewGuid()
            };
            var actWrapper = ActWrapper <Event>
                             .From((e, context) =>
            {
                resolvedEvent.ReconciliationId = (e as ReconciliationEvent).ReconciliationId;
                context.ReconciliationService.ResolveTask(resolvedEvent);
            });

            var eventTypes = new List <Type> {
                typeof(TestReconciliationEvent)
            };
            var acts = new ActList {
                actWrapper.Act
            };

            dispatcher.RegisterPipeline(eventTypes, acts);

            var originalEvent       = new TestReconciliationEvent();
            var reconciliationEvent = await dispatcher.DispatchWithReconciliation(originalEvent);

            reconciliationEvent.ShouldBeEquivalentTo(resolvedEvent);
        }
Ejemplo n.º 4
0
            public static ActWrapper <TEvent> From(Act <TEvent> act)
            {
                var actWrapper = new ActWrapper <TEvent>();

                actWrapper.HasBeenCalled = false;
                actWrapper.ActTask       = new Task(() => {});
                actWrapper.Act           = (e, context) =>
                {
                    actWrapper.Event           = e;
                    actWrapper.PipelineContext = context;
                    actWrapper.HasBeenCalled   = true;
                    act(e, context);
                    actWrapper.ActTask.RunSynchronously();
                };
                return(actWrapper);
            }
Ejemplo n.º 5
0
        public async Task DispatcherShouldDispatchEventToPipelineAsync()
        {
            var actWrapper = ActWrapper <Event> .From(nopAct);

            var actions = new ActList {
                actWrapper.Act
            };
            var eventTypes = new List <Type>
            {
                typeof(Event1)
            };

            dispatcher.RegisterPipeline(eventTypes, actions);
            dispatcher.Dispatch(new Event1());
            await actWrapper.ActTask;

            actWrapper.HasBeenCalled.Should().BeTrue();
        }
Ejemplo n.º 6
0
        public void Initialize()
        {
            dispatcherMock            = new Mock <IDispatcher>(MockBehavior.Strict);
            reconciliationServiceMock = new Mock <IReconciliationService>(MockBehavior.Strict);
            eventStoreMock            = new Mock <IEventStore>(MockBehavior.Strict);
            actWrapper = ActWrapper <Event> .From(nopAct);

            pipeline = new Pipeline(
                new List <Type> {
                typeof(Event)
            },
                new ActList {
                actWrapper.Act
            },
                dispatcherMock.Object,
                reconciliationServiceMock.Object,
                eventStoreMock.Object
                );
        }
Ejemplo n.º 7
0
        public async Task DispatcherShouldSaveEventAsync()
        {
            var actWrapper = ActWrapper <Event> .From(nopAct);

            var eventTypes = new List <Type> {
                typeof(Event1)
            };
            var acts = new ActList {
                actWrapper.Act
            };

            dispatcher.RegisterPipeline(eventTypes, acts);

            var originalEvent = new Event1();

            dispatcher.Dispatch(originalEvent);
            await actWrapper.ActTask;

            var savedEvent = await eventStore.Get <Event1>(actWrapper.Event.Id);

            savedEvent.Should().NotBeNull();
        }