Beispiel #1
0
        public async Task Test_Updating_The_ToDo_Title_Completed_Order()
        {
            /*
             *  Given that I have a command to update a ToDo's title, complete, & order
             *  When I handle that command
             *  Then I should update the ToDo
             *
             */

            const string NEW_TITLE     = "New Title";
            const bool   NEW_COMPLETED = false;
            const int    NEW_ORDER     = 523;

            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase("order_title_completed_writes_to_database")
                          .Options;

            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem {
                Title = "Title", Completed = true, Order = 10
            };

            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, NEW_TITLE, NEW_COMPLETED, NEW_ORDER);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(NEW_TITLE, context.ToDoItems.Single().Title);
                Assert.AreEqual(NEW_COMPLETED, context.ToDoItems.Single().Completed);
                Assert.AreEqual(NEW_ORDER, context.ToDoItems.Single().Order);
            }

            // Should not send task complete event
            Assert.IsFalse(fakeCommandProcessor.SentCompletedEvent);
        }
Beispiel #2
0
        public async Task Test_Updating_a_ToDo_Title_and_Completed()
        {
            /*
             *  Given that I have a command to pdate add a ToDo's Title and Completed
             *  When I handle that command
             *  Then I should update the ToDo
             *
             */

            const string TODO_TITLE = "test_title";

            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase("titlecompleted_writes_to_database")
                          .Options;

            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem {
                Title = "This title will be changed"
            };

            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, TODO_TITLE, true);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(TODO_TITLE, context.ToDoItems.Single().Title);
                Assert.AreEqual(true, context.ToDoItems.Single().Completed);
            }

            // Has sent task complete event
            Assert.IsTrue(fakeCommandProcessor.SentCompletedEvent);
        }
Beispiel #3
0
        public async Task Test_Updating_The_ToDo_Order()
        {
            /*
                Given that I have a command to update a ToDo's complete
                When I handle that command
                Then I should update the ToDo

            */

            const int NEW_ORDER = 523;

            var options = new DbContextOptionsBuilder<ToDoContext>()
                .UseInMemoryDatabase(databaseName: "order_writes_to_database")
                .Options;
            
            var fakeCommandProcessor = new FakeCommandProcessor();

            var toDoItem = new ToDoItem() { Title = "This title won't be changed", Completed = true, Order = 10};
            using (var context = new ToDoContext(options))
            {
                context.ToDoItems.Add(toDoItem);
                context.SaveChanges();
            }


            var command = new UpdateToDoCommand(toDoItem.Id, order: NEW_ORDER);
            var handler = new UpdateToDoCommandHandlerAsync(options, fakeCommandProcessor);

            await handler.HandleAsync(command);

            using (var context = new ToDoContext(options))
            {
                Assert.AreEqual(1, context.ToDoItems.Count());
                Assert.AreEqual(toDoItem.Title, context.ToDoItems.Single().Title);
                Assert.AreEqual(true, context.ToDoItems.Single().Completed);
                Assert.AreEqual(NEW_ORDER, context.ToDoItems.Single().Order);
            }

            // Should not send task complete event
            Assert.IsFalse(fakeCommandProcessor.SentCompletedEvent);
        }