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.
33 using System.Data.Sql;
35 using NUnit.Framework;
37 namespace MonoTests.System.Data.Sql
40 public class SqlNotificationRequestTest
43 public void Constructor1 ()
45 SqlNotificationRequest nr = new SqlNotificationRequest ();
46 Assert.IsNull (nr.Options, "#1");
47 Assert.AreEqual (0, nr.Timeout, "#2");
48 Assert.IsNull (nr.UserData, "#3");
51 [Test] // ctor (String, String, Int32)
52 public void Constructor2 ()
54 SqlNotificationRequest nr;
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");
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");
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");
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");
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");
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");
87 [Test] // ctor (String, String, Int32)
88 public void Constructor2_Options_ExceedMaxLength ()
90 string options = new string ('X', 0x10000);
92 new SqlNotificationRequest ("UD", options, 5);
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");
102 [Test] // ctor (String, String, Int32)
103 public void Constructor2_Timeout_Negative ()
106 new SqlNotificationRequest ("UD", "options", -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");
116 [Test] // ctor (String, String, Int32)
117 public void Constructor2_UserData_ExceedMaxLength ()
119 string userData = new string ('X', 0x10000);
121 new SqlNotificationRequest (userData, "options", 5);
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");
132 public void Options ()
134 SqlNotificationRequest nr = new SqlNotificationRequest ();
136 Assert.AreEqual ("XYZ", nr.Options, "#1");
138 Assert.IsNull (nr.Options, "#2");
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");
148 public void Options_Value_ExceedMaxLength ()
150 SqlNotificationRequest nr = new SqlNotificationRequest ();
151 string options = new string ('X', 0x10000);
154 nr.Options = options;
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");
165 public void Timeout ()
167 SqlNotificationRequest nr = new SqlNotificationRequest ();
169 Assert.AreEqual (5, nr.Timeout, "#1");
171 Assert.AreEqual (0, nr.Timeout, "#2");
172 nr.Timeout = int.MaxValue;
173 Assert.AreEqual (int.MaxValue, nr.Timeout, "#3");
177 public void Timeout_Value_Negative ()
179 SqlNotificationRequest nr = new SqlNotificationRequest ();
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");
193 public void UserData ()
195 SqlNotificationRequest nr = new SqlNotificationRequest ();
197 Assert.AreEqual ("XYZ", nr.UserData, "#1");
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");
209 public void UserData_Value_ExceedMaxLength ()
211 SqlNotificationRequest nr = new SqlNotificationRequest ();
212 string userData = new string ('X', 0x10000);
215 nr.UserData = userData;
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");