Merge branch 'master'
[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
31 using System;
32 using System.Data.Sql;
33
34 using NUnit.Framework;
35
36 namespace MonoTests.System.Data.Sql
37 {
38         [TestFixture]
39         public class SqlNotificationRequestTest
40         {
41                 [Test] // ctor ()
42                 public void Constructor1 ()
43                 {
44                         SqlNotificationRequest nr = new SqlNotificationRequest ();
45                         Assert.IsNull (nr.Options, "#1");
46                         Assert.AreEqual (0, nr.Timeout, "#2");
47                         Assert.IsNull (nr.UserData, "#3");
48                 }
49
50                 [Test] // ctor (String, String, Int32)
51                 public void Constructor2 ()
52                 {
53                         SqlNotificationRequest nr;
54                         
55                         nr = new SqlNotificationRequest ("UD", "options", 5);
56                         Assert.AreEqual ("options", nr.Options, "#A1");
57                         Assert.AreEqual (5, nr.Timeout, "#A2");
58                         Assert.AreEqual ("UD", nr.UserData, "#A3");
59
60                         nr = new SqlNotificationRequest (string.Empty, " ", 0);
61                         Assert.AreEqual (" ", nr.Options, "#B1");
62                         Assert.AreEqual (0, nr.Timeout, "#B2");
63                         Assert.AreEqual (string.Empty, nr.UserData, "#B3");
64
65                         nr = new SqlNotificationRequest (" ", "O", int.MaxValue);
66                         Assert.AreEqual ("O", nr.Options, "#C1");
67                         Assert.AreEqual (int.MaxValue, nr.Timeout, "#C2");
68                         Assert.AreEqual (" ", nr.UserData, "#C3");
69
70                         nr = new SqlNotificationRequest ((string) null, "O", 7);
71                         Assert.AreEqual ("O", nr.Options, "#D1");
72                         Assert.AreEqual (7, nr.Timeout, "#D2");
73                         Assert.IsNull (nr.UserData, "#D3");
74
75                         nr = new SqlNotificationRequest ("UD", (string) null, 14);
76                         Assert.IsNull (nr.Options, "#E1");
77                         Assert.AreEqual (14, nr.Timeout, "#E2");
78                         Assert.AreEqual ("UD", nr.UserData, "#E3");
79
80                         nr = new SqlNotificationRequest (new string ('A', 0xffff), new string ('X', 0xffff), 3);
81                         Assert.AreEqual (new string ('X', 0xffff), nr.Options, "#F1");
82                         Assert.AreEqual (3, nr.Timeout, "#F2");
83                         Assert.AreEqual (new string ('A', 0xffff), nr.UserData, "#F3");
84                 }
85
86                 [Test] // ctor (String, String, Int32)
87                 public void Constructor2_Options_ExceedMaxLength ()
88                 {
89                         string options = new string ('X', 0x10000);
90                         try {
91                                 new SqlNotificationRequest ("UD", options, 5);
92                                 Assert.Fail ("#1");
93                         } catch (ArgumentOutOfRangeException ex) {
94                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
95                                 Assert.IsNull (ex.InnerException, "#3");
96                                 Assert.IsNotNull (ex.Message, "#4");
97                                 Assert.AreEqual ("Service", ex.ParamName, "#5");
98                         }
99                 }
100
101                 [Test] // ctor (String, String, Int32)
102                 public void Constructor2_Timeout_Negative ()
103                 {
104                         try {
105                                 new SqlNotificationRequest ("UD", "options", -1);
106                                 Assert.Fail ("#1");
107                         } catch (ArgumentOutOfRangeException ex) {
108                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
109                                 Assert.IsNull (ex.InnerException, "#3");
110                                 Assert.IsNotNull (ex.Message, "#4");
111                                 Assert.AreEqual ("Timeout", ex.ParamName, "#5");
112                         }
113                 }
114
115                 [Test] // ctor (String, String, Int32)
116                 public void Constructor2_UserData_ExceedMaxLength ()
117                 {
118                         string userData = new string ('X', 0x10000);
119                         try {
120                                 new SqlNotificationRequest (userData, "options", 5);
121                                 Assert.Fail ("#1");
122                         } catch (ArgumentOutOfRangeException ex) {
123                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
124                                 Assert.IsNull (ex.InnerException, "#3");
125                                 Assert.IsNotNull (ex.Message, "#4");
126                                 Assert.AreEqual ("UserData", ex.ParamName, "#5");
127                         }
128                 }
129
130                 [Test]
131                 public void Options ()
132                 {
133                         SqlNotificationRequest nr = new SqlNotificationRequest ();
134                         nr.Options = "XYZ";
135                         Assert.AreEqual ("XYZ", nr.Options, "#1");
136                         nr.Options = null;
137                         Assert.IsNull (nr.Options, "#2");
138                         nr.Options = " \r ";
139                         Assert.AreEqual (" \r ", nr.Options, "#3");
140                         nr.Options = string.Empty;
141                         Assert.AreEqual (string.Empty, nr.Options, "#4");
142                         nr.Options = new string ('X', 0xffff);
143                         Assert.AreEqual (new string ('X', 0xffff), nr.Options, "#5");
144                 }
145
146                 [Test]
147                 public void Options_Value_ExceedMaxLength ()
148                 {
149                         SqlNotificationRequest nr = new SqlNotificationRequest ();
150                         string options = new string ('X', 0x10000);
151
152                         try {
153                                 nr.Options = options;
154                                 Assert.Fail ("#1");
155                         } catch (ArgumentOutOfRangeException ex) {
156                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
157                                 Assert.IsNull (ex.InnerException, "#3");
158                                 Assert.IsNotNull (ex.Message, "#4");
159                                 Assert.AreEqual ("Service", ex.ParamName, "#5");
160                         }
161                 }
162
163                 [Test]
164                 public void Timeout ()
165                 {
166                         SqlNotificationRequest nr = new SqlNotificationRequest ();
167                         nr.Timeout = 5;
168                         Assert.AreEqual (5, nr.Timeout, "#1");
169                         nr.Timeout = 0;
170                         Assert.AreEqual (0, nr.Timeout, "#2");
171                         nr.Timeout = int.MaxValue;
172                         Assert.AreEqual (int.MaxValue, nr.Timeout, "#3");
173                 }
174
175                 [Test]
176                 public void Timeout_Value_Negative ()
177                 {
178                         SqlNotificationRequest nr = new SqlNotificationRequest ();
179                         
180                         try {
181                                 nr.Timeout = -1;
182                                 Assert.Fail ("#1");
183                         } catch (ArgumentOutOfRangeException ex) {
184                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
185                                 Assert.IsNull (ex.InnerException, "#3");
186                                 Assert.IsNotNull (ex.Message, "#4");
187                                 Assert.AreEqual ("Timeout", ex.ParamName, "#5");
188                         }
189                 }
190
191                 [Test]
192                 public void UserData ()
193                 {
194                         SqlNotificationRequest nr = new SqlNotificationRequest ();
195                         nr.UserData = "XYZ";
196                         Assert.AreEqual ("XYZ", nr.UserData, "#1");
197                         nr.UserData = null;
198                         Assert.IsNull (nr.UserData, "#2");
199                         nr.UserData = " \r ";
200                         Assert.AreEqual (" \r ", nr.UserData, "#3");
201                         nr.UserData = string.Empty;
202                         Assert.AreEqual (string.Empty, nr.UserData, "#4");
203                         nr.UserData = new string ('X', 0xffff);
204                         Assert.AreEqual (new string ('X', 0xffff), nr.UserData, "#5");
205                 }
206
207                 [Test]
208                 public void UserData_Value_ExceedMaxLength ()
209                 {
210                         SqlNotificationRequest nr = new SqlNotificationRequest ();
211                         string userData = new string ('X', 0x10000);
212
213                         try {
214                                 nr.UserData = userData;
215                                 Assert.Fail ("#1");
216                         } catch (ArgumentOutOfRangeException ex) {
217                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
218                                 Assert.IsNull (ex.InnerException, "#3");
219                                 Assert.IsNotNull (ex.Message, "#4");
220                                 Assert.AreEqual ("UserData", ex.ParamName, "#5");
221                         }
222                 }
223         }
224 }
225