Beispiel #1
0
        public Product AddProductToStock(AddProductToStock data)
        {
            var prod = Get(data.ProductId);

            if (prod == null)
            {
                return(null);
            }
            prod.Stock += data.Quantity;
            Update(prod, data.ProductId);
            return(prod);
        }
Beispiel #2
0
        public void When_AddProductToStockZero_NothingHappens()
        {
            Given(new ProductCreated(id, "Test Product", 2));

            var command = new AddProductToStock(id, 0);

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

            When(command);

            Then(new IEvent[] { });
        }
Beispiel #3
0
        public void When_AddProductToStock_ProductQuantityChanged()
        {
            Given(new ProductCreated(id, "Test Product", 2));

            var command = new AddProductToStock(id, 5);

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

            When(command);

            var expectedEvent = new ProductQuantityChanged(id, 5);

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

            Then(expectedEvent);
        }
Beispiel #4
0
        public OperationResult <Product> AddProductToStock(AddProductToStock data)
        {
            try
            {
                var prod = _productRepository.AddProductToStock(data);

                return(new OperationResult <Product>
                {
                    IsSuccess = prod != null,
                    Result = prod,
                    ErrorMessage = prod == null? "Product not found, review id":""
                });
            }
            catch (Exception e)
            {
                return(new OperationResult <Product>
                {
                    ErrorCode = 500,
                    ErrorMessage = e.Message,
                    IsSuccess = false
                });
            }
        }
Beispiel #5
0
        internal void AddToStock(AddProductToStock cmd)
        {
            var newQuantity = Quantity + cmd.Quantity;

            ChangeQuantity(newQuantity);
        }