[jenkins] Make the concurrent GC the default on mainline archtectures.
[mono.git] / mcs / class / System.Data / Test / System.Data / DataViewManagerTest.cs
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 : Assertion
40         {
41                 [Test]
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                         AssertNull (m.DataSet);
50                         AssertEquals ("", m.DataViewSettingCollectionString);
51                         AssertNotNull (m.DataViewSettings);
52                         DataSet ds = new DataSet ("ds");
53                         m.DataSet = ds;
54                         AssertEquals ("default#1", defaultString,
55                                 m.DataViewSettingCollectionString);
56
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);
63                         m.DataSet = ds2;
64                         AssertEquals ("#3", current, m.DataViewSettingCollectionString);
65
66                         // Note that " Deleted " is trimmed.
67                         m.DataViewSettingCollectionString = @"<DataViewSettingCollectionString><table2-1 Sort='' RowFilter='' RowStateFilter=' Deleted '/></DataViewSettingCollectionString>";
68                         AssertEquals ("#4", deleted, m.DataViewSettingCollectionString);
69
70                         m.DataSet = ds2; //resets modified string.
71                         AssertEquals ("#5", current, m.DataViewSettingCollectionString);
72
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);
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 //                      AssertEquals ("#7", @"<DataViewSettingCollectionString><table2-1 Sort="""" RowFilter=""a=b"" RowStateFilter=""Deleted""/></DataViewSettingCollectionString>", m.DataViewSettingCollectionString);
83                 }
84
85                 [Test]
86                 [ExpectedException (typeof (DataException))]
87                 public void SetNullDataSet ()
88                 {
89                         DataViewManager m = new DataViewManager (null);
90                         m.DataSet = null; // DataException
91                 }
92
93                 [Test]
94                 [ExpectedException (typeof (NullReferenceException))]
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))]
104                 public void SetIncorrectRootElement ()
105                 {
106                         DataViewManager m = new DataViewManager (null);
107                         m.DataViewSettingCollectionString = "<foo/>";
108                 }
109         }
110 }