public IHttpActionResult ChangeQuantity([FromBody] SetQuantityModel model)
        {
            var cmd     = new SetProductQuantity(model.Id, model.Quantity);
            var product = _commandDispatcher.ExecuteCommand <ProductAggregate>(cmd);

            return(Ok(ProductModel.FromAggregate(product)));
        }
示例#2
0
        public async Task <IActionResult> SetQuantity([FromBody] SetProductQuantityModel model)
        {
            var useCase = new SetProductQuantity(model.Id, model.Quantity);
            var cmd     = new Command <SetProductQuantity>(useCase);

            var product = await _commandHandler.Execute <Product>(cmd);

            return(Ok(ProductModel.FromAggregateRoot(product)));
        }
示例#3
0
        public void When_SetProductQuantitySame_NothingHappens()
        {
            Given(
                new ProductCreated(id, "Test Product", 2),
                new ProductQuantityChanged(id, 2));

            var command = new SetProductQuantity(id, 2);

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

            When(command);

            Then(new IEvent[] { });
        }
示例#4
0
        public void When_SetProductQuantity_ProductQuantityChanged()
        {
            Given(new ProductCreated(id, "Test Product", 2));

            var command = new SetProductQuantity(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);
        }
示例#5
0
 internal void SetQuantity(SetProductQuantity cmd)
 {
     ChangeQuantity(cmd.Quantity);
 }