예제 #1
0
        public void When_AllProductsReserved_PrepareOrderForShipping()
        {
            var notificationId = Guid.NewGuid();

            AggregateRepository.CreateGuid = () => notificationId;
            SetupPreviousEvents();

            orderId = AddProcessedEvent <BasketAggregate>(new BasketCheckedOut(basketId, OrderLines, shippingAddress));
            AddProcessedEvent <OrderAggregate>(new OrderCreated(orderId, basketId, shippingAddress), orderId);
            AddProcessedEvent <ProductAggregate>(new ProductReserved(productOneId, 10), orderId);
            AddProcessedEvent <OrderAggregate>(new OrderLineAdded(orderId, OrderLines[0]), orderId);

            var nonProcessedEvent = new ProductReserved(productTwoId, 20);

            AddPreviousEvent <ProductAggregate>(nonProcessedEvent);
            SetInitalMetadata();

            Given(_initialEvents.ToArray());

            WhenProcessed(nonProcessedEvent);

            var expectedCommands = new List <ICommand> {
                new AddOrderLine(orderId, OrderLines[1]), new PrepareOrderForShipping(orderId)
            };
            var expectedEvents = new List <IEvent> {
                new EventProcessed(orderId, nonProcessedEvent)
            };

            SetMetadata(nonProcessedEvent, expectedCommands, expectedEvents);

            Then(expectedCommands.ToArray());
            Then(expectedEvents.ToArray());
        }
예제 #2
0
        public void When_ProductReserved_AddOrderLine()
        {
            SetupPreviousEvents();
            orderId = AddProcessedEvent <BasketAggregate>(new BasketCheckedOut(basketId, OrderLines, shippingAddress));
            AddProcessedEvent <OrderAggregate>(new OrderCreated(orderId, basketId, shippingAddress), orderId);

            var nonProcessedEvent = new ProductReserved(productTwoId, 20);

            AddPreviousEvent <ProductAggregate>(nonProcessedEvent);
            SetInitalMetadata();

            Given(_initialEvents.ToArray());

            WhenProcessed(nonProcessedEvent);

            var expectedCommands = new List <ICommand> {
                new AddOrderLine(orderId, OrderLines[1])
            };
            var expectedEvents = new List <IEvent> {
                new EventProcessed(orderId, nonProcessedEvent)
            };

            SetMetadata(nonProcessedEvent, expectedCommands, expectedEvents);

            Then(expectedCommands.ToArray());
            Then(expectedEvents.ToArray());
        }
예제 #3
0
        public IActionResult IndexPost()
        {
            List <int> lstCartItems = HttpContext.Session.Get <List <int> >("ssShoppingCart");

            ShoppingCartVM.Reservation.ReservationDate = ShoppingCartVM.Reservation.ReservationDate
                                                         .AddHours(ShoppingCartVM.Reservation.ReservationTime.Hour)
                                                         .AddMinutes(ShoppingCartVM.Reservation.ReservationTime.Minute);

            Reservation reservation = ShoppingCartVM.Reservation;

            _db.Reservation.Add(reservation);
            _db.SaveChanges();

            int reservationId = reservation.Id;

            foreach (int productId in lstCartItems)
            {
                ProductReserved productReserved = new ProductReserved()
                {
                    ReservationId = reservationId,
                    ProductId     = productId
                };

                _db.ProductReserved.Add(productReserved);
            }
            _db.SaveChanges();
            lstCartItems = new List <int>();
            HttpContext.Session.Set("ssShoppingCart", lstCartItems);

            return(RedirectToAction("ReservationConfirmation", "ShoppingCart", new{ Id = reservationId }));
        }
        private void OnProductReserved(ProductReserved evt)
        {
            var product = GetProduct(evt);

            product.Reserved       += evt.QuantityToReserve;
            product.LastEventNumber = evt.Metadata.EventNumber;
            _ctx.SaveChanges();
        }
예제 #5
0
        public void When_ReserveProduct_NewProductHasNewQuantity()
        {
            Given(InitialEvents);

            var command = new ReserveProduct(id, 3);

            command.Metadata.CausationId   = command.Metadata.CommandId;
            command.Metadata.CorrelationId = causationAndCorrelationId;

            When(command);

            var expectedEvent = new ProductReserved(id, 3);

            expectedEvent.Metadata.CausationId   = command.Metadata.CommandId;
            expectedEvent.Metadata.CorrelationId = causationAndCorrelationId;
            expectedEvent.Metadata.ProcessId     = command.Metadata.ProcessId;

            Then(expectedEvent);
        }
예제 #6
0
        private void Apply(ProductReserved evt)
        {
            // todo: if order not pending revoke reservation
            if (_state != OrderAggregate.OrderState.Pending)
            {
                DispatchCommand <ProductAggregate>(new CancelProductReservation(evt.AggregateId, evt.QuantityToReserve));
                return;
            }

            _reservations[evt.AggregateId] = true;


            var orderLine = _orderLines[evt.AggregateId];

            DispatchCommand <OrderAggregate>(new AddOrderLine(_orderId, orderLine));

            if (_reservations.All(x => x.Value))
            {
                DispatchCommand <OrderAggregate>(new PrepareOrderForShipping(_orderId));
            }
        }
예제 #7
0
 private void OnProductReserved(ProductReserved evt)
 {
     _orderProcessEventHandler.HandleEvent <ProductReserved, OrderProcessManager>(evt);
     SetLastEventNumber(evt);
 }
예제 #8
0
 private void Apply(ProductReserved evt)
 {
     Reserved += evt.QuantityToReserve;
 }