Exemplo n.º 1
0
        public void TestPopulatesCriteriaCacheableCachRegionAndCacheModeProperly()
        {
            IImmediateFlowQuery <CacheableUser> query = Session.FlowQuery <CacheableUser>()
                                                        .Cacheable("Region1", CacheMode.Put);

            var criteria = (CriteriaImpl) new CriteriaBuilder()
                           .Build <CacheableUser, CacheableUser>
                           (
                QuerySelection.Create(query as IQueryableFlowQuery)
                           );

            Assert.That(criteria.Cacheable, Is.True);
            Assert.That(criteria.CacheRegion, Is.EqualTo("Region1"));

            Type type = typeof(CriteriaImpl);

            FieldInfo field = type.GetField("cacheMode", BindingFlags.Instance | BindingFlags.NonPublic);

            Assert.That(field, Is.Not.Null, "FieldInfo");

            object mode = field
                          .GetValue(criteria);

            Assert.That(mode, Is.EqualTo(CacheMode.Put));
        }
Exemplo n.º 2
0
        public void TestPopulatesCriteriaCacheableProperly()
        {
            IImmediateFlowQuery <CacheableUser> query = Session.FlowQuery <CacheableUser>()
                                                        .Cacheable();

            var criteria = (CriteriaImpl) new CriteriaBuilder()
                           .Build <CacheableUser, CacheableUser>
                           (
                QuerySelection.Create(query as IQueryableFlowQuery)
                           );

            Assert.That(criteria.Cacheable, Is.True);
        }
Exemplo n.º 3
0
        public void ReadOnlyTrueIsPopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .ReadOnly();

            var queryable = (IQueryableFlowQuery)query;

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(queryable));

            Assert.That(criteria, Is.Not.Null);
            Assert.That(criteria.IsReadOnlyInitialized, Is.True, "Initialized");
            Assert.That(criteria.IsReadOnly, Is.True, "ReadOnly");
        }
Exemplo n.º 4
0
        public void CanCreateDelayedFlowQueryWithOptions()
        {
            FlowQueryOptions options = new FlowQueryOptions()
                                       .Add(c => c.SetMaxResults(5));

            IDelayedFlowQuery <UserEntity> q = Session.DelayedFlowQuery <UserEntity>(options);

            Assert.That(q, Is.Not.Null);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(q as IQueryableFlowQuery));

            Assert.That(criteria.GetRootEntityTypeIfAvailable(), Is.EqualTo(typeof(UserEntity)));
        }
Exemplo n.º 5
0
        public void SpecifiedTimeoutIsUsedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Timeout(10);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.Timeout, Is.EqualTo(10));
        }
        public void CanCreateStatelessDelayedFlowQueryWithAlias()
        {
            UserEntity alias = null;

            Assert.That(() => StatelessSession.DelayedFlowQuery(() => alias), Throws.Nothing);

            IDelayedFlowQuery <UserEntity> query = StatelessSession.DelayedFlowQuery(() => alias);

            Assert.That(query != null);

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create(query as IQueryableFlowQuery));

            Assert.That(criteria.Alias, Is.EqualTo("alias"));
        }
Exemplo n.º 7
0
        public void FetchSizeIsPopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .FetchSize(10);

            var queryable = (IQueryableFlowQuery)query;

            Assert.That(queryable.FetchSizeValue, Is.EqualTo(10));

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.FetchSize, Is.EqualTo(10));
        }
Exemplo n.º 8
0
        public void CommentIsPopulatedOnCriteria()
        {
            const string Comment = "Should fetch all users";

            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Comment(Comment);

            var queryable = (IQueryableFlowQuery)query;

            Assert.That(queryable.CommentValue, Is.EqualTo(Comment));

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.Comment, Is.EqualTo(Comment));
        }
Exemplo n.º 9
0
        public void LocksArePopulatedOnCriteria()
        {
            IImmediateFlowQuery <UserEntity> query = Query <UserEntity>()
                                                     .Lock().Upgrade()
                                                     .Lock("user").Read()
                                                     .Lock("testAlias").Force();

            ICriteria criteria = new CriteriaBuilder()
                                 .Build <UserEntity, UserEntity>(QuerySelection.Create((IQueryableFlowQuery)query));

            Assert.That(criteria, Is.Not.Null);

            var impl = (CriteriaImpl)criteria;

            Assert.That(impl.LockModes.Keys, Contains.Item("this"));
            Assert.That(impl.LockModes.Keys, Contains.Item("user"));
            Assert.That(impl.LockModes.Keys, Contains.Item("testAlias"));

            Assert.That(impl.LockModes["this"], Is.EqualTo(LockMode.Upgrade));
            Assert.That(impl.LockModes["user"], Is.EqualTo(LockMode.Read));
            Assert.That(impl.LockModes["testAlias"], Is.EqualTo(LockMode.Force));
        }
Exemplo n.º 10
0
 /// <summary>
 ///     Populates the given <see cref="IResultStream{TDestination}" /> with the results of this query in a
 ///     streamed fashion.
 /// </summary>
 /// <param name="stream">
 ///     The <see cref="IResultStream{TDestination}" /> to stream the results into.
 /// </param>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 protected virtual void SelectStream <TDestination>(IResultStream <TDestination> stream)
 {
     SelectionHelper.SelectStream <TSource, TDestination>(QuerySelection.Create(this), stream);
 }
Exemplo n.º 11
0
 public void QuerySelectionThrowsIfQueryIsNull()
 {
     Assert.That(() => QuerySelection.Create(null), Throws.InstanceOf <ArgumentNullException>());
 }
Exemplo n.º 12
0
 /// <summary>
 ///     Creates a wrapped selection.
 /// </summary>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 /// <returns>
 ///     The created wrapped selection.
 /// </returns>
 protected virtual Func <TDestination> SelectValue <TDestination>()
 {
     return(SelectionHelper.SelectValue <TSource, TDestination>(QuerySelection.Create(this)));
 }
Exemplo n.º 13
0
 /// <summary>
 ///     Creates a <see cref="FlowQuerySelection{TDestination}" />.
 /// </summary>
 /// <typeparam name="TDestination">
 ///     The <see cref="System.Type" /> of the selection.
 /// </typeparam>
 /// <returns>
 ///     The created <see cref="FlowQuerySelection{TDestination}" />.
 /// </returns>
 protected virtual FlowQuerySelection <TDestination> SelectList <TDestination>()
 {
     return(SelectionHelper.SelectList <TSource, TDestination>(QuerySelection.Create(this)));
 }
Exemplo n.º 14
0
 /// <summary>
 ///     Creates a wrapped dictionary selection.
 /// </summary>
 /// <typeparam name="TKey">
 ///     The <see cref="System.Type" /> of the dictionary keys.
 /// </typeparam>
 /// <typeparam name="TValue">
 ///     The <see cref="System.Type" /> of the dictionary values.
 /// </typeparam>
 /// <returns>
 ///     The created wrapped dictionary selection.
 /// </returns>
 protected virtual Func <Dictionary <TKey, TValue> > SelectDictionary <TKey, TValue>()
 {
     return(SelectionHelper.SelectDictionary <TSource, TKey, TValue>(QuerySelection.Create(this)));
 }