public void Cannot_Delete_Nonexistent_Activity() { // Arrange - creating an activity var activity = new TimerActivity { Name = "Potato", ID = 2 }; // Arrange - create the mock repository var mock = new Mock <IRepository <TimerActivity> >(); mock.Setup(m => m.GetAll()).Returns(new[] { new TimerActivity { ID = 1, Name = "P1" }, new TimerActivity { ID = 3, Name = "P3" }, }.AsQueryable()); // Arrange - create a controller var target = new TimerController(mock.Object, null, null); // Act - delete the product target.DeleteActivity(activity.ID); // Assert - ensure that the repository delete method was // called with the correct Product mock.Verify(m => m.Delete(activity.ID)); Assert.Equal(2, mock.Object.GetAll().Count()); }