public void AddItems_GivenAListOfNewItems_AddsThemToDatabase() { // arrange List <OrderItem> items = new List <OrderItem>(); items.Add(new OrderItem() { ID = 30 }); items.Add(new OrderItem() { ID = 31 }); items.Add(new OrderItem() { ID = 32 }); items.Add(new OrderItem() { ID = 33 }); Mock <DbSet <OrderItem> > mockSet = new Mock <DbSet <OrderItem> >(); Mock <OrderDb> mockContext = new Mock <OrderDb>(); mockContext.Setup(c => c.OrderItems).Returns(mockSet.Object); OrderItemRepository sut = new OrderItemRepository(mockContext.Object); // act sut.AddItems(items); // assert mockSet.Verify(s => s.AddRange(It.Is <IEnumerable <OrderItem> >(l => l.Count() == 4)), Times.Once()); mockContext.Verify(c => c.SaveChanges(), Times.Once()); }