コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }