public void On(StartStockingProduct cmd)
        {
            if (!BarcodeLengthIsCorrect(cmd.Barcode))
            {
                throw new InvalidBarcodeException(cmd.Barcode);
            }

            if (!NameIsValid(cmd.Name))
            {
                throw new ProductStockingException(cmd);
            }

            EventRouter.FireEventOnAggregate<ProductAggregate>(new NewProductAddedToWarehouse(cmd.AggregateIdentity,
                                                                                              cmd.ItemCode, cmd.Name,
                                                                                              cmd.Description,
                                                                                              cmd.Barcode));
        }
Example #2
0
        public void Setup()
        {
            Core.Reset();
            Core.Instance
                .WithDomainNamespaceRoot("Cuttlefish.ExampleApp.Domain")
                .UseInMemoryEventStore()
                .Done();

            _productName = "Widget X";
            _description = "blah blah blah";
            _itemcode = "X0001";
            _barcode = "123456";
            var newProductCommand = new StartStockingProduct(Guid.NewGuid(), _itemcode, _productName, _description,
                                                             _barcode);
            CommandRouter.ExecuteCommand(newProductCommand);

            _productId = newProductCommand.AggregateIdentity;
        }
Example #3
0
 public void WarehouseThrowsExceptionWhenNewProductNameIsBlank()
 {
     var newProductCommand = new StartStockingProduct(Guid.NewGuid(), _itemcode, string.Empty, _description,
                                                      _barcode);
     CommandRouter.ExecuteCommand(newProductCommand);
 }
Example #4
0
 public void WarehouseThrowsExceptionWhenInvalidBarcodeIsSelectedForNewProduct()
 {
     var newProductCommand = new StartStockingProduct(Guid.NewGuid(), _itemcode, _productName, _description,
                                                      "invalid barcode");
     CommandRouter.ExecuteCommand(newProductCommand);
 }