Subversion Repository Public Repository

ConnectionOdbcSdk

Diff Revisions 10 vs 11 for /trunk/ConnectionServerOdbcIntegrationTests/UnitTests/ConnectionServerOdbcUnitTests.cs

Diff revisions: vs.
  @@ -111,6 +111,54 @@
111 111
112 112 #region Mocked Tests
113 113
114 + private void SetupVersionAndServerInfo(string pVersionString, bool pIsCoRes, params string[] pNeighborIds)
115 + {
116 + Reset();
117 + MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).
118 + Returns(new DbFetchResult() { Successful = true });
119 +
120 + if (pIsCoRes)
121 + {
122 + MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("coresident");
123 + }
124 + else
125 + {
126 + MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("");
127 + }
128 +
129 +
130 + DataTable oDtVer = new DataTable();
131 + oDtVer.Columns.Add("product", typeof(string));
132 + oDtVer.Rows.Add(pVersionString);
133 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
134 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = true });
135 +
136 + DataTable oDtLocation = new DataTable();
137 + oDtLocation.Columns.Add("DisplayName", typeof(string));
138 + oDtLocation.Columns.Add("ObjectID", typeof(string));
139 + oDtLocation.Columns.Add("SMTPDomain", typeof(string));
140 + oDtLocation.Columns.Add("HostAddress", typeof(string));
141 + oDtLocation.Rows.Add("name", "objectid", "smtpdomain", "hostaddress");
142 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_LocalVMS", out oDtLocation, false, null)).
143 + Returns(new DbFetchResult() { Successful = true });
144 +
145 + DataTable oDtNeighbor = new DataTable();
146 + oDtNeighbor.Columns.Add("ObjectId", typeof (string));
147 + foreach (string strObjectId in pNeighborIds)
148 + {
149 + oDtNeighbor.Rows.Add(strObjectId);
150 + }
151 + //post 9.x
152 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("Select ObjectId FROM vw_Location WHERE ObjectId <> ? ",
153 + out oDtNeighbor, false, It.IsAny<string>())).Returns(new DbFetchResult() { Successful = true });
154 +
155 + //pre 9.x
156 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("Select ObjectId FROM vw_NetworkTopology WHERE ObjectId <> NeighbourLocationObjectId " +
157 + "AND NeighbourLocationObjectId = ?",out oDtNeighbor, false, It.IsAny<string>())).
158 + Returns(new DbFetchResult() { Successful = true });
159 + }
160 +
161 +
114 162 [TestMethod]
115 163 public void UpdateDatabaseName_NullNameFailure()
116 164 {
  @@ -120,16 +168,147 @@
120 168 [TestMethod]
121 169 public void InitVersionTest_CoRes()
122 170 {
123 - MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(),It.IsAny<string>(),It.IsAny<string>(),It.IsAny<string>())).
124 - Returns(new DbFetchResult(){Successful = true});
171 + SetupVersionAndServerInfo("9.1.5.0", true);
172 + var res= MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
173 + Assert.IsTrue(res.Successful,"Login failed:"+res);
174 + Assert.IsTrue(MockServer.UnityVersionIsCoRes,"CoRes flag should be set to true");
175 + }
176 +
177 + [TestMethod]
178 + public void InitVersionTest_NotCoRes()
179 + {
180 + SetupVersionAndServerInfo("9.1.5.0", false);
181 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
182 + Assert.IsTrue(res.Successful, "Login failed:" + res);
183 + Assert.IsFalse(MockServer.UnityVersionIsCoRes, "CoRes flag should be set to false");
184 + }
185 +
186 + [TestMethod]
187 + public void InitVersionTest_FiveNeighborsPre95()
188 + {
189 + SetupVersionAndServerInfo("9.0.1.0", false,"one","two","three","four","five");
190 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
191 + Assert.IsTrue(res.Successful, "Login failed:" + res);
192 + Assert.IsTrue(MockServer.NeighborLocations.Count==5, "Neighbor count should be 5");
193 + }
194 +
195 + [TestMethod]
196 + public void InitVersionTest_FiveNeighborsPost95()
197 + {
198 + SetupVersionAndServerInfo("10.0.1.0", false, "one", "two", "three", "four", "five");
199 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
200 + Assert.IsTrue(res.Successful, "Login failed:" + res);
201 + Assert.IsTrue(MockServer.NeighborLocations.Count == 5, "Neighbor count should be 5");
202 + }
203 +
204 + [TestMethod]
205 + public void InitVersionTest_ErrorVersionInfoFetch()
206 + {
207 + SetupVersionAndServerInfo("10.0.1.0", false, "one", "two", "three", "four", "five");
125 208
126 - MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("coresident");
209 + DataTable oDtVer = new DataTable();
210 + oDtVer.Columns.Add("product", typeof(string));
211 + oDtVer.Rows.Add("version");
212 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
213 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = false });
214 +
215 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
216 + Assert.IsFalse(res.Successful, "Login should have failed:" + res);
217 + }
218 +
219 + [TestMethod]
220 + public void InitVersionTest_VersionInfoFetchNoResults()
221 + {
222 + SetupVersionAndServerInfo("10.0.1.0", false, "one", "two", "three", "four", "five");
127 223
128 224 DataTable oDtVer = new DataTable();
129 225 oDtVer.Columns.Add("product", typeof(string));
130 - oDtVer.Rows.Add("9.5.1.0");
131 - MockDbFunctions.Setup(x => x.FillDataTableBlocking(It.IsAny<string>(), out oDtVer, false, null)).
132 - Returns(new DbFetchResult(){Successful = true});
226 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
227 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = true });
228 +
229 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
230 + Assert.IsFalse(res.Successful, "Login should have failed:" + res);
231 + }
232 +
233 + [TestMethod]
234 + public void InitVersionTest_VersionInfoFetchShort()
235 + {
236 + SetupVersionAndServerInfo("10.0", false);
237 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
238 + Assert.IsFalse(res.Successful, "Login should have failed:" + res);
239 + }
240 +
241 + [TestMethod]
242 + public void InitVersionTest_VersionInfoFetchNoDecimals()
243 + {
244 + SetupVersionAndServerInfo("10000100", false);
245 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
246 + Assert.IsFalse(res.Successful, "Login should have failed:" + res);
247 + }
248 +
249 + [TestMethod]
250 + public void InitVersionTest_VersionInfoFetchNonNumericSections()
251 + {
252 + SetupVersionAndServerInfo("ab.cd.ef.gh", false);
253 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
254 + Assert.IsFalse(res.Successful, "Login should have failed:" + res);
255 + }
256 +
257 + [TestMethod]
258 + public void InitVersionTest_IntEs()
259 + {
260 + SetupVersionAndServerInfo("10.0.1.0ES99", false);
261 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
262 + Assert.IsTrue(res.Successful, "Login failed:" + res);
263 + Assert.IsTrue(MockServer.UnityVersionEs==99,"ES did not parse out to 99 properly:"+MockServer.UnityVersionString);
264 + }
265 +
266 + [TestMethod]
267 + public void InitVersionTest_StringEs()
268 + {
269 + SetupVersionAndServerInfo("10.0.1.0ESblah", false);
270 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
271 + Assert.IsTrue(res.Successful, "Login failed:" + res);
272 + Assert.IsTrue(MockServer.UnityVersionEs == 0, "ES should be 0 if passed as non numeric string:" + MockServer.UnityVersionString);
273 + }
274 +
275 + [TestMethod]
276 + public void FillLocationProperties_Failure()
277 + {
278 + Reset();
279 + MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).
280 + Returns(new DbFetchResult() { Successful = true });
281 +
282 + MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("");
283 +
284 + DataTable oDtVer = new DataTable();
285 + oDtVer.Columns.Add("product", typeof(string));
286 + oDtVer.Rows.Add("10.0.1.0");
287 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
288 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = true });
289 +
290 + DataTable oDtLocation = new DataTable();
291 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_LocalVMS", out oDtLocation, false, null)).
292 + Returns(new DbFetchResult() { Successful = false });
293 +
294 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
295 + Assert.IsFalse(res.Successful, "Login should fail:" + res);
296 + }
297 +
298 + [TestMethod]
299 + public void FillLocationProperties_NeighborFetchFailurePre10()
300 + {
301 + Reset();
302 + MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).
303 + Returns(new DbFetchResult() { Successful = true });
304 +
305 + MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("");
306 +
307 + DataTable oDtVer = new DataTable();
308 + oDtVer.Columns.Add("product", typeof(string));
309 + oDtVer.Rows.Add("10.0.1.0");
310 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
311 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = true });
133 312
134 313 DataTable oDtLocation = new DataTable();
135 314 oDtLocation.Columns.Add("DisplayName", typeof(string));
  @@ -137,18 +316,95 @@
137 316 oDtLocation.Columns.Add("SMTPDomain", typeof(string));
138 317 oDtLocation.Columns.Add("HostAddress", typeof(string));
139 318 oDtLocation.Rows.Add("name", "objectid", "smtpdomain", "hostaddress");
140 - MockDbFunctions.Setup(x => x.FillDataTableBlocking(It.IsAny<string>(), out oDtLocation, true, null)).
319 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_LocalVMS", out oDtLocation, false, null)).
141 320 Returns(new DbFetchResult() { Successful = true });
142 321
322 +
143 323 DataTable oDtNeighbor = new DataTable();
144 - MockDbFunctions.Setup(x => x.FillDataTableBlocking(It.IsAny<string>(), out oDtNeighbor, false, It.IsAny<string>())).
324 +
325 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("Select ObjectId FROM vw_NetworkTopology WHERE ObjectId <> NeighbourLocationObjectId " +
326 + "AND NeighbourLocationObjectId = ?", out oDtNeighbor, false, It.IsAny<string>())).
327 + Returns(new DbFetchResult() { Successful = false });
328 +
329 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
330 + Assert.IsTrue(res.Successful, "Login should not fail with neighbor fetch failure:" + res);
331 + Assert.IsTrue(MockServer.NeighborLocations.Count==0,"Neighbor count should be 0 for failed fetch");
332 + }
333 +
334 + [TestMethod]
335 + public void FillLocationProperties_NeighborFetchFailurePost10()
336 + {
337 + Reset();
338 + MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).
339 + Returns(new DbFetchResult() { Successful = true });
340 +
341 + MockDbFunctions.Setup(x => x.GetConfigurationString(It.IsAny<string>())).Returns("");
342 +
343 + DataTable oDtVer = new DataTable();
344 + oDtVer.Columns.Add("product", typeof(string));
345 + oDtVer.Rows.Add("9.0.1.0");
346 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_Schemainformation WHERE IsCurrent=1",
347 + out oDtVer, false, null)).Returns(new DbFetchResult() { Successful = true });
348 +
349 + DataTable oDtLocation = new DataTable();
350 + oDtLocation.Columns.Add("DisplayName", typeof(string));
351 + oDtLocation.Columns.Add("ObjectID", typeof(string));
352 + oDtLocation.Columns.Add("SMTPDomain", typeof(string));
353 + oDtLocation.Columns.Add("HostAddress", typeof(string));
354 + oDtLocation.Rows.Add("name", "objectid", "smtpdomain", "hostaddress");
355 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("SELECT * FROM vw_LocalVMS", out oDtLocation, false, null)).
145 356 Returns(new DbFetchResult() { Successful = true });
146 357
147 - var res= MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
148 - Assert.IsTrue(res.Successful,"Login failed:"+res);
149 - Assert.IsTrue(MockServer.UnityVersionIsCoRes,"CoRes flag should be set to true");
358 + DataTable oDtNeighbor = new DataTable();
359 +
360 + MockDbFunctions.Setup(x => x.FillDataTableBlocking("Select ObjectId FROM vw_Location WHERE ObjectId <> ? ",
361 + out oDtNeighbor, false, It.IsAny<string>())).Returns(new DbFetchResult() { Successful = false });
362 +
363 + var res = MockServer.LoginDatabaseBlocking("login", "password", "127.0.0.1");
364 + Assert.IsTrue(res.Successful, "Login should not fail with neighbor fetch failure:" + res);
365 + Assert.IsTrue(MockServer.NeighborLocations.Count == 0, "Neighbor count should be 0 for failed fetch");
150 366 }
151 367
368 + [TestMethod]
369 + public void ChangeActiveDatabase_FetchFailure()
370 + {
371 + Reset();
372 + MockDbFunctions.Setup(x => x.AttachToDatabase(It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>(), It.IsAny<string>())).
373 + Returns(new DbFetchResult() { Successful = false });
374 +
375 + var res = MockServer.ChangeActiveDatabase("UnityRptDb");
376 + Assert.IsFalse(res,"Changing database call should fail");
377 + }
378 +
379 + [TestMethod]
380 + public void LargeDbOperationPause_StartCommand_GrammarCompilePauseFailure()
381 + {
382 + SetupVersionAndServerInfo("10.0.0.1", false);
383 + MockDbFunctions.Setup(x => x.StartNewCommand("csp_grammarcompilepause",true)).Returns(false);
384 + bool res = MockServer.LargeDbOperationPause(false);
385 + Assert.IsFalse(res,"LargeDbOperationPause should return false on proc failure");
386 + }
387 +
388 + [TestMethod]
389 + public void LargeDbOperationPause_ExecuteProcGrammarCompilePauseFailure()
390 + {
391 + SetupVersionAndServerInfo("10.0.0.1", false);
392 + MockDbFunctions.Setup(x => x.StartNewCommand(It.IsAny<string>(), true)).Returns(true);
393 + MockDbFunctions.Setup(x => x.ExecuteProc()).Returns(new DbFetchResult(){Successful = false});
394 + bool res = MockServer.LargeDbOperationPause(false);
395 + Assert.IsFalse(res, "LargeDbOperationPause should return false on proc failure");
396 + }
397 +
398 + [TestMethod]
399 + public void LargeDbOperationPause_StartCommand_NetworkPauseFailure()
400 + {
401 + SetupVersionAndServerInfo("10.0.0.1",false);
402 + MockDbFunctions.Setup(x => x.StartNewCommand("csp_grammarcompilepause", true)).Returns(true);
403 + MockDbFunctions.Setup(x => x.ExecuteProc()).Returns(new DbFetchResult() { Successful = true });
404 + MockDbFunctions.Setup(x => x.StartNewCommand("csp_networkreplicationpause", true)).Returns(false);
405 + bool res = MockServer.LargeDbOperationPause(true);
406 + Assert.IsFalse(res, "LargeDbOperationPause should return false on proc failure");
407 + }
152 408
153 409 #endregion
154 410