2 // DataViewManagerTest.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2005 Novell Inc,
9 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using NUnit.Framework;
34 using System.ComponentModel;
36 namespace MonoTests.System.Data
39 public class DataViewManagerTest : Assertion
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>";
48 DataViewManager m = new DataViewManager (null);
49 AssertNull (m.DataSet);
50 AssertEquals ("", m.DataViewSettingCollectionString);
51 AssertNotNull (m.DataViewSettings);
52 DataSet ds = new DataSet ("ds");
54 AssertEquals ("default#1", defaultString,
55 m.DataViewSettingCollectionString);
57 DataSet ds2 = new DataSet ("ds2");
58 AssertEquals ("default#2", defaultString,
59 ds.DefaultViewManager.DataViewSettingCollectionString);
60 DataTable dt2_1 = new DataTable ("table2-1");
61 dt2_1.Namespace ="urn:foo"; // It is ignored though.
62 ds2.Tables.Add (dt2_1);
64 AssertEquals ("#3", current, m.DataViewSettingCollectionString);
66 // Note that " Deleted " is trimmed.
67 m.DataViewSettingCollectionString = @"<DataViewSettingCollectionString><table2-1 Sort='' RowFilter='' RowStateFilter=' Deleted '/></DataViewSettingCollectionString>";
68 AssertEquals ("#4", deleted, m.DataViewSettingCollectionString);
70 m.DataSet = ds2; //resets modified string.
71 AssertEquals ("#5", current, m.DataViewSettingCollectionString);
73 m.DataViewSettingCollectionString = @"<DataViewSettingCollectionString><table2-1 Sort='' RowFilter='' RowStateFilter='Deleted'/></DataViewSettingCollectionString>";
74 // it does not clear anything.
75 m.DataViewSettingCollectionString = "<DataViewSettingCollectionString/>";
76 AssertEquals ("#6", deleted, m.DataViewSettingCollectionString);
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 // AssertEquals ("#7", @"<DataViewSettingCollectionString><table2-1 Sort="""" RowFilter=""a=b"" RowStateFilter=""Deleted""/></DataViewSettingCollectionString>", m.DataViewSettingCollectionString);
86 [ExpectedException (typeof (DataException))]
87 public void SetNullDataSet ()
89 DataViewManager m = new DataViewManager (null);
90 m.DataSet = null; // DataException
94 [ExpectedException (typeof (NullReferenceException))]
95 public void SpecifyNonExistentTable ()
97 DataViewManager m = new DataViewManager (null);
98 // NullReferenceException is thrown.
99 m.DataViewSettingCollectionString = "<DataViewSettingCollectionString><table1-1 RowFilter='a=b' /></DataViewSettingCollectionString>";
103 [ExpectedException (typeof (DataException))]
104 public void SetIncorrectRootElement ()
106 DataViewManager m = new DataViewManager (null);
107 m.DataViewSettingCollectionString = "<foo/>";