using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using AzureStorageMapper.Criterias.TableStorage;

namespace AzureStorageMapper.Tests.Criterias.TableStorage
{
    [TestFixture]
    public class TableQueryUtilsTests
    {

        private Criteria _crit1;
        private Criteria _crit2;
        private Restrietion _rest1;
        private Restrietion _rest2;

        private TableQueryUtils util;

        [SetUp]
        public void TestSetUp()
        {
            _crit1 = new Criteria();
            _crit2 = new Criteria();
            _rest1 = new Restrietion();
            _rest2 = new Restrietion();

            util = new TableQueryUtils();

            _crit1.QueryColumn("col1").QueryOperation(CriteriaOperator.Equal).QueryValue("value 1");
            _crit2.QueryColumn("col1").QueryOperation(CriteriaOperator.Equal)
                .QuerySubCriteria.QueryColumn("col2").QueryOperation(CriteriaOperator.GreaterThanOrEqual)
                    .QuerySubCriteria.QueryColumn("col3").QueryOperation(CriteriaOperator.LessThanOrEqueal).QueryValue(12345L);

            _rest1.And(_crit1, _crit2);
            _rest2.Not(_crit1);
        }

        [Test]
        public void GetStringQuery_Criteria_Test()
        {
            string queryStr = util.GetStringQuery(_crit1);
            Assert.AreEqual("col1 eq value 1", queryStr);

            queryStr = util.GetStringQuery(_crit2);
            Assert.AreEqual("col1 eq (col2 ge (col3 le 12345))", queryStr);
        }

        [Test]
        public void GetStringQuery_Restrietion_Test()
        {
            string queryStr = util.GetStringQuery(_rest1);
            Assert.AreEqual("(col1 eq value 1) and (col1 eq (col2 ge (col3 le 12345)))", queryStr);

            queryStr = util.GetStringQuery(_rest2);
            Assert.AreEqual("not(col1 eq value 1)", queryStr);
        }
    }
}

Last edited Dec 5, 2011 at 12:56 AM by shrimpy, version 1

Comments

No comments yet.