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.Collections.Generic;
  using System.Collections.ObjectModel;
  using Habanero.Faces.Base;
  
  
  using NUnit.Framework;
  
  namespace Habanero.Faces.Test.Base
  {
      /// <summary>
      /// Tests the standard MultiSelector control's model
      /// </summary>
      public abstract class TestMultiSelector
      {
          protected abstract IControlFactory GetControlFactory();
  
  
  
          #region Test AllOptions List
  
          [Test]
          public void TestCreateMultiSelector()
          {
              //---------------Set up test pack-------------------
  
              //---------------Execute Test ----------------------
              IMultiSelector<object> multiSelector = GetControlFactory().CreateMultiSelector<object>();
              //---------------Test Result -----------------------
  
              Assert.IsNotNull(multiSelector);
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSettingOptionsPopulatesOptionsListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
              //---------------Assert Preconditions -------------
              Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
              Assert.AreEqual(0, _selector.SelectedOptionsListBox.Items.Count);
              //---------------Execute Test ----------------------
              _selector.AllOptions = twoOptions;
  
              //---------------Test Result -----------------------
              Assert.AreEqual(2, _selector.AvailableOptionsListBox.Items.Count); 
          }
  
          [Test]
          public void Test_SetAllOptions_ToNull_ShouldClearAllOptions()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
              _selector.AllOptions = twoOptions;
              //---------------Assert Preconditions -------------
              Assert.AreEqual(2, _selector.AvailableOptionsListBox.Items.Count); 
              //---------------Execute Test ----------------------
              _selector.AllOptions = null;
              //---------------Test Result -----------------------
              Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
              Assert.AreEqual(0, _selector.SelectedOptionsListBox.Items.Count);
          }
  
          [Test]
          public void TestSettingOptionsPopulatesModel()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
  
              //---------------Execute Test ----------------------
              _selector.AllOptions = twoOptions;
  
              //---------------Test Result -----------------------
              Assert.AreEqual(2, _selector.Model.OptionsView.Count);
  
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestAddingOptionAddsToListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              _selector.AllOptions = CreateListWithTwoOptions();
  
              //---------------Execute Test ----------------------
              _selector.Model.AddOption(new TestT());
  
              //---------------Test Result -----------------------
              Assert.AreEqual(3, _selector.AvailableOptionsListBox.Items.Count);
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestRemoveOptionRemovesFromListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              _selector.AllOptions = CreateListWithTwoOptions();
  
              //---------------Execute Test ----------------------
              _selector.Model.RemoveOption(_selector.Model.OptionsView[0]);
  
              //---------------Test Result -----------------------
              Assert.AreEqual(1, _selector.AvailableOptionsListBox.Items.Count);
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSettingOptionsViaModelUpdatesListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
  
              //---------------Execute Test ----------------------
              _selector.Model.AllOptions = twoOptions;
  
              //---------------Test Result -----------------------
              Assert.AreEqual(2, _selector.AvailableOptionsListBox.Items.Count);
  
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSettingBlankOptionsClearsListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              _selector.Model.AllOptions = CreateListWithTwoOptions();
  
              //---------------Execute Test ----------------------
              _selector.Model.AllOptions = new List<TestT>();
              //---------------Test Result -----------------------
              Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestOptionsMirrorsModelOptions()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              _selector.Model.AllOptions = CreateListWithTwoOptions();
              Assert.AreEqual(_selector.AllOptions, _selector.Model.AllOptions);
              //---------------Execute Test ----------------------
              _selector.AllOptions = new List<TestT>();
              //---------------Test Result -----------------------
              Assert.AreEqual(_selector.AllOptions, _selector.Model.AllOptions);
              //---------------Tear Down ------------------------- 
          }
  
          #endregion Test AllOptions List
  
          #region Test selections List
  
          [Test]
          public void TestSetSelectionsPopulatesOptionsListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
              _selector.AllOptions = twoOptions;
  
              //---------------Execute Test ----------------------
              _selector.SelectedOptions = twoOptions;
  
              //---------------Test Result -----------------------
              Assert.AreEqual(2, _selector.SelectedOptionsListBox.Items.Count);
              Assert.AreEqual(_selector.SelectedOptionsListBox.Items.Count, _selector.SelectionsView.Count);
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSetSelectionsRemovesItemsFromOptionsListbox()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
              _selector.AllOptions = twoOptions;
  
              //---------------Execute Test ----------------------
              _selector.SelectedOptions = twoOptions;
  
              //---------------Test Result -----------------------
              Assert.AreEqual(0, _selector.AvailableOptionsListBox.Items.Count);
  
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSetEmptySelectionsRepopulatesOptionsAndSelections()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              List<TestT> twoOptions = CreateListWithTwoOptions();
              _selector.AllOptions = twoOptions;
              _selector.SelectedOptions = twoOptions;
  
              //---------------Execute Test ----------------------
              _selector.SelectedOptions = new List<TestT>();
              //---------------Test Result -----------------------
              AssertNoneSelected(_selector);
  
              //---------------Tear Down -------------------------          
          }
  
          [Test]
          public void TestSelectionsMirrorsModelSelections()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
              _selector.Model.SelectedOptions = CreateListWithTwoOptions();
              Assert.AreEqual(_selector.SelectedOptions, _selector.Model.SelectedOptions);
              //---------------Execute Test ----------------------
              _selector.AllOptions = new List<TestT>();
              //---------------Test Result -----------------------
              Assert.AreEqual(_selector.SelectedOptions, _selector.Model.SelectedOptions);
              //---------------Tear Down ------------------------- 
          }
  
          #endregion
  
          #region Test Selecting and Deselecting
  
          [Test]
          public void TestSelectingItemUpdatesListboxes()
          {
              //---------------Set up test pack-------------------
              IMultiSelector<TestT> _selector = GetControlFactory().CreateMultiSelector<TestT>();
  
gt:             _selector.AllOptions = CreateListWithTwoOptions();