public void AddItemToDatabase() { var data = new List <Item>() { new Item(1, "Bord", 45, "152", "Kid"), new Item(2, "Bord1", 45, "185", "Male") }.AsQueryable(); var mockSet = new Mock <DbSet <Item> >(); mockSet.As <IQueryable <Item> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Item> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Item> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Item> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <SkiResortContext>(); mockContext.Setup(c => c.Items).Returns(mockSet.Object); var service = new RentalController(mockContext.Object); data.ToList().ForEach(t => service.Add(t)); }