public void AddItemSetsItemAsOverDueIfDueDateIsBeforeToday() { var itemToAdd = new ToDoItem { Title = "New Item", DueDate = new DateTime(1900, 12, 30), }; var mockContext = new Mock <IToDoContext>(); mockContext.Setup(context => context.ToDoItems.Add(It.IsAny <EntityModel.ToDoItem>())) .Returns(new EntityModel.ToDoItem()); var repository = new ToDoItemsRepository(mockContext.Object); var result = repository.AddItem(itemToAdd).Result; mockContext.Verify(context => context.ToDoItems.Add(It.IsAny <EntityModel.ToDoItem>()), Times.Once); mockContext.Verify(context => context.SaveChangesAsync(), Times.Once); Assert.IsFalse(result.IsDone); Assert.IsTrue(result.IsOverDue); }
public void AddItemSavesItemAndReturnsValidModel() { var itemToAdd = new ToDoItem { Title = "New Item", DueDate = new DateTime(2020, 12, 30), }; var mockContext = new Mock <IToDoContext>(); mockContext.Setup(context => context.ToDoItems.Add(It.IsAny <EntityModel.ToDoItem>())) .Returns(new EntityModel.ToDoItem()); var repository = new ToDoItemsRepository(mockContext.Object); var result = repository.AddItem(itemToAdd).Result; mockContext.Verify(context => context.ToDoItems.Add(It.IsAny <EntityModel.ToDoItem>()), Times.Once); mockContext.Verify(context => context.SaveChangesAsync(), Times.Once); Assert.AreEqual(itemToAdd.Title, result.Title); Assert.AreEqual(itemToAdd.DueDate, result.DueDate); Assert.IsFalse(result.IsDone); Assert.IsFalse(result.IsOverDue); }