public void Can_GetAuthorizationsByLicenseId_Test() { var data = new List <Authorization> { new Authorization { Key = "3334 6879 1616 5989", Status = Status.Authorized, Quantity = 1, DateCreated = DateTime.Now, LicenseId = 1 }, new Authorization { Key = "6339 0924 3636 2969", Status = Status.Activated, Quantity = 1, DateCreated = DateTime.Now, LicenseId = 7 }, new Authorization { Key = "32062 7182 9649 9435", Status = Status.Authorized, Quantity = 1, DateCreated = DateTime.Now, LicenseId = 3 } }.AsQueryable(); var mockSet = new Mock <DbSet <Authorization> >(); mockSet.As <IQueryable <Authorization> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <Authorization> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <Authorization> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <Authorization> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <LicensingContext>(); mockContext.Setup(c => c.Authorizations).Returns(mockSet.Object); mockContext.Setup(m => m.Set <Authorization>()).Returns(mockSet.Object); var authorizationRepo = new AuthorizationRepository(mockContext.Object); var result = authorizationRepo.GetAuthorizationsByLicenseId(3); Assert.AreEqual(1, result.Count()); }