public void OnToDoUpdated(ToDoUpdatedV1 @event)
        {
            var toDo = _data.First(t => t.Id == @event.AggregateId);

            toDo.State       = ToDoState.Waiting;
            toDo.Label       = @event.Data.Label;
            toDo.Description = @event.Data.Description;
        }
示例#2
0
        public void ItShouldNotUpdateTheToDoIfTheToDoDoesntExist()
        {
            var          toDoListId     = Guid.NewGuid();
            const string newLabel       = "My awesome new ToDo label";
            const string newDescription = "My awesome new ToDo description";

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

            var @event = new ToDoUpdatedV1(toDo.Id, toDoListId, newLabel, newDescription);

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

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

            toDo.When(@event);

            await _aggregateRepository.SaveAsync(toDo);

            return(Unit.Value);
        }
示例#4
0
        public void ItShouldNotUpdateTheToDoWithANullDescription()
        {
            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 = null;

            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 ToDoUpdatedV1(toDo.Id, toDoListId, newLabel, newDescription);

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
示例#5
0
        public void ItShouldUpdateTheToDo()
        {
            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)
            };

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

            var @event = new ToDoUpdatedV1(toDo.Id, toDoListId, newLabel, newDescription);

            toDo.When(@event);

            Assert.Equal(newLabel, toDo.State.Label);
            Assert.Equal(newDescription, toDo.State.Description);
        }
示例#6
0
        public Task Handle(ToDoUpdatedV1 notification, CancellationToken cancellationToken)
        {
            When(notification);

            return(Task.CompletedTask);
        }