Example #1
0
        public void GetById_ReturnsNotFound_ForInvalidId()
        {
            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase(databaseName: "ControllerTest")
                          .Options;

            var context    = new ToDoContext(options);
            var controller = new ToDoController(context);

            var result = controller.GetById(123);

            Assert.IsType <NotFoundResult>(result);
        }
Example #2
0
        public async void CanUpdateAToDoItem()
        {
            DbContextOptions <ToDoDbContext> options =
                new DbContextOptionsBuilder <ToDoDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (ToDoDbContext context = new ToDoDbContext(options))
            {
                ToDoItem item = new ToDoItem
                {
                    Name   = "test todo",
                    IsDone = true,
                    ListID = 1
                };
                ToDoList list = new ToDoList
                {
                    ID     = 1,
                    Name   = "test list",
                    IsDone = true
                };

                ToDoListController tdlc = new ToDoListController(context);
                await tdlc.Create(list);

                ToDoController tdc = new ToDoController(context);
                await tdc.Create(item);

                ToDoItem update = new ToDoItem
                {
                    ID     = item.ID,
                    Name   = "todo test",
                    IsDone = false,
                    ListID = item.ListID
                };

                await tdc.Update(item.ID, update);

                var findItem = await tdc.GetById(update.ID);

                var result   = (ObjectResult)findItem.Result;
                var readItem = (ToDoItem)result.Value;


                Assert.Equal(update.Name, readItem.Name);
            }
        }
Example #3
0
        public void GetById_ReturnsToDoItem_ForTheGivenId()
        {
            var options = new DbContextOptionsBuilder <ToDoContext>()
                          .UseInMemoryDatabase(databaseName: "ControllerTest")
                          .Options;

            var      context  = new ToDoContext(options);
            ToDoItem new_item = new ToDoItem {
                Name = "New_Item"
            };

            context.ToDoItems.Add(new_item);

            var controller = new ToDoController(context);

            var result = controller.GetById(new_item.Id);

            var okResult   = Assert.IsType <ObjectResult>(result);
            var returnItem = Assert.IsType <ToDoItem>(okResult.Value);

            Assert.Equal("New_Item", returnItem.Name);
        }