context: //---------------------------------------------------------------------------------
  // Copyright (C) 2009 Chillisoft Solutions
  // 
  // This file is part of the Habanero framework.
  // 
  //     Habanero is a free framework: you can redistribute it and/or modify
  //     it under the terms of the GNU Lesser General Public License as published by
  //     the Free Software Foundation, either version 3 of the License, or
  //     (at your option) any later version.
  // 
  //     The Habanero framework is distributed in the hope that it will be useful,
  //     but WITHOUT ANY WARRANTY; without even the implied warranty of
  //     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  //     GNU Lesser General Public License for more details.
  // 
  //     You should have received a copy of the GNU Lesser General Public License
  //     along with the Habanero framework.  If not, see <http://www.gnu.org/licenses/>.
  //---------------------------------------------------------------------------------
  
  using System;
  using System.Collections;
  using System.Collections.Generic;
  using Habanero.Base;
  using Habanero.Base.Util;
  using Habanero.Faces.Base;
  using NUnit.Framework;
  
  namespace Habanero.Faces.Test.Base.FilterController
  {
      public abstract class TestFilterControlManager
      {
          protected abstract IControlFactory GetControlFactory();
  
          [SetUp]
          public void SetupTest()
          {
              //Runs every time that any testmethod is executed
          }
  
          [TestFixtureSetUp]
          public void TestFixtureSetup()
          {
              //Code that is executed before any test is run in this class. If multiple tests
              // are executed then it will still only be called once.
          }
  
          [TearDown]
          public void TearDownTest()
          {
              //runs every time any testmethod is complete
          }
  
          [Test]
          public void TestCreateFilterControlManager()
          {
              //---------------Set up test pack-------------------
              GridLayoutManager layoutManager = new GridLayoutManager(GetControlFactory().CreatePanel(),
                                                                      GetControlFactory());
              //---------------Execute Test ----------------------
              FilterControlManager filterControlManager = new FilterControlManager(GetControlFactory(), layoutManager);
              //---------------Test Result -----------------------
              Assert.AreEqual(layoutManager, filterControlManager.LayoutManager);
          }
  
          [Test]
          public void ClearFilters_FIXBUG()
          {
              //---------------Set up test pack-------------------
              GridLayoutManager layoutManager = new GridLayoutManager(GetControlFactory().CreatePanel(),
                                                                      GetControlFactory());
              IFilterClauseFactory filterClauseFactory = new DataViewFilterClauseFactory();
              FilterControlManager filterControlManager = new FilterControlManager(GetControlFactory(), layoutManager);
              filterControlManager.AddStringFilterTextBox("Test:", "TestColumn");
              filterClauseFactory.CreateStringFilterClause("TestColumn", FilterClauseOperator.OpLike, "testvalue");
  
              filterControlManager.AddStringFilterTextBox("Test2:", "TestColumn2");
              filterControlManager.GetFilterClause().GetFilterClauseString();
              //---------------Execute Test ----------------------
              filterControlManager.ClearFilters();
              //---------------Test Result -----------------------
              Assert.IsTrue(true, "Should not cause an Erro");
          }
  
          [Test]
          public void Test_AddStaticFilterClause()
          {
              //---------------Set up test pack-------------------
              GridLayoutManager layoutManager = new GridLayoutManager(GetControlFactory().CreatePanel(), GetControlFactory());
              FilterControlManager filterControlManager = new FilterControlManager(GetControlFactory(), layoutManager);
              //---------------Execute Test ----------------------
              const string propertyName = "TestColumn2";
              const string filtervalue = "FilterValue";
              filterControlManager.AddStaticStringFilterClause(propertyName, FilterClauseOperator.OpGreaterThan, filtervalue);
              //---------------Test Result -----------------------
              Assert.AreEqual(1, filterControlManager.FilterControls.Count);
              ICustomFilter control = filterControlManager.FilterControls[0];
              Assert.AreEqual(propertyName, control.PropertyName);
              Assert.AreEqual(FilterClauseOperator.OpGreaterThan, control.FilterClauseOperator);
              IFilterClause filterClause = control.GetFilterClause(new DataViewFilterClauseFactory());
              Assert.AreEqual(string.Format("{0} > '{1}'", propertyName, filtervalue), filterClause.GetFilterClauseString()); 
          }
  
          [Test]
          public void TestAdd_DateRangeFilterComboBox()
          {
              //---------------Set up test pack-------------------
  
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              //---------------Execute Test ----------------------
              IDateRangeComboBox dr1 = filterControl.AddDateRangeFilterComboBox("test", "test", true, true);
  
              //---------------Test Result -----------------------
              Assert.AreEqual(1, filterControl.FilterControls.Count);
              Assert.IsTrue(filterControl.FilterPanel.Controls.Contains(dr1));
          }
  
          [Test]
          public void TestAdd_DateRangeFilterComboBoxInclusive()
          {
              //---------------Set up test pack-------------------
  
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              IFilterClauseFactory filterClauseFactory = new DataViewFilterClauseFactory();
              DateTime testDate = new DateTime(2007, 1, 2, 3, 4, 5, 6);
  
              //---------------Execute Test ----------------------
              IDateRangeComboBox dr1 = filterControl.AddDateRangeFilterComboBox("test", "test", true, true);
              dr1.UseFixedNowDate = true;
              dr1.FixedNowDate = testDate;
              dr1.SelectedItem = "Today";
              IFilterClause clause1 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpGreaterThanOrEqualTo,
                                                             new DateTime(2007, 1, 2, 0, 0, 0));
              IFilterClause clause2 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpLessThanOrEqualTo,
                                                             new DateTime(2007, 1, 2, 23, 59, 59, 999));
              IFilterClause compClause =
                  filterClauseFactory.CreateCompositeFilterClause(clause1, FilterClauseCompositeOperator.OpAnd, clause2);
              //---------------Test Result -----------------------
  
              Assert.AreEqual(compClause.GetFilterClauseString(), filterControl.GetFilterClause().GetFilterClauseString());
          }
          [Test]
          public void TestAdd_DateRangeFilterComboBox_WhenExclusiveNotDefined_ShouldSetAsInclusive()
          {
              //---------------Set up test pack-------------------
  
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              IFilterClauseFactory filterClauseFactory = new DataViewFilterClauseFactory();
              DateTime testDate = new DateTime(2007, 1, 2, 3, 4, 5, 6);
  
              //---------------Execute Test ----------------------
              IDateRangeComboBox dr1 = filterControl.AddDateRangeFilterComboBox("test", "test");
              dr1.UseFixedNowDate = true;
              dr1.FixedNowDate = testDate;
              dr1.SelectedItem = "Today";
              IFilterClause clause1 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpGreaterThanOrEqualTo,
                                                             new DateTime(2007, 1, 2, 0, 0, 0));
              IFilterClause clause2 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpLessThanOrEqualTo,
                                                             new DateTime(2007, 1, 2, 23, 59, 59, 999));
              IFilterClause compClause =
                  filterClauseFactory.CreateCompositeFilterClause(clause1, FilterClauseCompositeOperator.OpAnd, clause2);
              //---------------Test Result -----------------------
  
              Assert.AreEqual(compClause.GetFilterClauseString(), filterControl.GetFilterClause().GetFilterClauseString());
          }
  
          [Test]
          public void TestAdd_DateRangeFilterComboBoxExclusive()
          {
              //---------------Set up test pack-------------------
  
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              IFilterClauseFactory filterClauseFactory = new DataViewFilterClauseFactory();
              DateTime testDate = new DateTime(2007, 1, 2, 3, 4, 5, 6);
  
              //---------------Execute Test ----------------------
              IDateRangeComboBox dr1 = filterControl.AddDateRangeFilterComboBox("test", "test", false, false);
              dr1.UseFixedNowDate = true;
              dr1.FixedNowDate = testDate;
              dr1.SelectedItem = "Today";
              IFilterClause clause1 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpGreaterThan,
                                                             new DateTime(2007, 1, 2, 0, 0, 0));
              IFilterClause clause2 =
                  filterClauseFactory.CreateDateFilterClause("test", FilterClauseOperator.OpLessThan,
                                                             new DateTime(2007, 1, 2, 23, 59, 59, 999));
              IFilterClause compClause =
                  filterClauseFactory.CreateCompositeFilterClause(clause1, FilterClauseCompositeOperator.OpAnd, clause2);
              //---------------Test Result -----------------------
  
              Assert.AreEqual(compClause.GetFilterClauseString(), filterControl.GetFilterClause().GetFilterClauseString());
          }
  
          [Test]
          public void TestAdd_DateRangeFilterComboBoxOverload()
          {
              //---------------Set up test pack-------------------
  
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              List<DateRangeOptions> options = new List<DateRangeOptions>();
              options.Add(DateRangeOptions.Today);
              options.Add(DateRangeOptions.Yesterday);
  
              //---------------Execute Test ----------------------
              IDateRangeComboBox dateRangeCombo =
                  filterControl.AddDateRangeFilterComboBox("test", "test", options, true, false);
              //---------------Test Result -----------------------
              Assert.AreEqual(3, dateRangeCombo.Items.Count);
          }
  
          [Test]
          public void TestAdd_CustomFilter()
          {
              //---------------Set up test pack-------------------
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              ICustomFilter customFilter = new CustomFilterStub(GetControlFactory());
  
              //---------------Execute Test ----------------------
              filterControl.AddCustomFilter("LabelText", customFilter);
  
              //---------------Test Result -----------------------
              Assert.AreEqual(1, filterControl.FilterControls.Count);
              IControlHabanero controlHabanero = filterControl.GetChildControl("test");
              Assert.AreEqual(customFilter.Control, controlHabanero);
              Assert.IsNotNull(controlHabanero);
              Assert.IsInstanceOf(typeof (ITextBox), controlHabanero);
              //---------------Tear Down -------------------------
          }
  
          [Test]
          public void TestCustomFilterValue_changedFiresWhenTextChanged()
          {
              //---------------Set up test pack-------------------
              IFilterControl filterControl = GetControlFactory().CreateFilterControl();
              ICustomFilter customFilter = new CustomFilterStub(GetControlFactory());
              filterControl.AddCustomFilter("LabelText", customFilter);
  
              //---------------Assert pre conditions--------------
              Assert.IsFalse(((CustomFilterStub) customFilter)._valueChangedFired);
  
              //---------------Execute Test ----------------------
              customFilter.Control.Text = "newText";
  
              //---------------Test Result -----------------------
              Assert.IsTrue(((CustomFilterStub) customFilter)._valueChangedFired);
          }
  
          [Test]
          public void TestAddTextBox()
          {
              //---------------Set up test pack-------------------
  
gt:             IFilterControl ctl = GetControlFactory().CreateFilterControl();