source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.Test/AdoTests/AsyncAdoTests.cs@ 1742

Last change on this file since 1742 was 1146, checked in by Sam Habiel, 14 years ago

Initial Import of BMX4

File size: 5.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using NUnit.Framework;
5using IndianHealthService.BMXNet.Ado;
6using System.Threading;
7
8namespace IndianHealthService.BMXNet.Tests.AdoTests
9{
10 [TestFixture]
11 public class AsyncAdoTests : BmxValidUserTestSuite
12 {
13
14 public override void SetupTestUser()
15 {
16 this.User = TestUser.ReadFromAppConfig("BmxTestUser");
17 }
18
19 public override void Setup()
20 {
21 this.TheFuture = null;
22 base.Setup();
23 }
24
25 private DataTableFuture _theFuture = null;
26
27 public DataTableFuture TheFuture
28 {
29 get { return _theFuture; }
30 set { _theFuture = value; }
31 }
32
33
34
35 [Test]
36 public void BadStandardAsyncFetch()
37 {
38 int timeToWait = 3;
39 this.RemoteSession.EventServices.EventPollingInterval = 2000;
40 this.RemoteSession.EventServices.IsEventPollingEnabled = true;
41 Thread.Sleep(timeToWait * 1000);
42 TestTable testTable = TestTable.TypicalTableFetch();
43 try
44 {
45 DataTableFuture futureTestStandardAsyncFetch = this.RemoteSession.AsyncTableFromCommand("DOES NOT EXIST");
46 } catch {
47
48 }
49 }
50
51 [Test]
52 public void StandardAsyncFetch()
53 {
54 int timeToWait = 3;
55 this.RemoteSession.EventServices.EventPollingInterval = 2000;
56 this.RemoteSession.EventServices.IsEventPollingEnabled = true;
57
58 TestTable testTable = TestTable.TypicalTableFetch();
59 this.RemoteSession.AppContext = "BMXRPC";
60 DataTableFuture futureTestStandardAsyncFetch = this.RemoteSession.AsyncTableFromCommand(testTable.AsyncCommand("Test1", timeToWait));
61 futureTestStandardAsyncFetch.Returned += new EventHandler<DataTableFutureEventArgs>(futureTestStandardAsyncFetch_Returned);
62
63 Assert.IsNull(this.TheFuture);
64 Assert.IsFalse(futureTestStandardAsyncFetch.HasReturned);
65 Assert.IsFalse(futureTestStandardAsyncFetch.WasCancelled);
66 this.Hang(5);
67 Assert.IsNull(this.TheFuture);
68 Assert.IsFalse(futureTestStandardAsyncFetch.HasReturned);
69 Assert.IsFalse(futureTestStandardAsyncFetch.WasCancelled);
70 this.Hang((int)((timeToWait + 1) * 2));
71 Assert.IsNotNull(this.TheFuture);
72 Assert.IsTrue(futureTestStandardAsyncFetch.HasReturned);
73 Assert.IsTrue(futureTestStandardAsyncFetch.HasData);
74 Assert.IsFalse(futureTestStandardAsyncFetch.WasCancelled);
75 Assert.AreEqual(testTable.Repeat, futureTestStandardAsyncFetch.Result.Rows.Count);
76 }
77
78 void futureTestStandardAsyncFetch_Returned(object sender, DataTableFutureEventArgs e)
79 {
80 this.TheFuture = e.Future;
81 }
82
83 public void NonExistantRpcAsyncFetch()
84 {
85 int timeToWait = 3;
86 this.RemoteSession.EventServices.EventPollingInterval = 1000;
87 this.RemoteSession.EventServices.IsEventPollingEnabled = true;
88
89 DataTableFuture futureTestStandardAsyncFetch = this.RemoteSession.AsyncTableFromCommand("NON EXISTANT RPC");
90 futureTestStandardAsyncFetch.Returned += new EventHandler<DataTableFutureEventArgs>(futureTestStandardAsyncFetch_Returned);
91 this.Hang(5 + timeToWait);
92 //We should get a fast response
93 Assert.IsNotNull(this.TheFuture);
94 Assert.IsTrue(futureTestStandardAsyncFetch.HasReturned);
95 Assert.IsFalse(futureTestStandardAsyncFetch.HasData);
96 }
97
98
99 public void CancelAsyncFetch()
100 {
101 int timeToWait = 10;
102 this.RemoteSession.EventServices.EventPollingInterval = 2000;
103 this.RemoteSession.EventServices.IsEventPollingEnabled = true;
104
105 TestTable testTable = TestTable.TypicalTableFetch();
106 DataTableFuture futureTestStandardAsyncFetch = this.RemoteSession.AsyncTableFromCommand(testTable.AsyncCommand("Test1", timeToWait));
107 futureTestStandardAsyncFetch.Returned += new EventHandler<DataTableFutureEventArgs>(futureTestStandardAsyncFetch_Returned);
108
109 Assert.IsNull(this.TheFuture);
110 Assert.IsFalse(futureTestStandardAsyncFetch.HasReturned);
111 Assert.IsFalse(futureTestStandardAsyncFetch.WasCancelled);
112 this.Hang(5);
113 futureTestStandardAsyncFetch.Cancel();
114 Assert.IsNull(this.TheFuture);
115 Assert.IsFalse(futureTestStandardAsyncFetch.HasReturned);
116 Assert.IsTrue(futureTestStandardAsyncFetch.WasCancelled);
117 this.Hang(20);
118 Assert.IsNotNull(this.TheFuture);
119 Assert.IsTrue(futureTestStandardAsyncFetch.HasReturned);
120 Assert.IsFalse(futureTestStandardAsyncFetch.HasData);
121 Assert.IsTrue(futureTestStandardAsyncFetch.WasCancelled);
122 }
123
124 }
125}
Note: See TracBrowser for help on using the repository browser.