Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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
        }