public void EventStoreShouldProcess20000EventsInLessThan1Second() { var result = string.Empty; DependencyServiceMock.SetMock(new List <DependencyDescriptor> { new DependencyDescriptor(typeof(IEventHandler <TestEvent>), new TestEventHandler((name) => result += "0")) }); var eventBus = new EventBus(); 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().Should().BeLessOrEqualTo(new TimeSpan(0, 0, 1)); }
public void PerformanceMeasurementShouldBeWorkingMultiThreaded() { var service = PerformanceCounterMock.GetMock(); var thread1 = new Thread(() => { for (var i = 0; i < 100; i++) { service.CountCommand(Convert.ToInt64(new TimeSpan(0, 0, 0, 0, 1000).TotalMilliseconds)); } }); var thread2 = new Thread(() => { for (var i = 0; i < 100; i++) { service.CountCommand(Convert.ToInt64(new TimeSpan(0, 0, 0, 0, 1000).TotalMilliseconds)); } }); thread1.Start(); thread2.Start(); thread1.Join(); thread2.Join(); var results = service.GetResults().ToDictionary(r => r.Key, r => r); results["Total Commands"].Value.Should().Be(200); results["Average Commands Duration (ms)"].Value.Should().Be(1000); }
public void PerformanceMeasurementShouldNotThrowIfNoResultsAreAvailable() { var service = PerformanceCounterMock.GetMock(); Action act = () => service.GetResults(); act.ShouldNotThrow(); }
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>(); }
public void PerformanceMeasurementShouldCalculateSnapshotCountersCorrectly() { var service = PerformanceCounterMock.GetMock(); service.CountSnapshot(); service.CountSnapshot(); var results = service.GetResults().ToDictionary(r => r.Key, r => r); results["Total Snapshots"].Value.Should().Be(2); }
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 PerformanceMeasurementShouldCalculateCommandCountersCorrectly() { var service = PerformanceCounterMock.GetMock(); service.CountCommand(Convert.ToInt64(new TimeSpan(0, 0, 0, 0, 1000).TotalMilliseconds)); service.CountCommand(Convert.ToInt64(new TimeSpan(0, 0, 0, 0, 1000).TotalMilliseconds)); var results = service.GetResults().ToDictionary(r => r.Key, r => r); results["Total Commands"].Value.Should().Be(2); results["Average Commands Duration (ms)"].Value.Should().Be(1000); }
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); }
public void TimeMeasureShouldWorkInConjunctionWithPerformanceService() { var service = PerformanceCounterMock.GetMock(); using (new TimeMeasure(ms => service.CountCommand(ms))) { Thread.Sleep(500); } var results = service.GetResults().ToDictionary(r => r.Key, r => r); results["Total Commands"].Value.Should().Be(1); results["Average Commands Duration (ms)"].Value.Should().BeApproximately(500, 5); }
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(); }
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]); }
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"); }
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]); }