Example #1
0
            public void SelectWithBooleanTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Expired;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "expired = 'True'", "The query text was incorrect.");
            }
Example #2
0
            public void SelectWithLocallyScopedEmbeddedVariableOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Inserted < DateTime.UtcNow;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(Regex.Match(querytext, @"inserted < '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z'").Success, "The query text was incorrect.");
            }
Example #3
0
            public void SimpleSelectOnIdTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Guid testGuid = Guid.NewGuid();
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Id == testGuid;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "itemName() = '" + testGuid + "'", "The query text was incorrect.");
            }
Example #4
0
            public void SelectWithLocallyScopedVariableOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                string username = "******";
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Username == username;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******'", "The query text was incorrect.");
            }
Example #5
0
            public void SelectWithNotCombinedWithAndOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                DateTime checkDate = DateTime.Now;
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "not (expired = 'True') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
Example #6
0
            public void SelectWithNotEqualMemberVariableOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                var myObj = new { Name = "xyz" };
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Username != myObj.Name;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username != '" + myObj.Name + "'", "The query text was incorrect.");
            }
Example #7
0
            public void SelectWithAndOperatorTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Guid id = Guid.NewGuid();
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Id == id && asset.Username == "abcd";
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "itemName() = '" + id + "' and username = '******'", "The query text was incorrect.");
            }
Example #8
0
            public void SimpleSelectOnDateTest()
            {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                DateTime checkDate = DateTime.Now;
                Expression <Func <MockSIPAsset, bool> > whereClause = (asset) => asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);

                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
 public override int Count(Expression <Func <T, bool> > whereClause)
 {
     try
     {
         SimpleDBQueryProvider simpleDBQueryProvider = new SimpleDBQueryProvider(m_simpleDBClient, m_objectMapper.TableName, m_objectMapper.SetValue);
         Query <T>             assets = new Query <T>(simpleDBQueryProvider);
         if (whereClause != null)
         {
             return(assets.Where(whereClause).Count());
         }
         else
         {
             return(assets.Count());
         }
     }
     catch (Exception excp)
     {
         logger.Error("Exception SimpleDBAssetPersistor Count (for " + typeof(T).Name + "). " + excp.Message);
         throw;
     }
 }
        public override List <T> Get(Expression <Func <T, bool> > whereClause, string orderByField, int offset, int count)
        {
            try
            {
                SimpleDBQueryProvider simpleDBQueryProvider = new SimpleDBQueryProvider(m_simpleDBClient, m_objectMapper.TableName, m_objectMapper.SetValue);
                Query <T>             assetList             = new Query <T>(simpleDBQueryProvider);
                //IQueryable<T> getList = from asset in assetList.Where(whereClause) orderby orderByField select asset;
                IQueryable <T> getList = null;
                if (whereClause != null)
                {
                    getList = from asset in assetList.Where(whereClause) select asset;
                }
                else
                {
                    getList = from asset in assetList select asset;
                }

                if (!orderByField.IsNullOrBlank())
                {
                    simpleDBQueryProvider.OrderBy = orderByField;
                }

                //if (offset != 0) {
                //   simpleDBQueryProvider.Offset = offset;
                //}

                if (count != Int32.MaxValue)
                {
                    simpleDBQueryProvider.Count = count;
                }

                return(getList.ToList() ?? new List <T>());
            }
            catch (Exception excp)
            {
                string whereClauseStr = (whereClause != null) ? whereClause.ToString() + ". " : null;
                logger.Error("Exception SimpleDBAssetPersistor Get (list) (for " + typeof(T).Name + "). " + whereClauseStr + excp.Message);
                throw;
            }
        }
 public override T Get(Expression <Func <T, bool> > whereClause)
 {
     try
     {
         SimpleDBQueryProvider simpleDBQueryProvider = new SimpleDBQueryProvider(m_simpleDBClient, m_objectMapper.TableName, m_objectMapper.SetValue);
         Query <T>             assets  = new Query <T>(simpleDBQueryProvider);
         IQueryable <T>        getList = null;
         if (whereClause != null)
         {
             getList = from asset in assets.Where(whereClause) select asset;
         }
         else
         {
             getList = from asset in assets select asset;
         }
         return(getList.FirstOrDefault());
     }
     catch (Exception excp)
     {
         string whereClauseStr = (whereClause != null) ? whereClause.ToString() + ". " : null;
         logger.Error("Exception SimpleDBAssetPersistor Get (where) (for " + typeof(T).Name + "). " + whereClauseStr + excp.Message);
         throw;
     }
 }
            public void SimpleSelectOnIdTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Guid testGuid = Guid.NewGuid();
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Id == testGuid;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "itemName() = '" + testGuid + "'", "The query text was incorrect.");
            }
            public void SelectWithLocallyScopedVariableOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                string username = "******";
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username == username;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******'", "The query text was incorrect.");
            }
            public void SelectWithAndOperatorTest() {

                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Guid id = Guid.NewGuid();
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Id == id && asset.Username == "abcd";
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "itemName() = '" + id + "' and username = '******'", "The query text was incorrect.");
            }
            public void SelectWithBooleanTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Expired;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext + ".");

                Assert.IsTrue(querytext == "expired = 'True'", "The query text was incorrect.");
            }
            public void SelectWithNotEqualMemberVariableOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                var myObj = new { Name = "xyz" };
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username != myObj.Name;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username != '" + myObj.Name + "'", "The query text was incorrect.");
            }
            public void SelectWithMemberVariableCombinedWithAndClauseOperatorTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                var myObj = new { Name = "xyz" };
                DateTime checkDate = DateTime.Now;
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Username == myObj.Name && !asset.Expired && asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "username = '******' and not (expired = 'True') and inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }
            public void SelectWithLocallyScopedEmbeddedVariableOperatorTest() {

                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Inserted < DateTime.UtcNow;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(Regex.Match(querytext, @"inserted < '\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{7}Z'").Success, "The query text was incorrect.");
            }
            public void SimpleSelectOnDateTest() {
                Console.WriteLine(System.Reflection.MethodBase.GetCurrentMethod().Name);

                SimpleDBQueryProvider queryProvider = new SimpleDBQueryProvider(null, null, null);
                DateTime checkDate = DateTime.Now;
                Expression<Func<MockSIPAsset, bool>> whereClause = (asset) => asset.Inserted >= checkDate;
                string querytext = queryProvider.GetQueryText(whereClause);
                Console.WriteLine("Query: " + querytext);

                Assert.IsTrue(querytext == "inserted >= '" + checkDate.ToString("o") + "'", "The query text was incorrect.");
            }