public void ComponentTypeService_LookupAsync_ReturnsNoRecordsIfNotActive() { // Arrange var mockDbContextScopeFac = new Mock<IDbContextScopeFactory>(); var mockDbContextScope = new Mock<IDbContextReadOnlyScope>(); var mockEfDbContext = new Mock<EFDbContext>(); mockDbContextScopeFac.Setup(x => x.CreateReadOnly(DbContextScopeOption.JoinExisting)).Returns(mockDbContextScope.Object); mockDbContextScope.Setup(x => x.DbContexts.Get<EFDbContext>()).Returns(mockEfDbContext.Object); var dbEntry1 = new ComponentType { Id = "dummyEntryId1", CompTypeName = "Name1", CompTypeAltName = "NameAlt1", IsActive_bl = false }; var dbEntry2 = new ComponentType { Id = "dummyEntryId2", CompTypeName = "Name2", CompTypeAltName = "NameAlt2", IsActive_bl = true }; var dbEntry3 = new ComponentType { Id = "dummyEntryId3", CompTypeName = "Name3", CompTypeAltName = "NameAlt3", IsActive_bl = true }; var dbEntries = (new List<ComponentType> { dbEntry1, dbEntry2, dbEntry3 }).AsQueryable(); var mockDbSet = new Mock<DbSet<ComponentType>>(); mockDbSet.As<IDbAsyncEnumerable<ComponentType>>().Setup(m => m.GetAsyncEnumerator()).Returns(new MockDbAsyncEnumerator<ComponentType>(dbEntries.GetEnumerator())); mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.Provider).Returns(new MockDbAsyncQueryProvider<ComponentType>(dbEntries.Provider)); mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.Expression).Returns(dbEntries.Expression); mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.ElementType).Returns(dbEntries.ElementType); mockDbSet.As<IQueryable<ComponentType>>().Setup(m => m.GetEnumerator()).Returns(dbEntries.GetEnumerator()); mockEfDbContext.Setup(x => x.ComponentTypes).Returns(mockDbSet.Object); var compTypeService = new ComponentTypeService(mockDbContextScopeFac.Object, "dummyUserId"); //Act var returnedComponentTypes = compTypeService.LookupAsync("NameAlt1", true).Result; //Assert Assert.IsTrue(returnedComponentTypes.Count == 0); }