Пример #1
0
        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);
        }
Пример #2
0
        public void ItShouldNotApplyAnUnsupportedEvent()
        {
            var toDo = new Domain.Write.ToDo.ToDo();

            var @event = new MyCustomEvent(toDo.Id, new MyCustomEventData());

            Assert.Throws <InvalidOperationException>(() => toDo.When(@event));
        }
Пример #3
0
        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));
        }
Пример #4
0
        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));
        }
Пример #5
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));
        }
Пример #6
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));
        }
Пример #7
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);
        }
Пример #8
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));
        }
Пример #9
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);
        }
Пример #10
0
        public void ItShouldStartTheToDo()
        {
            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)
            };

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

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

            toDo.When(@event);

            Assert.Equal(ToDoCurrentState.Started, toDo.State.CurrentState);
            Assert.NotEqual(DateTime.MinValue, toDo.State.StartedAt);
        }