Example #1
0
        public void EventStoreShouldProcess20000EventsInLessThan1Second()
        {
            var result = String.Empty;

            var handlers = new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler((name) => result += "0"))
            };

            var eventBus   = new EventBus(DependencyServiceMock.GetMock(handlers));
            var eventStore = new EventStore(eventBus, new InMemoryEventStore(), PerformanceCounterMock.GetMock());

            Action act = () =>
            {
                for (var i = 0; i <= 19999; i++)
                {
                    var events = new List <IDomainEvent>()
                    {
                        new TestEvent(Guid.NewGuid())
                    };
                    eventStore.Save(events, -1);
                }
            };

            act.ExecutionTime().ShouldNotExceed(new TimeSpan(0, 0, 1));
        }
        public void QueryDispatcherShouldThrowExceptionIfHandlerNotFound()
        {
            DependencyServiceMock.SetMock(new DependencyDescriptor(typeof(IQueryHandler <TestQuery, Test>), null));

            var dispatcher = new QueryDispatcher(PerformanceCounterMock.GetMock());

            Action act = () => dispatcher.Execute(new TestQuery());

            act.Should().Throw <QueryDispatcherException>();
        }
Example #3
0
        public void EventBusShouldNotThrowAnExceptionWhenNoEventHandlerAvailable()
        {
            var result = String.Empty;

            var eventBus = new EventBus(DependencyServiceMock.GetMock(new List <DependencyDescriptor>()));

            eventBus.Publish(new TestEvent(Guid.NewGuid()));

            result.Should().Be("");
        }
Example #4
0
        public void CommandDispatcherShouldThrowExceptionIfHandlerNotFound()
        {
            var dispatcher =
                new CommandDispatcher(
                    DependencyServiceMock.GetMock(new DependencyDescriptor(typeof(ICommandHandler <TestCommand>), null)),
                    PerformanceCounterMock.GetMock());

            Action act = () => dispatcher.Execute(new TestCommand());

            act.ShouldThrow <CommandDispatcherException>();
        }
        public void QueryDispatcherShouldReturnObjectOfQueryHandler()
        {
            var resultObj = new Test(Guid.NewGuid());

            DependencyServiceMock.SetMock(new DependencyDescriptor(typeof(IQueryHandler <TestQuery, Test>),
                                                                   QueryHandlerMock.GetMock(resultObj)));

            var dispatcher = new QueryDispatcher(PerformanceCounterMock.GetMock());
            var result     = dispatcher.Execute(new TestQuery());

            result.Should().Equals(resultObj);
        }
Example #6
0
        public void EventStoreShouldNotThrowExceptionWhenFilterIsUsedOnEmptyEventList()
        {
            DependencyServiceMock.SetMock(new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler())
            });

            var eventBus   = new EventBus();
            var eventStore = new EventStore(eventBus, new InMemoryEventStore(), PerformanceCounterMock.GetMock());

            Action act = () => eventStore.GetEventsByAggregateId(Guid.NewGuid());

            act.Should().NotThrow();
        }
Example #7
0
        public void init()
        {
            DependencyServiceMock dependencyService = new DependencyServiceMock();

            // Use the testable stub for unit tests
            dependencyService.Register <IFileHelper>(new FileHelper());

            database = new Storage(dependencyService);

            foreach (Beleg beleg in database.GetBelege().Result)
            {
                database.RemoveBeleg(beleg).Wait();
            }
            Assert.AreEqual(0, database.GetBelege().Result.Length);
        }
        public void EventBusShouldCallTheRegisteredEventHandler()
        {
            var result = string.Empty;

            DependencyServiceMock.SetMock(new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler((name) => result = name))
            });

            var eventBus = new EventBus();

            eventBus.Publish(new TestEvent(Guid.NewGuid()));

            result.Should().Be("TestEvent");
        }
Example #9
0
        public void EventBusShouldCallTheRightEventHandler()
        {
            var result = String.Empty;

            var handlers = new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler((name) => result += name)),
                new DependencyDescriptor(typeof(IEventHandler <TestAlternativeEvent>),
                                         new TestAlternativeEventHandler((name) => result += name))
            };

            var eventBus = new EventBus(DependencyServiceMock.GetMock(handlers));

            eventBus.Publish(new TestAlternativeEvent(Guid.NewGuid()));

            result.Should().Be("TestAlternativeEvent");
        }
        public void EventBusShouldCallAnEventHandlerWhichReceivesSpecificEvents()
        {
            var result = string.Empty;

            DependencyServiceMock.SetMock(new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestAllSpecificEventHandler((name) => result += name)),
                new DependencyDescriptor(typeof(IEventHandler <TestAlternativeEvent>),
                                         new TestAllSpecificEventHandler(name => result += name))
            });

            var eventBus = new EventBus();

            eventBus.Publish(new TestAlternativeEvent(Guid.NewGuid()));
            eventBus.Publish(new TestEvent(Guid.NewGuid()));

            result.Should().Be("TestAlternativeEventTestEvent");
        }
Example #11
0
        public void EventStoreShouldSaveEventToInternalStorage()
        {
            DependencyServiceMock.SetMock(new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler())
            });

            var eventBus   = new EventBus();
            var eventStore = new EventStore(eventBus, new InMemoryEventStore(), PerformanceCounterMock.GetMock());

            var events = new List <IDomainEvent>()
            {
                new TestEvent(Guid.NewGuid())
            };

            eventStore.Save(events, -1);

            eventStore.GetEventsByAggregateId(events[0].AggregateId).Should().BeEquivalentTo(events[0]);
        }
Example #12
0
        public void EventStoreShouldPublishAllSavedEventsToTheEventBus()
        {
            var result = string.Empty;

            DependencyServiceMock.SetMock(new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler((name) => result = name))
            });

            var eventBus   = new EventBus();
            var eventStore = new EventStore(eventBus, new InMemoryEventStore(), PerformanceCounterMock.GetMock());

            var events = new List <IDomainEvent>()
            {
                new TestEvent(Guid.NewGuid())
            };

            eventStore.Save(events, -1);

            result.Should().Be("TestEvent");
        }
Example #13
0
        public void EventStoreShouldApplyTheFilterCorrectly()
        {
            var handlers = new List <DependencyDescriptor>
            {
                new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler())
            };

            var eventBus   = new EventBus(DependencyServiceMock.GetMock(handlers));
            var eventStore = new EventStore(eventBus, new InMemoryEventStore(), PerformanceCounterMock.GetMock());

            var aggregateId = Guid.NewGuid();
            var events      = new List <IDomainEvent>()
            {
                new TestEvent(aggregateId),
                new TestAlternativeEvent(Guid.NewGuid())
            };

            eventStore.Save(events, -1);

            eventStore.GetEventsByAggregateId(aggregateId).Should().BeEquivalentTo(events[0]);
        }