public void create_and_update_inherit_aggregate_test() { var aggregateId = ObjectId.GenerateNewStringId(); var command = new CreateInheritTestAggregateCommand { AggregateRootId = aggregateId, Title = "Sample Note" }; //执行创建聚合根的命令 var commandResult = _commandService.ExecuteAsync(command).Result; Assert.IsNotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); var note = _memoryCache.GetAsync <InheritTestAggregate>(aggregateId).Result; Assert.IsNotNull(note); Assert.AreEqual("Sample Note", note.Title); Assert.AreEqual(1, ((IAggregateRoot)note).Version); //执行修改聚合根的命令 var command2 = new ChangeInheritTestAggregateTitleCommand { AggregateRootId = aggregateId, Title = "Changed Note" }; commandResult = _commandService.ExecuteAsync(command2).Result; Assert.IsNotNull(commandResult); Assert.AreEqual(CommandStatus.Success, commandResult.Status); note = _memoryCache.GetAsync <InheritTestAggregate>(aggregateId).Result; Assert.IsNotNull(note); Assert.AreEqual("Changed Note", note.Title); Assert.AreEqual(2, ((IAggregateRoot)note).Version); }
public async Task HandleAsync(ICommandContext context, ChangeInheritTestAggregateTitleCommand command) { var testAggregate = await context.GetAsync <InheritTestAggregate>(command.AggregateRootId); testAggregate.ChangeMyTitle(command.Title); }