public async Task AppliesOptionsToQueryAsync() { var session = Substitute.For <ISessionImplementor>(); session.Factory.Settings.Returns(new Settings()); var query = Substitute.For <IQuery>(); query.ListAsync().Returns(Task.FromResult((IList) new List <Order>())); session.CreateQuery(Arg.Any <IQueryExpression>()).Returns(query); var queryable = new NhQueryable <Order>(session) .WithOptions( x => x .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("testregion") .SetTimeout(10) ); var t = await(queryable.ToListAsync()); query.Received(1).SetCacheable(true); query.Received(1).SetCacheMode(CacheMode.Normal); query.Received(1).SetCacheRegion("testregion"); query.Received(1).SetTimeout(10); // Prevent garbage collection of session substitute before end of test, since the Linq query provider // only has a weak reference on it. Assert.That(session, Is.Not.Null); }
public void DoNotContaminateQueryWithOptions() { var session = Substitute.For <ISessionImplementor>(); session.Factory.Settings.Returns(new Settings()); var query = Substitute.For <IQuery>(); query.List().Returns(new List <Order>()); session.CreateQuery(Arg.Any <IQueryExpression>()).Returns(query); var queryable = new NhQueryable <Order>(session); var o1 = queryable .WithOptions( x => x .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("testregion") .SetTimeout(10) ).ToList(); var o2 = queryable.ToList(); query.Received(1).SetCacheable(true); query.Received(1).SetCacheMode(CacheMode.Normal); query.Received(1).SetCacheRegion("testregion"); query.Received(1).SetTimeout(10); // Prevent garbage collection of session substitute before end of test, since the Linq query provider // only has a weak reference on it. Assert.That(session, Is.Not.Null); }
public async Task AppliesOptionsToQueryAsync() { var session = Substitute.For <ISessionImplementor>(); session.Factory.Settings.Returns(new Settings()); var query = Substitute.For <IQuery>(); query.ListAsync().Returns(Task.FromResult((IList) new List <Order>())); session.CreateQuery(Arg.Any <IQueryExpression>()).Returns(query); var queryable = new NhQueryable <Order>(session) .WithOptions( x => x .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("testregion") .SetTimeout(10) ); var t = await(queryable.ToListAsync()); query.Received(1).SetCacheable(true); query.Received(1).SetCacheMode(CacheMode.Normal); query.Received(1).SetCacheRegion("testregion"); query.Received(1).SetTimeout(10); }
public void DoNotContaminateQueryWithOptions() { var session = Substitute.For <ISessionImplementor>(); session.Factory.Settings.Returns(new Settings()); var query = Substitute.For <IQuery>(); query.List().Returns(new List <Order>()); session.CreateQuery(Arg.Any <IQueryExpression>()).Returns(query); var queryable = new NhQueryable <Order>(session); var o1 = queryable .WithOptions( x => x .SetCacheable(true) .SetCacheMode(CacheMode.Normal) .SetCacheRegion("testregion") .SetTimeout(10) ).ToList(); var o2 = queryable.ToList(); query.Received(1).SetCacheable(true); query.Received(1).SetCacheMode(CacheMode.Normal); query.Received(1).SetCacheRegion("testregion"); query.Received(1).SetTimeout(10); }
public IQueryable <T> CreateQuery <T>(Expression expression) { var newQuery = new NhQueryable <T>(this, expression); if (!typeof(T).IsAssignableFrom(Type)) //Select and other methods that returns other types { throw new NotSupportedException("IncludeQueryProvider does not support mixing types"); } Type = typeof(T); //Possbile typecast to a base type return(newQuery); }
private static ISession GetSession <TResult>(NhQueryable <TResult> nhQueryable) { var queryProvider = nhQueryable.Provider; return(ReflectionUtilities.GetValueForProperty <ISession>(queryProvider, "Session")); }
public NhQueryableAdaptor(NhQueryable <T> queryable) { this.queryable = queryable; }
public static void Verify <T>(NhQueryable <T> queryable) { DatabaseApprovals.Verify(new NhQueryableAdaptor <T>(queryable)); }