Beispiel #1
0
        public void Handle_should_update_product_names_on_stockItems()
        {
            var dateCreated = new DateTime(2011, 2, 15);

            var stockItems = new System.Collections.Generic.List <StockItem>()
            {
                StockItem.Create("Widget", "Small", dateCreated, "*****@*****.**"),
                StockItem.Create("Widget", "Medium", dateCreated, "*****@*****.**"),
                StockItem.Create("Widget", "Large", dateCreated, "*****@*****.**"),
                StockItem.Create("Gadget", "Small", dateCreated, "*****@*****.**"),
            };

            stockItemRepository.GetAllDelegate = () => stockItems.AsQueryable();

            var @event = new ProductNameChangedEvent("Widget", "Widget_Plus");

            handler.Handle(@event);

            stockItems[0].ProductName.ShouldEqual("Widget_Plus");
            stockItems[1].ProductName.ShouldEqual("Widget_Plus");
            stockItems[2].ProductName.ShouldEqual("Widget_Plus");
            stockItems[3].ProductName.ShouldEqual("Gadget");

            stockItems[2].History[1].Description.ShouldEqual("Product name changed from 'Widget' to 'Widget_Plus'");
        }
Beispiel #2
0
 public void Handle(ProductNameChangedEvent @event)
 {
     try
     {
         EventStore.Save(@event);
     }
     catch
     {
         throw;
     }
 }
Beispiel #3
0
        public async Task ChangeProductName(Guid productId, string name)
        {
            try
            {
                var product = await Repository.GetByKeyAsync <Product>(productId);

                product.ChangeName(name);

                await Repository.SaveChangesAsync();

                var @event = new ProductNameChangedEvent(productId, name);
                EventBus.RaiseEvent(@event);
            }
            catch
            {
                throw;
            }
        }
Beispiel #4
0
        public void Handler_should_update_orderLine_product_urlNames()
        {
            const string oldName = "Widget";
            const string newName = "Gadget";

            orderLineRepository.EntitesToReturnFromGetAll.Add(new OrderLine {
                ProductUrlName = oldName
            });
            orderLineRepository.EntitesToReturnFromGetAll.Add(new OrderLine {
                ProductUrlName = "some_other"
            });
            orderLineRepository.EntitesToReturnFromGetAll.Add(new OrderLine {
                ProductUrlName = oldName
            });

            var @event = new ProductNameChangedEvent(oldName, newName);

            handler.Handle(@event);

            orderLineRepository.EntitesToReturnFromGetAll[0].ProductUrlName.ShouldEqual("Gadget");
            orderLineRepository.EntitesToReturnFromGetAll[1].ProductUrlName.ShouldEqual("some_other");
            orderLineRepository.EntitesToReturnFromGetAll[2].ProductUrlName.ShouldEqual("Gadget");
        }