public void Get_Rental_By_Id() { var dt = DateTime.Now; var rentals = new List <Rental>() { new Rental { Id = 111, Since = DateTime.Now, Until = DateTime.Now }, new Rental { Id = 222, Since = DateTime.Now, Until = dt }, new Rental { Id = 333, Since = DateTime.Now, Until = DateTime.Now } }.AsQueryable(); var mockDbSet = new Mock <DbSet <Rental> >(); mockDbSet.As <IQueryable <Rental> >().Setup(p => p.Provider).Returns(rentals.Provider); mockDbSet.As <IQueryable <Rental> >().Setup(p => p.Expression).Returns(rentals.Expression); mockDbSet.As <IQueryable <Rental> >().Setup(p => p.ElementType).Returns(rentals.ElementType); mockDbSet.As <IQueryable <Rental> >().Setup(p => p.GetEnumerator()).Returns(rentals.GetEnumerator); var mockContext = new Mock <RentalContext>(); mockContext.Setup(r => r.Rentals).Returns(mockDbSet.Object); var service = new RentalService(mockContext.Object); var rental = service.GetById(222); rental.Id.Should().Be(222); rental.Until.Should().Be(dt); }