public void ItShouldDeleteTheToDo() { 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, Guid.Empty, label, description), new ToDoUpdatedV1(toDoId, toDoListId, newLabel, newDescription), new ToDoStartedV1(toDoId, toDoListId), new ToDoFinishedV1(toDoId, toDoListId), new ToDoResetedV1(toDoId, toDoListId) }; var toDo = new Domain.Write.ToDo.ToDo(toDoId, history.Count + 1, history); var @event = new ToDoDeletedV1(toDo.Id, toDoListId); toDo.When(@event); Assert.Equal(ToDoCurrentState.Deleted, toDo.State.CurrentState); }
public void ItShouldNotDeleteTheToDoIfTheToDoDoesntExist() { var toDo = new Domain.Write.ToDo.ToDo(); var toDoListId = Guid.NewGuid(); var @event = new ToDoDeletedV1(toDo.Id, toDoListId); Assert.Throws <InvalidOperationException>(() => toDo.When(@event)); }
public async Task <Unit> Handle(DeleteToDo request, CancellationToken cancellationToken) { var toDo = await _aggregateRepository.LoadAsync(request.ToDoId); var @event = new ToDoDeletedV1(toDo.Id, toDo.State.ToDoListId); toDo.When(@event); await _aggregateRepository.SaveAsync(toDo); return(Unit.Value); }
public void OnToDoDeleted(ToDoDeletedV1 @event) { var toDo = _data.First(t => t.Id == @event.AggregateId); _data.Remove(toDo); }
public Task Handle(ToDoDeletedV1 notification, CancellationToken cancellationToken) { When(notification); return(Task.CompletedTask); }