namespace MonoTests.System.Windows.Forms
{
[TestFixture]
- class GridTableStylesCollectionTests : Assertion
+ public class GridTableStylesCollectionTest : TestHelper
{
private bool eventhandled;
private object Element;
private CollectionChangeAction Action;
+ private int times;
- [TearDown]
- public void Clean() {}
-
- [SetUp]
- public void GetReady ()
+ [Test]
+ public void TestDefaultValues ()
{
+ DataGrid grid = new DataGrid ();
+ GridTableStylesCollection sc = grid.TableStyles;
+
+ Assert.AreEqual (false, sc.IsSynchronized, "IsSynchronized property");
+ Assert.AreEqual (0, sc.Count, "Count");
+ Assert.AreEqual (sc, sc.SyncRoot, "SyncRoot property");
+ Assert.AreEqual (false, ((IList)sc).IsFixedSize, "IsFixedSize property");
+ Assert.AreEqual (false, sc.IsReadOnly, "IsReadOnly property");
}
[Test]
- public void TestDefaultValues ()
+ public void TestMappingNameChanged ()
{
DataGrid grid = new DataGrid ();
GridTableStylesCollection sc = grid.TableStyles;
+ sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
- AssertEquals ("IsSynchronized property", false, sc.IsSynchronized);
- AssertEquals ("SyncRoot property", false, sc.IsSynchronized);
- AssertEquals ("IsReadOnly property", false, sc.IsSynchronized);
+ // Add single
+ DataGridTableStyle ts = new DataGridTableStyle ();
+ ts.MappingName = "Table1";
+ sc.Add (ts);
+ ResetEventData ();
+ ts.MappingName = "Table2";
+
+ Assert.AreEqual (true, eventhandled, "A1");
+ Assert.AreEqual (null, Element, "A2");
+ Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
}
+ // Fails due to:
+ // "The TableStyles collection already has a TableStyle with this mapping name"
+ // There is a TODO in DataGrid about allowing TableStyles to have the same mapping name.
[Test]
+ [NUnit.Framework.Category ("NotWorking")]
public void TestAdd ()
{
DataGrid grid = new DataGrid ();
DataGridTableStyle ts = new DataGridTableStyle ();
ts.MappingName = "Table1";
sc.Add (ts);
- AssertEquals (true, eventhandled);
- AssertEquals (ts, Element);
- AssertEquals (CollectionChangeAction.Add, Action);
+ Assert.AreEqual (true, eventhandled, "A1");
+ Assert.AreEqual (ts, Element, "A2");
+ Assert.AreEqual (CollectionChangeAction.Add, Action, "A3");
// Add multiple
ResetEventData ();
sc.AddRange (new DataGridTableStyle [] {new DataGridTableStyle (), new DataGridTableStyle ()});
- AssertEquals (true, eventhandled);
- AssertEquals (null, Element);
- AssertEquals (CollectionChangeAction.Refresh, Action);
+ Assert.AreEqual (true, eventhandled, "A4");
+ Assert.AreEqual (null, Element, "A5");
+ Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A6");
+ }
+
+ [Test]
+ public void TestAddRange ()
+ {
+ DataGrid grid = new DataGrid ();
+ GridTableStylesCollection sc = grid.TableStyles;
+ sc.CollectionChanged += new CollectionChangeEventHandler (OnCollectionEventHandler);
+
+ ResetEventData ();
+ DataGridTableStyle ts1 = new DataGridTableStyle ();
+ ts1.MappingName = "Table1";
+
+ DataGridTableStyle ts2 = new DataGridTableStyle ();
+ ts2.MappingName = "Table2";
+ sc.AddRange (new DataGridTableStyle[] {ts1, ts2});
+
+ Assert.AreEqual (true, eventhandled, "A1");
+ Assert.AreEqual (null, Element, "A2");
+ Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A3");
+ Assert.AreEqual (1, times, "A4");
}
[Test]
ResetEventData ();
sc.Remove (ts2);
- AssertEquals (true, eventhandled);
- AssertEquals (ts2, Element);
- AssertEquals (CollectionChangeAction.Remove, Action);
- AssertEquals (2, sc.Count);
+ Assert.AreEqual (true, eventhandled, "A1");
+ Assert.AreEqual (ts2, Element, "A2");
+ Assert.AreEqual (CollectionChangeAction.Remove, Action, "A3");
+ Assert.AreEqual (2, sc.Count, "A4");
ResetEventData ();
sc.RemoveAt (0);
- AssertEquals (true, eventhandled);
- AssertEquals (ts1, Element);
- AssertEquals (CollectionChangeAction.Remove, Action);
- AssertEquals (1, sc.Count);
+ Assert.AreEqual (true, eventhandled, "A5");
+ Assert.AreEqual (ts1, Element, "A6");
+ Assert.AreEqual (CollectionChangeAction.Remove, Action, "A7");
+ Assert.AreEqual (1, sc.Count, "A8");
ResetEventData ();
sc.Clear ();
- AssertEquals (null, Element);
- AssertEquals (CollectionChangeAction.Refresh, Action);
+ Assert.AreEqual (null, Element, "A9");
+ Assert.AreEqual (CollectionChangeAction.Refresh, Action, "A10");
}
ResetEventData ();
IList ilist = (IList) sc;
- AssertEquals (1, ilist.IndexOf (ts2));
- AssertEquals (false, sc.Contains ("nothing"));
- AssertEquals (true, sc.Contains (ts3));
+ Assert.AreEqual (1, ilist.IndexOf (ts2), "A1");
+ Assert.AreEqual (false, sc.Contains ("nothing"), "A2");
+ Assert.AreEqual (true, sc.Contains (ts3), "A3");
}
private void ResetEventData ()
{
+ times = 0;
eventhandled = false;
Element = null;
Action = (CollectionChangeAction) 0;
}
- private void OnEventHandler (object sender, EventArgs e)\r
- {\r
- eventhandled = true;\r
- }
+ //private void OnEventHandler (object sender, EventArgs e)
+ //{
+ // eventhandled = true;
+ //}
- private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)\r
- {\r
+ private void OnCollectionEventHandler (object sender, CollectionChangeEventArgs e)
+ {
+ times++;
eventhandled = true;
Element = e.Element;
- Action = e.Action; \r
+ Action = e.Action;
}
+
}
}