| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916 |
- // Permission is hereby granted, free of charge, to any person obtaining
- // a copy of this software and associated documentation files (the
- // "Software"), to deal in the Software without restriction, including
- // without limitation the rights to use, copy, modify, merge, publish,
- // distribute, sublicense, and/or sell copies of the Software, and to
- // permit persons to whom the Software is furnished to do so, subject to
- // the following conditions:
- //
- // The above copyright notice and this permission notice shall be
- // included in all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
- // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
- // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
- // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
- // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
- // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- //
- // Copyright (c) 2007 Novell, Inc.
- //
- #if NET_2_0
- using System;
- using System.Data;
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Windows.Forms;
- using NUnit.Framework;
- namespace MonoTests.System.Windows.Forms {
- [TestFixture]
- public class BindingSourceTest
- {
- [Test]
- public void DefaultDataSource ()
- {
- BindingSource source = new BindingSource ();
- Assert.IsTrue (source.List is BindingList<object>, "1");
- Assert.AreEqual (0, source.List.Count, "2");
- }
- [Test]
- public void DataSource_InitialAddChangingType ()
- {
- BindingSource source = new BindingSource ();
- source.Add ((int)32);
- Assert.IsTrue (source.List is BindingList<int>, "1");
- }
- class EmptyEnumerable : IEnumerable {
- class EmptyEnumerator : IEnumerator {
- public object Current {
- get { throw new InvalidOperationException (); }
- }
- public void Reset () {
- // nada
- }
- public bool MoveNext () {
- return false;
- }
- }
- public IEnumerator GetEnumerator () {
- return new EmptyEnumerator ();
- }
- }
- class GenericEnumerable : IEnumerable<int> {
- int length;
- public GenericEnumerable (int length) {
- this.length = length;
- }
- class MyEnumerator : IEnumerator<int> {
- public int count;
- public int index;
- public int Current {
- get { return index; }
- }
- object IEnumerator.Current {
- get { return Current; }
- }
- public void Reset () {
- index = 0;
- }
- public bool MoveNext () {
- if (index++ == count)
- return false;
- else
- return true;
- }
- void IDisposable.Dispose () {
- }
- }
- public IEnumerator<int> GetEnumerator () {
- MyEnumerator e = new MyEnumerator ();
- e.count = length;
- return e;
- }
- IEnumerator IEnumerable.GetEnumerator () {
- return GetEnumerator ();
- }
- }
- class WorkingEnumerable : IEnumerable {
- int length;
- public WorkingEnumerable (int length) {
- this.length = length;
- }
- class MyEnumerator : IEnumerator {
- public int count;
- public int index;
- public object Current {
- get { return index; }
- }
- public void Reset () {
- index = 0;
- }
- public bool MoveNext () {
- if (index++ == count)
- return false;
- else
- return true;
- }
- }
- public IEnumerator GetEnumerator () {
- MyEnumerator e = new MyEnumerator ();
- e.count = length;
- return e;
- }
- }
- [Test]
- public void DataSource_ListRelationship ()
- {
- BindingSource source = new BindingSource ();
- // null
- source.DataSource = null;
- Assert.IsTrue (source.List is BindingList<object>, "1");
- // a non-list object
- source.DataSource = new object ();
- Assert.IsTrue (source.List is BindingList<object>, "2");
- // array instance (value type)
- source.DataSource = new int[32];
- Assert.IsTrue (source.List is int[], "3");
- // an instance array with 0 elements
- source.DataSource = new int[0];
- Assert.IsTrue (source.List is int[], "4");
- // array instance (object type)
- source.DataSource = new string[32];
- Assert.IsTrue (source.List is string[], "5");
- // list type
- source.DataSource = new List<bool>();
- Assert.IsTrue (source.List is List<bool>, "6");
- // an IEnumerable type
- source.DataSource = "hi";
- Assert.IsTrue (source.List is BindingList<char>, "7");
- // an IEnumerable type with 0 items
- source.DataSource = "";
- Assert.IsTrue (source.List is BindingList<char>, "8");
- Assert.AreEqual (0, source.List.Count, "9");
- // a generic enumerable with no elements.
- // even though we can figure out the type
- // through reflection, we shouldn't..
- source.DataSource = new GenericEnumerable (0);
- Console.WriteLine (source.List.GetType());
- Assert.IsTrue (source.List is BindingList<char>, "10");
- Assert.AreEqual (0, source.List.Count, "11");
- // a non-generic IEnumerable type with 0 items
- // this doesn't seem to change the type of the
- // binding source's list, probably because it
- // can't determine the type of the
- // enumerable's elements.
- source.DataSource = new EmptyEnumerable ();
- Assert.IsTrue (source.List is BindingList<char>, "12");
- // an enumerable with some elements
- source.DataSource = new WorkingEnumerable (5);
- Assert.IsTrue (source.List is BindingList<int>, "13");
- Assert.AreEqual (5, source.List.Count, "14");
- }
- [Test]
- public void ResetItem ()
- {
- BindingSource source = new BindingSource ();
- bool delegate_reached = false;
- int old_index = 5;
- int new_index = 5;
- ListChangedType type = ListChangedType.Reset;
- source.ListChanged += delegate (object sender, ListChangedEventArgs e) {
- delegate_reached = true;
- type = e.ListChangedType;
- old_index = e.OldIndex;
- new_index = e.NewIndex;
- };
- source.ResetItem (0);
- Assert.IsTrue (delegate_reached, "1");
- Assert.AreEqual (-1, old_index, "2");
- Assert.AreEqual (0, new_index, "3");
- Assert.AreEqual (ListChangedType.ItemChanged, type, "3");
- }
- [Test]
- public void Movement ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new WorkingEnumerable (5);
- int raised = 0;
- source.PositionChanged += delegate (object sender, EventArgs e) { raised ++; };
- Console.WriteLine ("count = {0}", source.Count);
- source.Position = 3;
- Assert.AreEqual (3, source.Position, "1");
- source.MoveFirst ();
- Assert.AreEqual (0, source.Position, "2");
- source.MoveNext ();
- Assert.AreEqual (1, source.Position, "3");
- source.MovePrevious ();
- Assert.AreEqual (0, source.Position, "4");
- source.MoveLast ();
- Assert.AreEqual (4, source.Position, "5");
- Assert.AreEqual (5, raised, "6");
- }
- [Test]
- public void Position ()
- {
- BindingSource source = new BindingSource ();
- Assert.AreEqual (-1, source.Position, "0");
- source.DataSource = new WorkingEnumerable (5);
- int raised = 0;
- source.PositionChanged += delegate (object sender, EventArgs e) { raised ++; };
- Assert.AreEqual (0, source.Position, "1");
- source.Position = -1;
- Assert.AreEqual (0, source.Position, "2");
- Assert.AreEqual (0, raised, "3");
- source.Position = 10;
- Assert.AreEqual (4, source.Position, "4");
- Assert.AreEqual (1, raised, "5");
- source.Position = 10;
- Assert.AreEqual (4, source.Position, "6");
- Assert.AreEqual (1, raised, "7");
- }
- [Test]
- public void ResetCurrentItem ()
- {
- BindingSource source = new BindingSource ();
- bool delegate_reached = false;
- int old_index = 5;
- int new_index = 5;
- ListChangedType type = ListChangedType.Reset;
- source.DataSource = new WorkingEnumerable (5);
- source.Position = 2;
- source.ListChanged += delegate (object sender, ListChangedEventArgs e) {
- delegate_reached = true;
- type = e.ListChangedType;
- old_index = e.OldIndex;
- new_index = e.NewIndex;
- };
- source.ResetCurrentItem ();
- Assert.IsTrue (delegate_reached, "1");
- Assert.AreEqual (-1, old_index, "2");
- Assert.AreEqual (2, new_index, "3");
- Assert.AreEqual (ListChangedType.ItemChanged, type, "3");
- }
- [Test]
- public void ResetBindings ()
- {
- BindingSource source;
- int event_count = 0;
- ListChangedType[] types = new ListChangedType[2];
- int[] old_index = new int[2];
- int[] new_index = new int[2];
- source = new BindingSource ();
- source.ListChanged += delegate (object sender, ListChangedEventArgs e) {
- types[event_count] = e.ListChangedType;
- old_index[event_count] = e.OldIndex;
- new_index[event_count] = e.NewIndex;
- event_count ++;
- };
- event_count = 0;
- source.ResetBindings (false);
- Assert.AreEqual (1, event_count, "1");
- Assert.AreEqual (ListChangedType.Reset, types[0], "2");
- Assert.AreEqual (-1, old_index[0], "3");
- Assert.AreEqual (-1, new_index[0], "4");
- event_count = 0;
- source.ResetBindings (true);
- Assert.AreEqual (2, event_count, "5");
- Assert.AreEqual (ListChangedType.PropertyDescriptorChanged, types[0], "6");
- Assert.AreEqual (0, old_index[0], "7");
- Assert.AreEqual (0, new_index[0], "8");
- Assert.AreEqual (ListChangedType.Reset, types[1], "9");
- Assert.AreEqual (-1, old_index[1], "10");
- Assert.AreEqual (-1, new_index[1], "11");
- }
- [Test]
- public void AllowRemove ()
- {
- BindingSource source = new BindingSource ();
- Assert.IsTrue (source.AllowRemove, "1");
- source.DataSource = "";
- Assert.IsTrue (source.AllowRemove, "2");
- source.DataSource = new ArrayList ();
- Assert.IsTrue (source.AllowRemove, "3");
- source.DataSource = new int[10];
- Assert.IsFalse (source.AllowRemove, "4");
- source.DataSource = new WorkingEnumerable (5);
- Assert.IsTrue (source.AllowRemove, "5");
- }
- [Test]
- public void DataMember_ListRelationship ()
- {
- }
- [Test]
- public void DataMemberNull ()
- {
- BindingSource source = new BindingSource ();
- Assert.AreEqual ("", source.DataMember, "1");
- source.DataMember = null;
- Assert.AreEqual ("", source.DataMember, "2");
- }
- [Test]
- public void DataSourceChanged ()
- {
- ArrayList list = new ArrayList ();
- BindingSource source = new BindingSource ();
- bool event_raised = false;
- source.DataSourceChanged += delegate (object sender, EventArgs e) {
- event_raised = true;
- };
- source.DataSource = list;
- Assert.IsTrue (event_raised, "1");
- event_raised = false;
- source.DataSource = list;
- Assert.IsFalse (event_raised, "2");
- }
- [Test]
- [ExpectedException (typeof (ArgumentException))] // DataMember property 'hi' cannot be found on the DataSource.
- public void DataMemberArgumentException ()
- {
- ArrayList list = new ArrayList ();
- BindingSource source = new BindingSource ();
- source.DataSource = list;
- source.DataMember = "hi";
- }
- [Test]
- public void DataMemberBeforeDataSource ()
- {
- ArrayList list = new ArrayList ();
- BindingSource source = new BindingSource ();
- source.DataMember = "hi";
- Assert.AreEqual ("hi", source.DataMember, "1");
- source.DataSource = list;
- Assert.AreEqual ("", source.DataMember, "2");
- }
- [Test]
- public void DataSourceAssignToDefaultType()
- {
- BindingSource source = new BindingSource ();
- source.DataMember = "hi";
- Assert.AreEqual ("hi", source.DataMember, "1");
- Assert.IsTrue (source.List is BindingList<object>, "2");
- source.DataSource = new BindingList<object>();
- Assert.AreEqual ("", source.DataMember, "3");
- }
- [Test]
- public void DataMemberChanged ()
- {
- ArrayList list = new ArrayList ();
- BindingSource source = new BindingSource ();
- bool event_raised = false;
- list.Add ("hi"); // make the type System.String
- source.DataMemberChanged += delegate (object sender, EventArgs e) {
- event_raised = true;
- };
- source.DataSource = list;
- source.DataMember = "Length";
- Assert.IsTrue (event_raised, "1");
- event_raised = false;
- source.DataMember = "Length";
- Assert.IsFalse (event_raised, "2");
- }
- [Test]
- public void SuppliedDataSource ()
- {
- List<string> list = new List<string>();
- BindingSource source;
- source = new BindingSource (list, "");
- Assert.IsTrue (source.List is List<string>, "1");
- source.DataMember = "Length";
- Assert.IsTrue (source.List is BindingList<int>, "2");
- source = new BindingSource (list, "Length");
- Assert.IsTrue (source.List is BindingList<int>, "3");
- }
- [Test]
- public void DataSourceMember_set ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new List<string>();
- source.DataMember = "Length";
- Assert.IsNotNull (source.CurrencyManager, "1");
- source.DataSource = new List<string>();
- Assert.AreEqual ("Length", source.DataMember, "2");
- Assert.IsNotNull (source.CurrencyManager, "3");
- source.DataSource = new List<string>();
- Assert.AreEqual ("Length", source.DataMember, "4");
- Assert.IsNotNull (source.CurrencyManager, "5");
- }
- [Test]
- public void DataSourceMemberChangedEvents ()
- {
- BindingSource source = new BindingSource ();
- bool data_source_changed = false;
- bool data_member_changed = false;
- source.DataSourceChanged += delegate (object sender, EventArgs e) {
- data_source_changed = true;
- };
- source.DataMemberChanged += delegate (object sender, EventArgs e) {
- data_member_changed = true;
- };
- data_source_changed = false;
- data_member_changed = false;
- source.DataSource = new List<string>();
- Assert.IsTrue (data_source_changed, "1");
- Assert.IsFalse (data_member_changed, "2");
- data_source_changed = false;
- data_member_changed = false;
- source.DataMember = "Length";
- Assert.IsFalse (data_source_changed, "3");
- Assert.IsTrue (data_member_changed, "4");
- }
- [Test]
- public void AddNew ()
- {
- BindingSource source = new BindingSource ();
- source.AddNew ();
- Assert.AreEqual (1, source.Count, "1");
- }
- [Test]
- public void AddNew_NonBindingList ()
- {
- IList list = new List<object> ();
- BindingSource source = new BindingSource ();
- source.DataSource = list;
- Assert.IsTrue (source.List is List<object>, "1");
- source.AddNew ();
- Assert.AreEqual (1, source.Count, "2");
- }
- [Test]
- public void AllowNew_getter ()
- {
- BindingSource source = new BindingSource ();
- // true because the default datasource is BindingList<object>
- Assert.IsTrue (source.AllowNew, "1");
- source.DataSource = new object[10];
- // fixed size
- Assert.IsFalse (source.AllowNew, "2");
- source.DataSource = new BindingList<string>();
- // no default ctor
- Assert.IsFalse (source.AllowNew, "3");
- }
- [Test]
- public void AllowNew ()
- {
- BindingSource source = new BindingSource ();
- source.AllowNew = false;
- Assert.IsFalse (source.AllowNew, "1");
- source.ResetAllowNew ();
- Assert.IsTrue (source.AllowNew, "2");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // "AllowNew can only be set to true on an
- // IBindingList or on a read-write list with a default
- // public constructor."
- public void AllowNew_FixedSize ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new object[10];
- source.AllowNew = true;
- }
- #if false
- // According to the MS docs, this should fail with a MissingMethodException
- [Test]
- public void AllowNew_NoDefaultCtor ()
- {
- List<string> s = new List<string>();
- s.Add ("hi");
- BindingSource source = new BindingSource ();
- source.DataSource = s;
- source.AllowNew = true;
- Assert.Fail ();
- }
- #endif
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // "Item cannot be added to a read-only or fixed-size list."
- public void AddNew_BindingListWithoutAllowNew ()
- {
- BindingList<int> l = new BindingList<int>();
- l.AllowNew = false;
- BindingSource source = new BindingSource ();
- source.DataSource = l;
- source.AddNew ();
- Assert.AreEqual (1, source.Count, "1");
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // "Item cannot be added to a read-only or fixed-size list."
- public void AddNew_FixedSize ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new int[5];
- object o = source.AddNew ();
- Assert.IsTrue (o is int, "1");
- Assert.AreEqual (6, source.Count, "2");
- }
- class ReadOnlyList : List<int>, IList {
- public int Add (object value) {
- throw new Exception ();
- }
- public bool Contains (object value) {
- throw new Exception ();
- }
- public int IndexOf (object value) {
- throw new Exception ();
- }
- public void Insert (int index, object value) {
- throw new Exception ();
- }
- public void Remove (object value) {
- throw new Exception ();
- }
- public bool IsFixedSize {
- get { return false; }
- }
- public bool IsReadOnly {
- get { return true; }
- }
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // "Item cannot be added to a read-only or fixed-size list."
- public void AddNew_ReadOnly ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new ReadOnlyList ();
- object o = source.AddNew ();
- }
- [Test]
- [ExpectedException (typeof (InvalidOperationException))]
- // "AddNew cannot be called on the 'System.String' type. This type does not have a public default constructor. You can call AddNew on the 'System.String' type if you set AllowNew=true and handle the AddingNew event."
- public void AddNew_Invalid ()
- {
- BindingSource source = new BindingSource ();
- source.DataSource = new List<string>();
- object o = source.AddNew ();
- }
- [Test]
- public void BindingSuspended1 ()
- {
- /* how does this property work? */
- BindingSource source = new BindingSource ();
- source.DataSource = new List<string>();
- Assert.IsTrue (source.IsBindingSuspended, "1");
- source.SuspendBinding ();
- Assert.IsTrue (source.IsBindingSuspended, "2");
- source.ResumeBinding ();
- Assert.IsTrue (source.IsBindingSuspended, "3");
- source.ResumeBinding ();
- Assert.IsTrue (source.IsBindingSuspended, "4");
- }
- class BindingListViewPoker : BindingList<string>, IBindingListView
- {
- public bool supports_filter;
- public bool supports_advanced_sorting;
- public string Filter {
- get { return ""; }
- set { }
- }
- public ListSortDescriptionCollection SortDescriptions {
- get { return null; }
- }
- public bool SupportsAdvancedSorting {
- get { return supports_advanced_sorting; }
- }
- public bool SupportsFiltering {
- get { return supports_filter; }
- }
- public void ApplySort (ListSortDescriptionCollection sorts)
- {
- }
- public void RemoveFilter ()
- {
- }
- }
- [Test]
- public void SupportsFilter ()
- {
- BindingListViewPoker c = new BindingListViewPoker ();
- BindingSource source = new BindingSource ();
- // because the default list is a BindingList<object>
- Assert.IsFalse (source.SupportsFiltering, "1");
- source.DataSource = c;
- // the DataSource is IBindingListView, but
- // SupportsFilter is false.
- Assert.IsFalse (source.SupportsFiltering, "2");
- c.supports_filter = true;
- Assert.IsTrue (source.SupportsFiltering, "3");
- }
- [Test]
- public void SupportsAdvancedSorting ()
- {
- BindingListViewPoker c = new BindingListViewPoker ();
- BindingSource source = new BindingSource ();
- // because the default list is a BindingList<object>
- Assert.IsFalse (source.SupportsAdvancedSorting, "1");
- source.DataSource = c;
- // the DataSource is IBindingListView, but
- // SupportsAdvancedSorting is false.
- Assert.IsFalse (source.SupportsAdvancedSorting, "2");
- c.supports_advanced_sorting = true;
- Assert.IsTrue (source.SupportsAdvancedSorting, "3");
- }
- class IBindingListPoker : BindingList<string>, IBindingList {
- public void AddIndex (PropertyDescriptor property)
- {
- }
- public void ApplySort (PropertyDescriptor property, ListSortDirection direction)
- {
- }
- public int Find (PropertyDescriptor property, object key)
- {
- throw new NotImplementedException ();
- }
- public void RemoveIndex (PropertyDescriptor property)
- {
- }
- public void RemoveSort ()
- {
- }
- public bool IsSorted {
- get { throw new NotImplementedException (); }
- }
- public ListSortDirection SortDirection {
- get { throw new NotImplementedException (); }
- }
- public PropertyDescriptor SortProperty {
- get { throw new NotImplementedException (); }
- }
- public bool SupportsChangeNotification {
- get { return supports_change_notification; }
- }
- public bool SupportsSearching {
- get { return supports_searching; }
- }
- public bool SupportsSorting {
- get { return supports_sorting; }
- }
- public bool supports_change_notification;
- public bool supports_searching;
- public bool supports_sorting;
- }
- [Test]
- public void SupportsSearching ()
- {
- IBindingListPoker c = new IBindingListPoker ();
- BindingSource source = new BindingSource ();
- // because the default list is a BindingList<object>
- Assert.IsFalse (source.SupportsSearching, "1");
- source.DataSource = c;
- // the DataSource is IBindingList, but
- // SupportsSearching is false.
- Assert.IsFalse (source.SupportsSearching, "2");
- c.supports_searching = true;
- Console.WriteLine ("set c.supports_searching to {0}, so c.SupportsSearching = {1}",
- c.supports_searching, c.SupportsSearching);
- Assert.IsTrue (source.SupportsSearching, "3");
- }
- [Test]
- public void SupportsSorting ()
- {
- IBindingListPoker c = new IBindingListPoker ();
- BindingSource source = new BindingSource ();
- // because the default list is a BindingList<object>
- Assert.IsFalse (source.SupportsSorting, "1");
- source.DataSource = c;
- // the DataSource is IBindingList, but
- // SupportsSorting is false.
- Assert.IsFalse (source.SupportsSorting, "2");
- c.supports_sorting = true;
- Assert.IsTrue (source.SupportsSorting, "3");
- }
- [Test]
- public void SupportsChangeNotification ()
- {
- IBindingListPoker c = new IBindingListPoker ();
- BindingSource source = new BindingSource ();
- // because the default list is a BindingList<object>
- Assert.IsTrue (source.SupportsChangeNotification, "1");
- source.DataSource = c;
- // the DataSource is IBindingList, but
- // SupportsChangeNotification is false.
- Assert.IsTrue (source.SupportsChangeNotification, "2");
- c.supports_change_notification = true;
- Assert.IsTrue (source.SupportsChangeNotification, "3");
- }
- [Test]
- public void InitializedEvent ()
- {
- // XXX this test is officially useless. does
- // BindingSource even raise the event? it
- // seems to always be initialized.
- BindingSource source = new BindingSource ();
- ISupportInitializeNotification n = (ISupportInitializeNotification)source;
- bool event_handled = false;
- n.Initialized += delegate (object sender, EventArgs e) {
- event_handled = true;
- };
- Assert.IsTrue (n.IsInitialized, "1");
- source.DataSource = "hi";
- Assert.IsTrue (n.IsInitialized, "2");
- Assert.IsFalse (event_handled, "3");
- }
- }
- }
- #endif
|