public void UsingIncludeInOfTypeObjectSet_Test() { //Arrange List <Product> products = new List <Product>() { new Product() { ProductId = 1, Description = "Description 1" }, new Software() { ProductId = 2, Description = "Description 2", LicenseCode = "A01" }, new Software() { ProductId = 3, Description = "Description 3", LicenseCode = "A02" }, }; //Act MemorySet <Product> productSet = products.ToMemorySet <Product>(); IQueryable <Software> softwareSet = productSet.OfType <Product, Software>() .Include("SoftwareData"); //Assert List <string> actual = new PrivateObject(softwareSet).GetField("_IncludePaths") as List <string>; Assert.IsTrue(actual.Where(s => s == "SoftwareData").Count() == 1); }
/// <summary> /// OfType extension method for IQueryable. This /// method is only for supporting mock OfType /// </summary> /// <typeparam name="KEntity">The type to filter the elements of the sequence on. </typeparam> /// <param name="queryable">The queryable object</param> /// <returns> /// A new IQueryable hat contains elements from /// the input sequence of type TResult /// </returns> public static IQueryable <KEntity> OfType <TEntity, KEntity>(this IQueryable <TEntity> queryable) where TEntity : class where KEntity : class, TEntity { ObjectQuery <TEntity> query = queryable as ObjectQuery <TEntity>; if (query != null) //if is a EF ObjectQuery object { return(query.OfType <KEntity>()); } else { //a fake or in memory object set for testing MemorySet <TEntity> fakeQuery = queryable as MemorySet <TEntity>; return(fakeQuery.OfType <KEntity>()); } }