public void OnToDoFinished(ToDoFinishedV1 @event) { var toDo = _data.First(t => t.Id == @event.AggregateId); toDo.State = ToDoState.Finished; toDo.EndedAt = DateTime.Now; }
public void ItShouldFinishTheToDo() { 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), new ToDoStartedV1(toDoId, toDoListId) }; var toDo = new Domain.Write.ToDo.ToDo(toDoId, history.Count + 1, history); var @event = new ToDoFinishedV1(toDo.Id, toDoListId); toDo.When(@event); Assert.Equal(ToDoCurrentState.Finished, toDo.State.CurrentState); Assert.NotEqual(DateTime.MinValue, toDo.State.EndedAt); }
public void ItShouldNotFinishTheToDoIfTheToDoIsNotStarted() { var toDoListId = Guid.NewGuid(); var toDo = new Domain.Write.ToDo.ToDo(); var @event = new ToDoFinishedV1(toDo.Id, toDoListId); Assert.Throws <InvalidOperationException>(() => toDo.When(@event)); }
public async Task <Unit> Handle(FinishToDo request, CancellationToken cancellationToken) { var toDo = await _aggregateRepository.LoadAsync(request.ToDoId); var @event = new ToDoFinishedV1(toDo.Id, toDo.State.ToDoListId); toDo.When(@event); await _aggregateRepository.SaveAsync(toDo); return(Unit.Value); }
public Task Handle(ToDoFinishedV1 notification, CancellationToken cancellationToken) { When(notification); return(Task.CompletedTask); }