source: BMXNET_RPMS_dotNET_UTILITIES-BMX/branch/BMX41000/IHS BMX Framework/IndianHealthService.BMXNet.Test/CreateUpdateDeleteChildRows.cs@ 1685

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

Initial Import of BMX4

File size: 7.5 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Text;
4using NUnit.Framework;
5using System.Data;
6
7namespace IndianHealthService.BMXNet.Tests
8{
9
10 /// <summary>
11 /// BMX ADO SS^BMX TEST FILE^^~~~~~
12 ///
13 /// </summary>
14 ///
15 [TestFixture]
16 public class CreateUpdateDeleteChildRows:BmxValidUserTestSuite
17 {
18
19
20 [SetUp]
21 public override void Setup()
22 {
23 base.Setup();
24 this.SetupTable();
25 }
26
27
28 private String _parentIen = null;
29
30 public String ParentIen
31 {
32 get { return _parentIen; }
33 set { _parentIen = value; }
34 }
35
36
37 public override void SetupTable()
38 {
39 base.SetupTable();
40
41 this.ClearTable();
42 this.AddParent(); //necessary so that the next one won't fail
43 this.ClearChildTable();
44 }
45
46 [Test]
47 public void AddParent() {
48 DataTable table = this.RemoteSession.TableFromCommand(this.FetchTableString);
49 int rowCount = table.Rows.Count;
50 DataRow row = table.NewRow();
51 row["NAME"] = "Parent";
52 row["DATE"] = new DateTime(1970, 10, 10);
53 row["NUMBER"] = 8;
54 row["NUMBER R/O"] = 9;
55 table.Rows.Add(row);
56 Assert.AreEqual(rowCount + 1, table.Rows.Count);
57
58 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
59
60 table = this.RemoteSession.TableFromCommand(this.FetchTableString);
61 Assert.AreEqual(rowCount + 1, table.Rows.Count);
62 row = table.Rows[0];
63 Assert.AreEqual(row["NAME"], "Parent");
64
65 this.ParentIen = row["BMXIEN"].ToString();
66
67 Assert.Greater(int.Parse(this.ParentIen), 0);
68 }
69
70
71 public virtual void ClearChildTable()
72 {
73
74 DataTable table = this.RemoteSession.TableFromCommand(this.FetchString());
75
76 //TODO: is this supposed to work???? table.Rows.Clear();
77
78 foreach (DataRow each in table.Rows)
79 {
80 each.Delete();
81 }
82 this.RemoteSession.SaveChanges(table);
83
84 table = this.RemoteSession.TableFromCommand(this.FetchString());
85 Assert.AreEqual(0, table.Rows.Count);
86 }
87
88
89 public String FetchString() {
90
91 return "BMX ADO SS^BMX TEST FILE2^"+this.ParentIen+",^~~~~~";
92 }
93
94
95 [Test]
96 public void TestCarrotLimiter() {
97 String result=this.RemoteSession.TransmitRPC("BMX DEMO", "B^10", "OR CPRS GUI CHART");
98 }
99
100 [Test]
101 public void AddRow()
102 {
103
104
105 DataTable table = this.RemoteSession.TableFromCommand(this.FetchString());
106 DataRow row = table.NewRow();
107 row["BMXIEN1"] = this.ParentIen;
108
109 row["NAME2"] = "John";
110 row["DATE2"] = new DateTime(1970, 10, 10);
111 row["NUMBER2"] = 8;
112 row["NUMBER2 R/O"] = 9;
113 table.Rows.Add(row);
114 Assert.AreEqual(1, table.Rows.Count);
115
116 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
117
118 table = this.RemoteSession.TableFromCommand(this.FetchString());
119 Assert.AreEqual(1, table.Rows.Count);
120 row = table.Rows[0];
121 Assert.AreEqual(row["NAME2"], "John");
122 Assert.AreEqual(row["DATE2"], new DateTime(1970, 10, 10));
123 }
124
125
126
127 [Test]
128 public void UpdateRow()
129 {
130 DataTable table = this.RemoteSession.TableFromCommand(this.FetchString());
131 DataRow row = table.NewRow();
132 row["BMXIEN1"] = this.ParentIen;
133 row["NAME2"] = "John";
134 row["DATE2"] = new DateTime(1970, 10, 10);
135 row["NUMBER2"] = 8;
136 row["NUMBER2 R/O"] = 9;
137 table.Rows.Add(row);
138 Assert.AreEqual(1, table.Rows.Count);
139
140 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
141
142 table = this.RemoteSession.TableFromCommand(this.FetchString());
143 row = table.Rows[0];
144 row["NAME2"]="Fred";
145 row["DATE2"]= new DateTime(1970, 11, 11);
146
147 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
148
149 table = this.RemoteSession.TableFromCommand(this.FetchString());
150 Assert.AreEqual(1, table.Rows.Count);
151 row = table.Rows[0];
152 Assert.AreEqual(row["NAME2"], "Fred");
153 Assert.AreEqual(row["DATE2"], new DateTime(1970, 11, 11));
154 }
155
156
157 [Test]
158 public void DeleteRow()
159 {
160 DataTable table = this.RemoteSession.TableFromCommand(this.FetchString());
161 DataRow row = table.NewRow();
162 row["BMXIEN1"] = this.ParentIen;
163 row["NAME2"] = "John";
164 row["DATE2"] = new DateTime(1970, 10, 10);
165 row["NUMBER2"] = 8;
166 row["NUMBER2 R/O"] = 9;
167 table.Rows.Add(row);
168 Assert.AreEqual(1, table.Rows.Count);
169
170 row = table.NewRow();
171 row["BMXIEN1"] = this.ParentIen;
172 row["NAME2"] = "Jane";
173 row["DATE2"] = new DateTime(1972, 10, 10);
174 row["NUMBER2"] = 8;
175 row["NUMBER2 R/O"] = 9;
176 table.Rows.Add(row);
177 Assert.AreEqual(2, table.Rows.Count);
178
179 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
180
181 table = this.RemoteSession.TableFromCommand(this.FetchString());
182 Assert.AreEqual(2, table.Rows.Count);
183 row = table.Rows[1];
184 Assert.AreEqual(row["NAME2"], "Jane");
185 row.Delete();
186
187 //TODO: Deleting a row does not remove it ... it still counts. Assert below fails
188 //if 1
189 Assert.AreEqual(2, table.Rows.Count);
190
191 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
192
193 table = this.RemoteSession.TableFromCommand(this.FetchString());
194 Assert.AreEqual(1, table.Rows.Count);
195 row = table.Rows[0];
196 Assert.AreEqual(row["NAME2"],"John");
197
198 }
199
200
201
202
203 [Test]
204 public void CascadedDeleteRow()
205 {
206
207 DataTable table = this.RemoteSession.TableFromCommand(this.FetchString());
208 DataRow row = table.NewRow();
209 row["BMXIEN1"] = this.ParentIen;
210 row["NAME2"] = "John";
211 row["DATE2"] = new DateTime(1970, 10, 10);
212 row["NUMBER2"] = 8;
213 row["NUMBER2 R/O"] = 9;
214 table.Rows.Add(row);
215 Assert.AreEqual(1, table.Rows.Count);
216
217 Assert.IsTrue(this.RemoteSession.SaveChanges(table));
218
219 table = this.RemoteSession.TableFromCommand(this.FetchString());
220 Assert.AreEqual(1, table.Rows.Count);
221 row = table.Rows[0];
222 Assert.AreEqual(row["NAME2"], "John");
223 Assert.AreEqual(row["DATE2"], new DateTime(1970, 10, 10));
224
225 DataTable parentTable = this.RemoteSession.TableFromCommand(this.FetchTableString);
226 Assert.AreEqual(1, table.Rows.Count);
227 parentTable.Rows[0].Delete();
228 Assert.IsTrue(this.RemoteSession.SaveChanges(parentTable));
229
230 this.AddParent();
231 table = this.RemoteSession.TableFromCommand(this.FetchString());
232 Assert.AreEqual(0, table.Rows.Count);
233
234 }
235
236
237
238
239 }
240}
Note: See TracBrowser for help on using the repository browser.