public When_car_name_changed() { When(async() => { var command = new ChangeCarNameCommand(FakeCarId, fakeName); _result = await The <IMediator>().Send(command); }); }
public async Task <IActionResult> PatchCar([FromRoute] Guid id, [FromBody] CarInputModel model) { var aggregateId = CarId.With(id); var command = new ChangeCarNameCommand(aggregateId, model.Name); var executionResult = await _aggregateManager.Ask <ExecutionResult>(command); if (executionResult.IsSuccess) { return(Accepted(new { Id = aggregateId.GetGuid() })); } return(BadRequest(executionResult.ToString())); }
private bool Handle(ChangeCarNameCommand command) { if (!IsNew) { Emit(new CarNameChangedEvent(command.Name)); Sender.Tell(new SuccessExecutionResult(), Self); } else { Sender.Tell(new FailedExecutionResult(new List <string> { "aggregate is not created" }), Self); } return(true); }
public async Task <Unit> Handle(ChangeCarNameCommand request, CancellationToken cancellationToken) => await UpdateAsync(new CarId(request.CarId), async car => Car.ChangeName(car, request.Name)) .MapAsync(_ => Unit.Value);