public void AccessToken_GetAll_ShouldContainsAll() { var data = new List <AccessToken>() { new AccessToken() { Device = new Device() { Id = Guid.NewGuid(), LastRequestDateTime = DateTime.Now }, UniqueAccesToken = Guid.NewGuid().ToString("D"), CreatedDateTime = DateTime.Now }, new AccessToken() { Device = new Device() { Id = Guid.NewGuid(), LastRequestDateTime = DateTime.Now }, UniqueAccesToken = Guid.NewGuid().ToString("D"), CreatedDateTime = DateTime.Now }, new AccessToken() { Device = new Device() { Id = Guid.NewGuid(), LastRequestDateTime = DateTime.Now }, UniqueAccesToken = Guid.NewGuid().ToString("D"), CreatedDateTime = DateTime.Now } }.AsQueryable(); var mockSet = new Mock <DbSet <AccessToken> >(); mockSet.As <IQueryable <AccessToken> >().Setup(m => m.Provider).Returns(data.Provider); mockSet.As <IQueryable <AccessToken> >().Setup(m => m.Expression).Returns(data.Expression); mockSet.As <IQueryable <AccessToken> >().Setup(m => m.ElementType).Returns(data.ElementType); mockSet.As <IQueryable <AccessToken> >().Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator()); var mockContext = new Mock <Models.Models.Database>(); mockContext.Setup(c => c.AccessTokens).Returns(mockSet.Object); AccessTokenService accTokService = new AccessTokenService(mockContext.Object); Assert.AreEqual(3, accTokService.GetAll().Count()); }