public void OnToDoStarted(ToDoStartedV1 @event) { var toDo = _data.First(t => t.Id == @event.AggregateId); toDo.State = ToDoState.Started; toDo.StartedAt = DateTime.Now; }
public void ItShouldNotStartTheToDoIfTheToDoIsNotWaiting() { var toDoListId = Guid.NewGuid(); var toDo = new Domain.Write.ToDo.ToDo(); var @event = new ToDoStartedV1(toDo.Id, toDoListId); Assert.Throws <InvalidOperationException>(() => toDo.When(@event)); }
public async Task <Unit> Handle(StartToDo request, CancellationToken cancellationToken) { var toDo = await _aggregateRepository.LoadAsync(request.ToDoId); var @event = new ToDoStartedV1(toDo.Id, toDo.State.ToDoListId); toDo.When(@event); await _aggregateRepository.SaveAsync(toDo); return(Unit.Value); }
public void ItShouldStartTheToDo() { var toDoId = Guid.NewGuid(); var toDoListId = Guid.NewGuid(); const string label = "My awesome ToDo label"; const string description = "My awesome ToDo description"; const string newLabel = "My awesome new ToDo label"; const string newDescription = "My awesome new ToDo description"; var history = new List <IEvent> { new ToDoAddedV1(toDoId, toDoListId, label, description), new ToDoUpdatedV1(toDoId, toDoListId, newLabel, newDescription) }; var toDo = new Domain.Write.ToDo.ToDo(toDoId, history.Count + 1, history); var @event = new ToDoStartedV1(toDo.Id, toDoListId); toDo.When(@event); Assert.Equal(ToDoCurrentState.Started, toDo.State.CurrentState); Assert.NotEqual(DateTime.MinValue, toDo.State.StartedAt); }
public Task Handle(ToDoStartedV1 notification, CancellationToken cancellationToken) { When(notification); return(Task.CompletedTask); }