Ejemplo n.º 1
0
        public void UpdateItemSavesItemAndReturnsValidModel()
        {
            var itemToUpdate = new ToDoItem
            {
                ItemId  = 1,
                Title   = "Updated Item",
                DueDate = DateTime.Now,
                IsDone  = false
            };

            var existingEntityItem = new EntityModel.ToDoItem
            {
                ItemId      = itemToUpdate.ItemId,
                Title       = "Old Title",
                DueDate     = itemToUpdate.DueDate,
                IsCompleted = itemToUpdate.IsDone
            };

            var mockToDoDbSet = GetMockedDbSet(new [] { existingEntityItem });

            var mockContext = new Mock <IToDoContext>();

            mockContext.Setup(context => context.ToDoItems).Returns(mockToDoDbSet);

            var repository = new ToDoItemsRepository(mockContext.Object);

            var result = repository.UpdateItem(itemToUpdate).Result;

            mockContext.Verify(context => context.SaveChangesAsync(), Times.Once);
            Assert.AreEqual(itemToUpdate.Title, result.Title);
            Assert.AreEqual(itemToUpdate.DueDate, result.DueDate);
            Assert.AreEqual(itemToUpdate.IsDone, result.IsDone);
        }
Ejemplo n.º 2
0
        public void DeleteItemRemovesItem()
        {
            var existingEntityItem = new EntityModel.ToDoItem
            {
                ItemId      = 1,
                Title       = "Item 1",
                DueDate     = DateTime.Now,
                IsCompleted = false,
            };

            var mockToDoDbSet = GetMockedDbSet(new[] { existingEntityItem });

            var mockContext = new Mock <IToDoContext>();

            mockContext.Setup(context => context.ToDoItems).Returns(mockToDoDbSet);

            var repository = new ToDoItemsRepository(mockContext.Object);

            var result = repository.DeleteItem(existingEntityItem.ItemId);

            mockContext.Verify(context => context.SaveChangesAsync(), Times.Once);
        }
Ejemplo n.º 3
0
        public void UpdateItemStateSetsDoneStateCorrectlyOnItem()
        {
            var existingEntityItem = new EntityModel.ToDoItem
            {
                ItemId      = 1,
                Title       = "Item 1",
                DueDate     = DateTime.Now,
                IsCompleted = false,
            };

            var mockToDoDbSet = GetMockedDbSet(new[] { existingEntityItem });

            var mockContext = new Mock <IToDoContext>();

            mockContext.Setup(context => context.ToDoItems).Returns(mockToDoDbSet);

            var repository = new ToDoItemsRepository(mockContext.Object);

            var result = repository.UpdateItemState(existingEntityItem.ItemId).Result;

            mockContext.Verify(context => context.SaveChangesAsync(), Times.Once);
            Assert.AreNotSame(existingEntityItem.IsCompleted, result.IsDone);
        }