// DataViewTest.cs - Nunit Test Cases for for testing the DataView // class // Authors: // Punit Kumar Todi ( punit_todi@da-iict.org ) // Patrick Kalkman kalkman@cistron.nl // Umadevi S (sumadevi@novell.com) // Atsushi Enomoto (atsushi@ximian.com) // Sureshkumar T // // (C) 2003 Patrick Kalkman // // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com) // // 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. // using NUnit.Framework; using System; using System.Data; using System.ComponentModel; using System.IO; namespace MonoTests.System.Data { [TestFixture] public class DataViewTest : Assertion { DataTable dataTable; DataView dataView; Random rndm; int seed, rowCount; ListChangedEventArgs listChangedArgs; TextWriter eventWriter; [SetUp] public void GetReady () { dataTable = new DataTable ("itemTable"); DataColumn dc1 = new DataColumn ("itemId"); DataColumn dc2 = new DataColumn ("itemName"); DataColumn dc3 = new DataColumn ("itemPrice"); DataColumn dc4 = new DataColumn ("itemCategory"); dataTable.Columns.Add (dc1); dataTable.Columns.Add (dc2); dataTable.Columns.Add (dc3); dataTable.Columns.Add (dc4); DataRow dr; seed = 123; rowCount = 5; rndm = new Random (seed); for (int i = 1; i <= rowCount; i++) { dr = dataTable.NewRow (); dr["itemId"] = "item " + i; dr["itemName"] = "name " + rndm.Next (); dr["itemPrice"] = "Rs. " + (rndm.Next () % 1000); dr["itemCategory"] = "Cat " + ((rndm.Next () % 10) + 1); dataTable.Rows.Add (dr); } dataTable.AcceptChanges (); dataView = new DataView (dataTable); dataView.ListChanged += new ListChangedEventHandler (OnListChanged); listChangedArgs = null; } protected void OnListChanged (object sender, ListChangedEventArgs args) { listChangedArgs = args; // for debugging /*Console.WriteLine("EventType :: " + listChangedArgs.ListChangedType + " oldIndex :: " + listChangedArgs.OldIndex + " NewIndex :: " + listChangedArgs.NewIndex);*/ } private void PrintTableOrView (DataTable t, string label) { Console.WriteLine ("\n" + label); for (int i = 0; i