2 // SqlNotificationRequestTest.cs - NUnit Test Cases for testing
3 // System.Data.Sql.SqlNotificationRequest
6 // Gert Driesen (drieseng@users.sourceforge.net)
8 // Copyright (c) 2008 Gert Driesen
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:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
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.
32 using System.Data.Sql;
34 using NUnit.Framework;
36 namespace MonoTests.System.Data.Sql
39 public class SqlNotificationRequestTest
42 public void Constructor1 ()
44 SqlNotificationRequest nr = new SqlNotificationRequest ();
45 Assert.IsNull (nr.Options, "#1");
46 Assert.AreEqual (0, nr.Timeout, "#2");
47 Assert.IsNull (nr.UserData, "#3");
50 [Test] // ctor (String, String, Int32)
51 public void Constructor2 ()
53 SqlNotificationRequest nr;
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");
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");
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");
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");
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");
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");
86 [Test] // ctor (String, String, Int32)
87 public void Constructor2_Options_ExceedMaxLength ()
89 string options = new string ('X', 0x10000);
91 new SqlNotificationRequest ("UD", options, 5);
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");
101 [Test] // ctor (String, String, Int32)
102 public void Constructor2_Timeout_Negative ()
105 new SqlNotificationRequest ("UD", "options", -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");
115 [Test] // ctor (String, String, Int32)
116 public void Constructor2_UserData_ExceedMaxLength ()
118 string userData = new string ('X', 0x10000);
120 new SqlNotificationRequest (userData, "options", 5);
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");
131 public void Options ()
133 SqlNotificationRequest nr = new SqlNotificationRequest ();
135 Assert.AreEqual ("XYZ", nr.Options, "#1");
137 Assert.IsNull (nr.Options, "#2");
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");
147 public void Options_Value_ExceedMaxLength ()
149 SqlNotificationRequest nr = new SqlNotificationRequest ();
150 string options = new string ('X', 0x10000);
153 nr.Options = options;
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");
164 public void Timeout ()
166 SqlNotificationRequest nr = new SqlNotificationRequest ();
168 Assert.AreEqual (5, nr.Timeout, "#1");
170 Assert.AreEqual (0, nr.Timeout, "#2");
171 nr.Timeout = int.MaxValue;
172 Assert.AreEqual (int.MaxValue, nr.Timeout, "#3");
176 public void Timeout_Value_Negative ()
178 SqlNotificationRequest nr = new SqlNotificationRequest ();
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");
192 public void UserData ()
194 SqlNotificationRequest nr = new SqlNotificationRequest ();
196 Assert.AreEqual ("XYZ", nr.UserData, "#1");
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");
208 public void UserData_Value_ExceedMaxLength ()
210 SqlNotificationRequest nr = new SqlNotificationRequest ();
211 string userData = new string ('X', 0x10000);
214 nr.UserData = userData;
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");