Example #1
0
        public void CanObserveSingleEventType()
        {
            // Arrange
            var commandDispatcher = new CartCommandDispatcher();
            var eventStore        = new CartEventStore(commandDispatcher.ObserveEventAggregate());

            // Act
            int         eventListenedCount = 0;
            SimpleEvent lastEvent          = null;

            eventStore.ObserveEvent <AddItemInCartCommand>()
            .Subscribe(@event =>
            {
                eventListenedCount++;
                lastEvent = @event;
            });

            commandDispatcher.Dispatch(new AddItemInCartCommand
            {
                ItemName = "Book",
                UnitCost = 45
            });
            commandDispatcher.Dispatch(new ResetCartCommand());

            // Assert
            Assert.Equal(1, eventListenedCount);
            Assert.IsType <AddItemInCartCommand>(lastEvent.Data);
        }
Example #2
0
        public void CanObserveMultipleEventsOfTheSameType()
        {
            // Arrange
            var commandDispatcher = new CartCommandDispatcher();
            var eventStore        = new CartEventStore(commandDispatcher.ObserveEventAggregate());

            // Act
            int eventListenedCount = 0;

            eventStore.ObserveEvent()
            .Subscribe(_ =>
            {
                eventListenedCount++;
            });

            commandDispatcher.Dispatch(new AddItemInCartCommand
            {
                ItemName = "Book",
                UnitCost = 45
            });
            commandDispatcher.Dispatch(new AddItemInCartCommand
            {
                ItemName = "Book",
                UnitCost = 20
            });

            // Assert
            Assert.Equal(2, eventListenedCount);
        }
Example #3
0
        public void CanDispatchEvent()
        {
            // Arrange
            var commandDispatcher = new CartCommandDispatcher();
            var eventStore        = new CartEventStore(commandDispatcher.ObserveEventAggregate());

            // Act
            commandDispatcher.Dispatch(new AddItemInCartCommand
            {
                ItemName = "Book",
                UnitCost = 45
            });

            // Assert
        }