1 // 2 // DataViewManagerTest.cs 3 // 4 // Author: 5 // Atsushi Enomoto <atsushi@ximian.com> 6 // 7 // (C) 2005 Novell Inc, 8 // 9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com) 10 // 11 // Permission is hereby granted, free of charge, to any person obtaining 12 // a copy of this software and associated documentation files (the 13 // "Software"), to deal in the Software without restriction, including 14 // without limitation the rights to use, copy, modify, merge, publish, 15 // distribute, sublicense, and/or sell copies of the Software, and to 16 // permit persons to whom the Software is furnished to do so, subject to 17 // the following conditions: 18 // 19 // The above copyright notice and this permission notice shall be 20 // included in all copies or substantial portions of the Software. 21 // 22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 29 // 30 31 using NUnit.Framework; 32 using System; 33 using System.Data; 34 using System.ComponentModel; 35 36 namespace MonoTests.System.Data 37 { 38 [TestFixture] 39 public class DataViewManagerTest 40 { 41 [Test] Ctor()42 public void Ctor () 43 { 44 string defaultString = "<DataViewSettingCollectionString></DataViewSettingCollectionString>"; 45 string current = @"<DataViewSettingCollectionString><table2-1 Sort="""" RowFilter="""" RowStateFilter=""CurrentRows""/></DataViewSettingCollectionString>"; 46 string deleted = @"<DataViewSettingCollectionString><table2-1 Sort="""" RowFilter="""" RowStateFilter=""Deleted""/></DataViewSettingCollectionString>"; 47 48 DataViewManager m = new DataViewManager (null); 49 Assert.IsNull (m.DataSet); 50 Assert.AreEqual ("", m.DataViewSettingCollectionString); 51 Assert.IsNotNull (m.DataViewSettings); 52 DataSet ds = new DataSet ("ds"); 53 m.DataSet = ds; 54 Assert.AreEqual (defaultString, m.DataViewSettingCollectionString, 55 "default#1"); 56 57 DataSet ds2 = new DataSet ("ds2"); 58 Assert.AreEqual (defaultString, ds.DefaultViewManager.DataViewSettingCollectionString, 59 "default#2"); 60 DataTable dt2_1 = new DataTable ("table2-1"); 61 dt2_1.Namespace ="urn:foo"; // It is ignored though. 62 ds2.Tables.Add (dt2_1); 63 m.DataSet = ds2; 64 Assert.AreEqual (current, m.DataViewSettingCollectionString, "#3"); 65 66 // Note that " Deleted " is trimmed. 67 m.DataViewSettingCollectionString = @"<DataViewSettingCollectionString><table2-1 Sort='' RowFilter='' RowStateFilter=' Deleted '/></DataViewSettingCollectionString>"; 68 Assert.AreEqual (deleted, m.DataViewSettingCollectionString, "#4"); 69 70 m.DataSet = ds2; //resets modified string. 71 Assert.AreEqual (current, m.DataViewSettingCollectionString, "#5"); 72 73 m.DataViewSettingCollectionString = @"<DataViewSettingCollectionString><table2-1 Sort='' RowFilter='' RowStateFilter='Deleted'/></DataViewSettingCollectionString>"; 74 // it does not clear anything. 75 m.DataViewSettingCollectionString = "<DataViewSettingCollectionString/>"; 76 Assert.AreEqual (deleted, m.DataViewSettingCollectionString, "#6"); 77 78 // text node is not rejected (ignored). 79 // RowFilter is not examined. 80 m.DataViewSettingCollectionString = "<DataViewSettingCollectionString>blah<table2-1 RowFilter='a=b' ApplyDefaultSort='true' /></DataViewSettingCollectionString>"; 81 // LAMESPEC: MS.NET ignores ApplyDefaultSort. 82 // Assert.AreEqual (@"<DataViewSettingCollectionString><table2-1 Sort="""" RowFilter=""a=b"" RowStateFilter=""Deleted""/></DataViewSettingCollectionString>", m.DataViewSettingCollectionString, "#7"); 83 } 84 85 [Test] 86 [ExpectedException (typeof (DataException))] SetNullDataSet()87 public void SetNullDataSet () 88 { 89 DataViewManager m = new DataViewManager (null); 90 m.DataSet = null; // DataException 91 } 92 93 [Test] 94 [ExpectedException (typeof (NullReferenceException))] SpecifyNonExistentTable()95 public void SpecifyNonExistentTable () 96 { 97 DataViewManager m = new DataViewManager (null); 98 // NullReferenceException is thrown. 99 m.DataViewSettingCollectionString = "<DataViewSettingCollectionString><table1-1 RowFilter='a=b' /></DataViewSettingCollectionString>"; 100 } 101 102 [Test] 103 [ExpectedException (typeof (DataException))] SetIncorrectRootElement()104 public void SetIncorrectRootElement () 105 { 106 DataViewManager m = new DataViewManager (null); 107 m.DataViewSettingCollectionString = "<foo/>"; 108 } 109 } 110 } 111