New tests.
[mono.git] / mcs / class / System.Data / Test / System.Data.Sql / SqlNotificationRequestTest.cs
1 //
2 // SqlNotificationRequestTest.cs - NUnit Test Cases for testing
3 // System.Data.Sql.SqlNotificationRequest
4 //
5 // Author:
6 //      Gert Driesen (drieseng@users.sourceforge.net)
7 //
8 // Copyright (c) 2008 Gert Driesen
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 //
29
30 #if NET_2_0
31
32 using System;
33 using System.Data.Sql;
34
35 using NUnit.Framework;
36
37 namespace MonoTests.System.Data.Sql
38 {
39         [TestFixture]
40         public class SqlNotificationRequestTest
41         {
42                 [Test] // ctor ()
43                 public void Constructor1 ()
44                 {
45                         SqlNotificationRequest nr = new SqlNotificationRequest ();
46                         Assert.IsNull (nr.Options, "#1");
47                         Assert.AreEqual (0, nr.Timeout, "#2");
48                         Assert.IsNull (nr.UserData, "#3");
49                 }
50
51                 [Test] // ctor (String, String, Int32)
52                 public void Constructor2 ()
53                 {
54                         SqlNotificationRequest nr;
55                         
56                         nr = new SqlNotificationRequest ("UD", "options", 5);
57                         Assert.AreEqual ("options", nr.Options, "#A1");
58                         Assert.AreEqual (5, nr.Timeout, "#A2");
59                         Assert.AreEqual ("UD", nr.UserData, "#A3");
60
61                         nr = new SqlNotificationRequest (string.Empty, " ", 0);
62                         Assert.AreEqual (" ", nr.Options, "#B1");
63                         Assert.AreEqual (0, nr.Timeout, "#B2");
64                         Assert.AreEqual (string.Empty, nr.UserData, "#B3");
65
66                         nr = new SqlNotificationRequest (" ", "O", int.MaxValue);
67                         Assert.AreEqual ("O", nr.Options, "#C1");
68                         Assert.AreEqual (int.MaxValue, nr.Timeout, "#C2");
69                         Assert.AreEqual (" ", nr.UserData, "#C3");
70
71                         nr = new SqlNotificationRequest ((string) null, "O", 7);
72                         Assert.AreEqual ("O", nr.Options, "#D1");
73                         Assert.AreEqual (7, nr.Timeout, "#D2");
74                         Assert.IsNull (nr.UserData, "#D3");
75
76                         nr = new SqlNotificationRequest ("UD", (string) null, 14);
77                         Assert.IsNull (nr.Options, "#E1");
78                         Assert.AreEqual (14, nr.Timeout, "#E2");
79                         Assert.AreEqual ("UD", nr.UserData, "#E3");
80
81                         nr = new SqlNotificationRequest (new string ('A', 0xffff), new string ('X', 0xffff), 3);
82                         Assert.AreEqual (new string ('X', 0xffff), nr.Options, "#F1");
83                         Assert.AreEqual (3, nr.Timeout, "#F2");
84                         Assert.AreEqual (new string ('A', 0xffff), nr.UserData, "#F3");
85                 }
86
87                 [Test] // ctor (String, String, Int32)
88                 public void Constructor2_Options_ExceedMaxLength ()
89                 {
90                         string options = new string ('X', 0x10000);
91                         try {
92                                 new SqlNotificationRequest ("UD", options, 5);
93                                 Assert.Fail ("#1");
94                         } catch (ArgumentOutOfRangeException ex) {
95                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
96                                 Assert.IsNull (ex.InnerException, "#3");
97                                 Assert.IsNotNull (ex.Message, "#4");
98                                 Assert.AreEqual ("Service", ex.ParamName, "#5");
99                         }
100                 }
101
102                 [Test] // ctor (String, String, Int32)
103                 public void Constructor2_Timeout_Negative ()
104                 {
105                         try {
106                                 new SqlNotificationRequest ("UD", "options", -1);
107                                 Assert.Fail ("#1");
108                         } catch (ArgumentOutOfRangeException ex) {
109                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
110                                 Assert.IsNull (ex.InnerException, "#3");
111                                 Assert.IsNotNull (ex.Message, "#4");
112                                 Assert.AreEqual ("Timeout", ex.ParamName, "#5");
113                         }
114                 }
115
116                 [Test] // ctor (String, String, Int32)
117                 public void Constructor2_UserData_ExceedMaxLength ()
118                 {
119                         string userData = new string ('X', 0x10000);
120                         try {
121                                 new SqlNotificationRequest (userData, "options", 5);
122                                 Assert.Fail ("#1");
123                         } catch (ArgumentOutOfRangeException ex) {
124                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
125                                 Assert.IsNull (ex.InnerException, "#3");
126                                 Assert.IsNotNull (ex.Message, "#4");
127                                 Assert.AreEqual ("UserData", ex.ParamName, "#5");
128                         }
129                 }
130
131                 [Test]
132                 public void Options ()
133                 {
134                         SqlNotificationRequest nr = new SqlNotificationRequest ();
135                         nr.Options = "XYZ";
136                         Assert.AreEqual ("XYZ", nr.Options, "#1");
137                         nr.Options = null;
138                         Assert.IsNull (nr.Options, "#2");
139                         nr.Options = " \r ";
140                         Assert.AreEqual (" \r ", nr.Options, "#3");
141                         nr.Options = string.Empty;
142                         Assert.AreEqual (string.Empty, nr.Options, "#4");
143                         nr.Options = new string ('X', 0xffff);
144                         Assert.AreEqual (new string ('X', 0xffff), nr.Options, "#5");
145                 }
146
147                 [Test]
148                 public void Options_Value_ExceedMaxLength ()
149                 {
150                         SqlNotificationRequest nr = new SqlNotificationRequest ();
151                         string options = new string ('X', 0x10000);
152
153                         try {
154                                 nr.Options = options;
155                                 Assert.Fail ("#1");
156                         } catch (ArgumentOutOfRangeException ex) {
157                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
158                                 Assert.IsNull (ex.InnerException, "#3");
159                                 Assert.IsNotNull (ex.Message, "#4");
160                                 Assert.AreEqual ("Service", ex.ParamName, "#5");
161                         }
162                 }
163
164                 [Test]
165                 public void Timeout ()
166                 {
167                         SqlNotificationRequest nr = new SqlNotificationRequest ();
168                         nr.Timeout = 5;
169                         Assert.AreEqual (5, nr.Timeout, "#1");
170                         nr.Timeout = 0;
171                         Assert.AreEqual (0, nr.Timeout, "#2");
172                         nr.Timeout = int.MaxValue;
173                         Assert.AreEqual (int.MaxValue, nr.Timeout, "#3");
174                 }
175
176                 [Test]
177                 public void Timeout_Value_Negative ()
178                 {
179                         SqlNotificationRequest nr = new SqlNotificationRequest ();
180                         
181                         try {
182                                 nr.Timeout = -1;
183                                 Assert.Fail ("#1");
184                         } catch (ArgumentOutOfRangeException ex) {
185                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
186                                 Assert.IsNull (ex.InnerException, "#3");
187                                 Assert.IsNotNull (ex.Message, "#4");
188                                 Assert.AreEqual ("Timeout", ex.ParamName, "#5");
189                         }
190                 }
191
192                 [Test]
193                 public void UserData ()
194                 {
195                         SqlNotificationRequest nr = new SqlNotificationRequest ();
196                         nr.UserData = "XYZ";
197                         Assert.AreEqual ("XYZ", nr.UserData, "#1");
198                         nr.UserData = null;
199                         Assert.IsNull (nr.UserData, "#2");
200                         nr.UserData = " \r ";
201                         Assert.AreEqual (" \r ", nr.UserData, "#3");
202                         nr.UserData = string.Empty;
203                         Assert.AreEqual (string.Empty, nr.UserData, "#4");
204                         nr.UserData = new string ('X', 0xffff);
205                         Assert.AreEqual (new string ('X', 0xffff), nr.UserData, "#5");
206                 }
207
208                 [Test]
209                 public void UserData_Value_ExceedMaxLength ()
210                 {
211                         SqlNotificationRequest nr = new SqlNotificationRequest ();
212                         string userData = new string ('X', 0x10000);
213
214                         try {
215                                 nr.UserData = userData;
216                                 Assert.Fail ("#1");
217                         } catch (ArgumentOutOfRangeException ex) {
218                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
219                                 Assert.IsNull (ex.InnerException, "#3");
220                                 Assert.IsNotNull (ex.Message, "#4");
221                                 Assert.AreEqual ("UserData", ex.ParamName, "#5");
222                         }
223                 }
224         }
225 }
226
227 #endif