public void BuildFilterQuery_Basic( )
        {
            StructuredQuery query = ReportHelpers.BuildFilterQuery("Name='test'", new ReadiNow.Model.EntityRef("test:person"), false);

            Assert.That(query, Is.Not.Null);
            Assert.That(query.RootEntity, Is.Not.Null);
            Assert.That(query.RootEntity.Conditions.Count, Is.EqualTo(1));
        }
        public void Test_GetCacheKeyToken_Stability( )
        {
            StructuredQuery sq1 = ReportHelpers.BuildFilterQuery("Name='test1'", new ReadiNow.Model.EntityRef("test:person"), true);

            sq1.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq1.RootEntity, "core:name")
            });

            StructuredQuery sq2 = ReportHelpers.BuildFilterQuery("Name='test1'", new ReadiNow.Model.EntityRef("test:person"), true);

            sq2.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq2.RootEntity, "core:name")
            });

            string token1 = sq1.CacheKeyToken( );
            string token2 = sq2.CacheKeyToken( );

            Assert.That(token1, Is.EqualTo(token2).And.Not.Null);
        }
Esempio n. 3
0
        public void Test_EnsureDifferentInstancesCanCacheMatch( )
        {
            CachingQueryRunner   cachingQueryRunner;
            Mock <IQueryRunner>  mockQueryRunner;
            IQueryRunner         queryRunner;
            QuerySettings        settings;
            QueryBuild           queryBuild;
            QueryResult          result;
            IQuerySqlBuilder     queryBuilder        = MockQuerySqlBuilder( );
            IUserRuleSetProvider userRuleSetProvider = MockUserRuleSetProvider( );

            StructuredQuery sq1 = ReportHelpers.BuildFilterQuery("Name='test1'", new EntityRef("test:person"), true);

            sq1.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq1.RootEntity, "core:name")
            });

            StructuredQuery sq2 = ReportHelpers.BuildFilterQuery("Name='test1'", new EntityRef("test:person"), true);

            sq2.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq2.RootEntity, "core:name")
            });

            settings   = new QuerySettings( );
            queryBuild = new QueryBuild( );
            result     = new QueryResult(queryBuild);

            mockQueryRunner = new Mock <IQueryRunner>(MockBehavior.Strict);
            mockQueryRunner.Setup(x => x.ExecutePrebuiltQuery(sq1, settings, It.IsNotNull <QueryBuild>( )))
            .Returns(() => result)
            .Verifiable( );
            queryRunner        = mockQueryRunner.Object;
            cachingQueryRunner = new CachingQueryRunner(queryRunner, userRuleSetProvider, queryBuilder);

            cachingQueryRunner.ExecuteQuery(sq1, settings);
            cachingQueryRunner.ExecuteQuery(sq2, settings);

            mockQueryRunner.Verify(x => x.ExecutePrebuiltQuery(sq1, settings, It.IsNotNull <QueryBuild>( )), Times.Exactly(1));
            mockQueryRunner.VerifyAll( );
        }
        public void Test_GetCacheKeyToken_Concurrent( )
        {
            StructuredQuery sq1 = ReportHelpers.BuildFilterQuery("Name='test1'", new ReadiNow.Model.EntityRef("test:person"), true);

            sq1.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq1.RootEntity, "core:name")
            });

            StructuredQuery sq2 = ReportHelpers.BuildFilterQuery("Name='test1'", new ReadiNow.Model.EntityRef("test:person"), true);

            sq2.SelectColumns.Add(new SelectColumn {
                Expression = new ResourceExpression(sq2.RootEntity, "core:name")
            });

            string token1 = null;
            string token2 = null;

            Task.WaitAll(
                Task.Factory.StartNew(() => { token1 = sq1.CacheKeyToken( ); }),
                Task.Factory.StartNew(() => { token2 = sq2.CacheKeyToken( ); })
                );

            Assert.That(token1, Is.EqualTo(token2).And.Not.Null);
        }