-
Notifications
You must be signed in to change notification settings - Fork 1
/
CauHinhGiangVienPhanHoiTest.generated.cs
385 lines (308 loc) · 13.1 KB
/
CauHinhGiangVienPhanHoiTest.generated.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/*
File Generated by NetTiers templates [www.nettiers.net]
Important: Do not modify this file. Edit the file CauHinhGiangVienPhanHoiTest.cs instead.
*/
#region Using directives
using System;
using System.Xml;
using System.Xml.Serialization;
using NUnit.Framework;
using PMS.Entities;
using PMS.Data;
using PMS.Data.Bases;
#endregion
namespace PMS.UnitTests
{
/// <summary>
/// Provides tests for the and <see cref="CauHinhGiangVienPhanHoi"/> objects (entity, collection and repository).
/// </summary>
public partial class CauHinhGiangVienPhanHoiTest
{
// the CauHinhGiangVienPhanHoi instance used to test the repository.
protected CauHinhGiangVienPhanHoi mock;
// the TList<CauHinhGiangVienPhanHoi> instance used to test the repository.
protected TList<CauHinhGiangVienPhanHoi> mockCollection;
protected static TransactionManager CreateTransaction()
{
TransactionManager transactionManager = null;
if (DataRepository.Provider.IsTransactionSupported)
{
transactionManager = DataRepository.Provider.CreateTransaction();
transactionManager.BeginTransaction(System.Data.IsolationLevel.ReadCommitted);
}
return transactionManager;
}
/// <summary>
/// This method is used to construct the test environment prior to running the tests.
/// </summary>
static public void Init_Generated()
{
System.Console.WriteLine(new String('-', 75));
System.Console.WriteLine("-- Testing the CauHinhGiangVienPhanHoi Entity with the {0} --", PMS.Data.DataRepository.Provider.Name);
System.Console.WriteLine(new String('-', 75));
}
/// <summary>
/// This method is used to restore the environment after the tests are completed.
/// </summary>
static public void CleanUp_Generated()
{
System.Console.WriteLine("All Tests Completed");
System.Console.WriteLine();
}
/// <summary>
/// Inserts a mock CauHinhGiangVienPhanHoi entity into the database.
/// </summary>
private void Step_01_Insert_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
mock = CreateMockInstance(tm);
Assert.IsTrue(DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, mock), "Insert failed");
System.Console.WriteLine("DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(mock):");
System.Console.WriteLine(mock);
//normally one would commit here
//tm.Commit();
//IDisposable will Rollback Transaction since it's left uncommitted
}
}
/// <summary>
/// Selects all CauHinhGiangVienPhanHoi objects of the database.
/// </summary>
private void Step_02_SelectAll_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
//Find
int count = -1;
mockCollection = DataRepository.CauHinhGiangVienPhanHoiProvider.Find(tm, null, "", 0, 10, out count );
Assert.IsTrue(count >= 0 && mockCollection != null, "Query Failed to issue Find Command.");
System.Console.WriteLine("DataRepository.CauHinhGiangVienPhanHoiProvider.Find():");
System.Console.WriteLine(mockCollection);
// GetPaged
count = -1;
mockCollection = DataRepository.CauHinhGiangVienPhanHoiProvider.GetPaged(tm, 0, 10, out count);
Assert.IsTrue(count >= 0 && mockCollection != null, "Query Failed to issue GetPaged Command.");
System.Console.WriteLine("#get paged count: " + count.ToString());
}
}
/// <summary>
/// Deep load all CauHinhGiangVienPhanHoi children.
/// </summary>
private void Step_03_DeepLoad_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
int count = -1;
mock = CreateMockInstance(tm);
mockCollection = DataRepository.CauHinhGiangVienPhanHoiProvider.GetPaged(tm, 0, 10, out count);
DataRepository.CauHinhGiangVienPhanHoiProvider.DeepLoading += new EntityProviderBaseCore<CauHinhGiangVienPhanHoi, CauHinhGiangVienPhanHoiKey>.DeepLoadingEventHandler(
delegate(object sender, DeepSessionEventArgs e)
{
if (e.DeepSession.Count > 3)
e.Cancel = true;
}
);
if (mockCollection.Count > 0)
{
DataRepository.CauHinhGiangVienPhanHoiProvider.DeepLoad(tm, mockCollection[0]);
System.Console.WriteLine("CauHinhGiangVienPhanHoi instance correctly deep loaded at 1 level.");
mockCollection.Add(mock);
// DataRepository.CauHinhGiangVienPhanHoiProvider.DeepSave(tm, mockCollection);
}
//normally one would commit here
//tm.Commit();
//IDisposable will Rollback Transaction since it's left uncommitted
}
}
/// <summary>
/// Updates a mock CauHinhGiangVienPhanHoi entity into the database.
/// </summary>
private void Step_04_Update_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
CauHinhGiangVienPhanHoi mock = CreateMockInstance(tm);
Assert.IsTrue(DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, mock), "Insert failed");
UpdateMockInstance(tm, mock);
Assert.IsTrue(DataRepository.CauHinhGiangVienPhanHoiProvider.Update(tm, mock), "Update failed.");
System.Console.WriteLine("DataRepository.CauHinhGiangVienPhanHoiProvider.Update(mock):");
System.Console.WriteLine(mock);
//normally one would commit here
//tm.Commit();
//IDisposable will Rollback Transaction since it's left uncommitted
}
}
/// <summary>
/// Delete the mock CauHinhGiangVienPhanHoi entity into the database.
/// </summary>
private void Step_05_Delete_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
mock = (CauHinhGiangVienPhanHoi)CreateMockInstance(tm);
DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, mock);
Assert.IsTrue(DataRepository.CauHinhGiangVienPhanHoiProvider.Delete(tm, mock), "Delete failed.");
System.Console.WriteLine("DataRepository.CauHinhGiangVienPhanHoiProvider.Delete(mock):");
System.Console.WriteLine(mock);
//normally one would commit here
//tm.Commit();
//IDisposable will Rollback Transaction since it's left uncommitted
}
}
#region Serialization tests
/// <summary>
/// Serialize the mock CauHinhGiangVienPhanHoi entity into a temporary file.
/// </summary>
private void Step_06_SerializeEntity_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
mock = CreateMockInstance(tm);
string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_CauHinhGiangVienPhanHoi.xml");
EntityHelper.SerializeXml(mock, fileName);
Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock not found");
System.Console.WriteLine("mock correctly serialized to a temporary file.");
}
}
/// <summary>
/// Deserialize the mock CauHinhGiangVienPhanHoi entity from a temporary file.
/// </summary>
private void Step_07_DeserializeEntity_Generated()
{
string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_CauHinhGiangVienPhanHoi.xml");
Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock file not found to deserialize");
using (System.IO.StreamReader sr = System.IO.File.OpenText(fileName))
{
object item = EntityHelper.DeserializeEntityXml<CauHinhGiangVienPhanHoi>(sr.ReadToEnd());
sr.Close();
}
System.IO.File.Delete(fileName);
System.Console.WriteLine("mock correctly deserialized from a temporary file.");
}
/// <summary>
/// Serialize a CauHinhGiangVienPhanHoi collection into a temporary file.
/// </summary>
private void Step_08_SerializeCollection_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_CauHinhGiangVienPhanHoiCollection.xml");
mock = CreateMockInstance(tm);
TList<CauHinhGiangVienPhanHoi> mockCollection = new TList<CauHinhGiangVienPhanHoi>();
mockCollection.Add(mock);
EntityHelper.SerializeXml(mockCollection, fileName);
Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found");
System.Console.WriteLine("TList<CauHinhGiangVienPhanHoi> correctly serialized to a temporary file.");
}
}
/// <summary>
/// Deserialize a CauHinhGiangVienPhanHoi collection from a temporary file.
/// </summary>
private void Step_09_DeserializeCollection_Generated()
{
string fileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "temp_CauHinhGiangVienPhanHoiCollection.xml");
Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock file not found to deserialize");
XmlSerializer mySerializer = new XmlSerializer(typeof(TList<CauHinhGiangVienPhanHoi>));
using (System.IO.FileStream myFileStream = new System.IO.FileStream(fileName, System.IO.FileMode.Open))
{
TList<CauHinhGiangVienPhanHoi> mockCollection = (TList<CauHinhGiangVienPhanHoi>) mySerializer.Deserialize(myFileStream);
myFileStream.Close();
}
System.IO.File.Delete(fileName);
System.Console.WriteLine("TList<CauHinhGiangVienPhanHoi> correctly deserialized from a temporary file.");
}
#endregion
/// <summary>
/// Check the foreign key dal methods.
/// </summary>
private void Step_10_FK_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
CauHinhGiangVienPhanHoi entity = CreateMockInstance(tm);
bool result = DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, entity);
Assert.IsTrue(result, "Could Not Test FK, Insert Failed");
}
}
/// <summary>
/// Check the indexes dal methods.
/// </summary>
private void Step_11_IX_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
CauHinhGiangVienPhanHoi entity = CreateMockInstance(tm);
bool result = DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, entity);
Assert.IsTrue(result, "Could Not Test IX, Insert Failed");
CauHinhGiangVienPhanHoi t0 = DataRepository.CauHinhGiangVienPhanHoiProvider.GetById(tm, entity.Id);
}
}
/// <summary>
/// Test methods exposed by the EntityHelper class.
/// </summary>
private void Step_20_TestEntityHelper_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
mock = CreateMockInstance(tm);
CauHinhGiangVienPhanHoi entity = mock.Copy() as CauHinhGiangVienPhanHoi;
entity = (CauHinhGiangVienPhanHoi)mock.Clone();
Assert.IsTrue(CauHinhGiangVienPhanHoi.ValueEquals(entity, mock), "Clone is not working");
}
}
/// <summary>
/// Test Find using the Query class
/// </summary>
private void Step_30_TestFindByQuery_Generated()
{
using (TransactionManager tm = CreateTransaction())
{
//Insert Mock Instance
CauHinhGiangVienPhanHoi mock = CreateMockInstance(tm);
bool result = DataRepository.CauHinhGiangVienPhanHoiProvider.Insert(tm, mock);
Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed");
CauHinhGiangVienPhanHoiQuery query = new CauHinhGiangVienPhanHoiQuery();
query.AppendEquals(CauHinhGiangVienPhanHoiColumn.Id, mock.Id.ToString());
if(mock.MaCauHinh != null)
query.AppendEquals(CauHinhGiangVienPhanHoiColumn.MaCauHinh, mock.MaCauHinh.ToString());
if(mock.TenCauHinh != null)
query.AppendEquals(CauHinhGiangVienPhanHoiColumn.TenCauHinh, mock.TenCauHinh.ToString());
if(mock.NoiDung != null)
query.AppendEquals(CauHinhGiangVienPhanHoiColumn.NoiDung, mock.NoiDung.ToString());
if(mock.NgayCapNhat != null)
query.AppendEquals(CauHinhGiangVienPhanHoiColumn.NgayCapNhat, mock.NgayCapNhat.ToString());
TList<CauHinhGiangVienPhanHoi> results = DataRepository.CauHinhGiangVienPhanHoiProvider.Find(tm, query);
Assert.IsTrue(results.Count == 1, "Find is not working correctly. Failed to find the mock instance");
}
}
#region Mock Instance
///<summary>
/// Returns a Typed CauHinhGiangVienPhanHoi Entity with mock values.
///</summary>
static public CauHinhGiangVienPhanHoi CreateMockInstance_Generated(TransactionManager tm)
{
CauHinhGiangVienPhanHoi mock = new CauHinhGiangVienPhanHoi();
mock.MaCauHinh = TestUtility.Instance.RandomString(24, false);;
mock.TenCauHinh = TestUtility.Instance.RandomString(249, false);;
mock.NoiDung = TestUtility.Instance.RandomString(499, false);;
mock.NgayCapNhat = TestUtility.Instance.RandomDateTime();
// create a temporary collection and add the item to it
TList<CauHinhGiangVienPhanHoi> tempMockCollection = new TList<CauHinhGiangVienPhanHoi>();
tempMockCollection.Add(mock);
tempMockCollection.Remove(mock);
return (CauHinhGiangVienPhanHoi)mock;
}
///<summary>
/// Update the Typed CauHinhGiangVienPhanHoi Entity with modified mock values.
///</summary>
static public void UpdateMockInstance_Generated(TransactionManager tm, CauHinhGiangVienPhanHoi mock)
{
mock.MaCauHinh = TestUtility.Instance.RandomString(24, false);;
mock.TenCauHinh = TestUtility.Instance.RandomString(249, false);;
mock.NoiDung = TestUtility.Instance.RandomString(499, false);;
mock.NgayCapNhat = TestUtility.Instance.RandomDateTime();
}
#endregion
}
}