public void OnToDoAdded(ToDoAddedV1 @event)
 {
     _data.Add(new ToDo
     {
         Id          = @event.AggregateId,
         ToDoListId  = @event.Data.ToDoListId,
         Label       = @event.Data.Label,
         Description = @event.Data.Description
     });
 }
Exemplo n.º 2
0
        public async Task <Unit> Handle(AddToDo request, CancellationToken cancellationToken)
        {
            var toDo = await _aggregateRepository.LoadAsync(null);

            var @event = new ToDoAddedV1(toDo.Id, request.ToDoListId, request.Label, request.Description);

            toDo.When(@event);

            await _aggregateRepository.SaveAsync(toDo);

            return(Unit.Value);
        }
Exemplo n.º 3
0
        public void ItShouldNotAddAToDoWithANullDescription()
        {
            var toDo = new Domain.Write.ToDo.ToDo();

            var          toDoListId  = Guid.NewGuid();
            const string label       = "My awesome ToDo label";
            const string description = null;

            var @event = new ToDoAddedV1(toDo.Id, toDoListId, label, description);

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
Exemplo n.º 4
0
        public void ItShouldAddAToDo()
        {
            var toDo = new Domain.Write.ToDo.ToDo();

            var          toDoListId  = Guid.NewGuid();
            const string label       = "My awesome ToDo label";
            const string description = "My awesome ToDo description";

            var @event = new ToDoAddedV1(toDo.Id, toDoListId, label, description);

            toDo.When(@event);

            Assert.Equal(toDoListId, toDo.State.ToDoListId);
            Assert.Equal(label, toDo.State.Label);
            Assert.Equal(description, toDo.State.Description);
            Assert.Equal(ToDoCurrentState.Waiting, toDo.State.CurrentState);
        }
Exemplo n.º 5
0
        public void ItShouldNotAddAToDoIfTheToDoAlreadyExists()
        {
            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)
            };

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

            var @event = new ToDoAddedV1(toDo.Id, toDoListId, label, description);

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
Exemplo n.º 6
0
        public Task Handle(ToDoAddedV1 notification, CancellationToken cancellationToken)
        {
            When(notification);

            return(Task.CompletedTask);
        }