Ejemplo n.º 1
0
        public async void CanRemoveToDoItemsFromAToDoList()
        {
            DbContextOptions <ToDoDbContext> options =
                new DbContextOptionsBuilder <ToDoDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (ToDoDbContext context = new ToDoDbContext(options))
            {
                ToDoList list = new ToDoList
                {
                    ID     = 1,
                    Name   = "test list",
                    IsDone = true
                };
                ToDoListController tdlc = new ToDoListController(context);
                await tdlc.Create(list);

                ToDoList result = context.ToDoLists.Find(list.ID);
                Assert.Equal("test list", result.Name);

                ToDoItem item = new ToDoItem
                {
                    ID     = 1,
                    Name   = "test todo",
                    IsDone = true,
                    ListID = 1
                };
                ToDoItem item2 = new ToDoItem
                {
                    ID     = 2,
                    Name   = "to test do",
                    IsDone = false,
                    ListID = 1
                };

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

                await tdc.Create(item2);

                await tdc.Delete(item.ID);

                await tdc.Delete(item2.ID);

                var      viewItems = tdlc.GetById(list.ID).Result;
                var      r         = (ObjectResult)viewItems.Result;
                ToDoList todoItems = (ToDoList)r.Value;
                Assert.Empty(todoItems.ToDoItems);
            }
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 3
0
        public void CanCreateAToDoList()
        {
            DbContextOptions <ToDoDbContext> options =
                new DbContextOptionsBuilder <ToDoDbContext>()
                .UseInMemoryDatabase(Guid.NewGuid().ToString())
                .Options;

            using (ToDoDbContext context = new ToDoDbContext(options))
            {
                ToDoList list = new ToDoList
                {
                    Name   = "test list",
                    IsDone = true
                };

                ToDoListController tdlc = new ToDoListController(context);
                var result = tdlc.Create(list).Result;
                var r      = (ObjectResult)result;
                var status = r.StatusCode.Value;

                Assert.Equal(HttpStatusCode.Created, (HttpStatusCode)status);
            }
        }