public void ItShouldResetTheToDo()
        {
            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),
                new ToDoFinishedV1(toDoId, toDoListId)
            };

            var toDo = new Domain.Write.ToDo.ToDo(toDoId, history.Count + 1, history);

            var @event = new ToDoResetedV1(toDo.Id, toDoListId);

            toDo.When(@event);

            Assert.Equal(ToDoCurrentState.Waiting, toDo.State.CurrentState);
            Assert.Equal(DateTime.MinValue, toDo.State.StartedAt);
            Assert.Equal(DateTime.MinValue, toDo.State.EndedAt);
        }
        public void OnToDoReseted(ToDoResetedV1 @event)
        {
            var toDo = _data.First(t => t.Id == @event.AggregateId);

            toDo.State     = ToDoState.Waiting;
            toDo.StartedAt = DateTime.MinValue;
            toDo.EndedAt   = DateTime.MinValue;
        }
        public void ItShouldNotResetTheToDoIfTheToDoDoesntExist()
        {
            var toDoListId = Guid.NewGuid();

            var toDo = new Domain.Write.ToDo.ToDo();

            var @event = new ToDoResetedV1(toDo.Id, toDoListId);

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
        public async Task <Unit> Handle(ResetToDo request, CancellationToken cancellationToken)
        {
            var toDo = await _aggregateRepository.LoadAsync(request.ToDoId);

            var @event = new ToDoResetedV1(toDo.Id, toDo.State.ToDoListId);

            toDo.When(@event);

            await _aggregateRepository.SaveAsync(toDo);

            return(Unit.Value);
        }
        public void ItShouldNotResetTheToDoIfTheToDoIsDeleted()
        {
            var          toDoId      = Guid.NewGuid();
            var          toDoListId  = Guid.NewGuid();
            const string label       = "My awesome ToDo label";
            const string description = "My awesome ToDo description";

            var history = new List <IEvent>
            {
                new ToDoAddedV1(toDoId, toDoListId, label, description),
                new ToDoDeletedV1(toDoId, toDoListId)
            };

            var toDo = new Domain.Write.ToDo.ToDo(toDoId, history.Count + 1, history);

            var @event = new ToDoResetedV1(toDo.Id, toDoListId);

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
Exemple #6
0
        public Task Handle(ToDoResetedV1 notification, CancellationToken cancellationToken)
        {
            When(notification);

            return(Task.CompletedTask);
        }