using System.Collections.Generic;
using AzureStorageMapper.Criterias.TableStorage;
using AzureStorageMapper.TableStorage;
using AzureStorageMapper.TableStorage.Attributes;
using NUnit.Framework;

namespace AzureStorageMapper.Tests.TableStorage.TableEntityTests
{
    [TestFixture]
    public class FilterTests
    {

        [SetUp]
        public void TestSetUp()
        {
            // prepare data here
        }

        //[Test]
        public void ColumnFilterTest()
        {
            Criteria c1 = new Criteria();
            c1.QueryColumn("Column2").QueryOperation(CriteriaOperator.GreaterThanOrEqual).QueryValue(1);

            Criteria c2 = new Criteria();
            c2.QueryColumn("Column2").QueryOperation(CriteriaOperator.LessThan).QueryValue(4);

            Restrietion r = new Restrietion();
            r.And(c1, c2);

            List<SampleTableModel> li = SampleTableModel.GetEntities<SampleTableModel>(r);

            Assert.AreEqual(4, li.Count);
        }

        //[Test]
        public void TopFilterTest()
        {
            Criteria c1 = new Criteria();
            c1.QueryColumn("Column2").QueryOperation(CriteriaOperator.GreaterThanOrEqual).QueryValue(1);

            Criteria c2 = new Criteria();
            c2.QueryColumn("Column2").QueryOperation(CriteriaOperator.LessThan).QueryValue(4);

            Restrietion r = new Restrietion();
            r.And(c1, c2);

            List<SampleTableModel> li = SampleTableModel.GetEntities<SampleTableModel>(r, 2);

            Assert.AreEqual(2, li.Count);
        }

        [TableModel(Name = "SampleQueryTests")]
        internal class SampleTableModel : TableEntity
        {
            [TableColumn]
            public string ColumnOne { get; set; }

            [TableColumn(Name = "Column2")]
            public int ColumnTwo { get; set; }

            [TableColumn]
            public long ColumnThree { get; set; }

            public SampleTableModel(string partitionKey, string rowKey)
                : base(partitionKey, rowKey)
            {
            }
        }
    }
}

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

Comments

No comments yet.