///<summary> /// Returns a Typed AccTrans Entity with mock values. ///</summary> static public AccTrans CreateMockInstance_Generated(TransactionManager tm) { AccTrans mock = new AccTrans(); mock.TranDate = TestUtility.Instance.RandomDateTime(); mock.TranTime = TestUtility.Instance.RandomString(5, false);; mock.EfDate = TestUtility.Instance.RandomDateTime(); mock.TransNum = TestUtility.Instance.RandomString(5, false);; mock.Voucher = TestUtility.Instance.RandomString(9, false);; mock.TransCode = TestUtility.Instance.RandomString(2, false);; mock.AccountId = TestUtility.Instance.RandomString(9, false);; mock.DbAmount = (decimal)TestUtility.Instance.RandomShort(); mock.CrAmount = (decimal)TestUtility.Instance.RandomShort(); mock.UserId = (decimal)TestUtility.Instance.RandomShort(); mock.CorrAcc = TestUtility.Instance.RandomString(9, false);; mock.Remark = TestUtility.Instance.RandomString(99, false);; mock.Name = TestUtility.Instance.RandomString(99, false);; mock.Address = TestUtility.Instance.RandomString(126, false);; mock.PersonId = TestUtility.Instance.RandomString(9, false);; mock.Updated = TestUtility.Instance.RandomBoolean(); mock.Recnum = (decimal)TestUtility.Instance.RandomShort(); mock.Status = TestUtility.Instance.RandomBoolean(); // create a temporary collection and add the item to it TList <AccTrans> tempMockCollection = new TList <AccTrans>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return((AccTrans)mock); }
/// <summary> /// Deep load all AccTrans children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.AccTransProvider.GetPaged(tm, 0, 10, out count); DataRepository.AccTransProvider.DeepLoading += new EntityProviderBaseCore <AccTrans, AccTransKey> .DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) { e.Cancel = true; } } ); if (mockCollection.Count > 0) { DataRepository.AccTransProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("AccTrans instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.AccTransProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
///<summary> /// Update the Typed AccTrans Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, AccTrans mock) { AccTransTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
/// <summary> /// Check the foreign key dal methods. /// </summary> private void Step_10_FK_Generated() { using (TransactionManager tm = CreateTransaction()) { AccTrans entity = CreateMockInstance(tm); bool result = DataRepository.AccTransProvider.Insert(tm, entity); Assert.IsTrue(result, "Could Not Test FK, Insert Failed"); } }
/// <summary> /// Test Find using the Query class /// </summary> private void Step_30_TestFindByQuery_Generated() { using (TransactionManager tm = CreateTransaction()) { //Insert Mock Instance AccTrans mock = CreateMockInstance(tm); bool result = DataRepository.AccTransProvider.Insert(tm, mock); Assert.IsTrue(result, "Could Not Test FindByQuery, Insert Failed"); AccTransQuery query = new AccTransQuery(); query.AppendEquals(AccTransColumn.Id, mock.Id.ToString()); query.AppendEquals(AccTransColumn.TranDate, mock.TranDate.ToString()); if (mock.TranTime != null) { query.AppendEquals(AccTransColumn.TranTime, mock.TranTime.ToString()); } if (mock.EfDate != null) { query.AppendEquals(AccTransColumn.EfDate, mock.EfDate.ToString()); } query.AppendEquals(AccTransColumn.TransNum, mock.TransNum.ToString()); query.AppendEquals(AccTransColumn.Voucher, mock.Voucher.ToString()); query.AppendEquals(AccTransColumn.TransCode, mock.TransCode.ToString()); query.AppendEquals(AccTransColumn.AccountId, mock.AccountId.ToString()); query.AppendEquals(AccTransColumn.DbAmount, mock.DbAmount.ToString()); query.AppendEquals(AccTransColumn.CrAmount, mock.CrAmount.ToString()); query.AppendEquals(AccTransColumn.UserId, mock.UserId.ToString()); query.AppendEquals(AccTransColumn.CorrAcc, mock.CorrAcc.ToString()); query.AppendEquals(AccTransColumn.Remark, mock.Remark.ToString()); if (mock.Name != null) { query.AppendEquals(AccTransColumn.Name, mock.Name.ToString()); } if (mock.Address != null) { query.AppendEquals(AccTransColumn.Address, mock.Address.ToString()); } if (mock.PersonId != null) { query.AppendEquals(AccTransColumn.PersonId, mock.PersonId.ToString()); } query.AppendEquals(AccTransColumn.Updated, mock.Updated.ToString()); if (mock.Recnum != null) { query.AppendEquals(AccTransColumn.Recnum, mock.Recnum.ToString()); } query.AppendEquals(AccTransColumn.Status, mock.Status.ToString()); TList <AccTrans> results = DataRepository.AccTransProvider.Find(tm, query); Assert.IsTrue(results.Count == 1, "Find is not working correctly. Failed to find the mock instance"); } }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); AccTrans entity = mock.Copy() as AccTrans; entity = (AccTrans)mock.Clone(); Assert.IsTrue(AccTrans.ValueEquals(entity, mock), "Clone is not working"); } }
///<summary> /// Returns a Typed AccTrans Entity with mock values. ///</summary> static public AccTrans CreateMockInstance(TransactionManager tm) { // get the default mock instance AccTrans mock = AccTransTest.CreateMockInstance_Generated(tm); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); // return the modified object return(mock); }
/// <summary> /// Serialize the mock AccTrans 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_AccTrans.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> /// Inserts a mock AccTrans entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.AccTransProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.AccTransProvider.Insert(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Serialize a AccTrans 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_AccTransCollection.xml"); mock = CreateMockInstance(tm); TList <AccTrans> mockCollection = new TList <AccTrans>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<AccTrans> correctly serialized to a temporary file."); } }
///<summary> /// Update the Typed AccTrans Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, AccTrans mock) { mock.TranDate = TestUtility.Instance.RandomDateTime(); mock.TranTime = TestUtility.Instance.RandomString(5, false);; mock.EfDate = TestUtility.Instance.RandomDateTime(); mock.TransNum = TestUtility.Instance.RandomString(5, false);; mock.Voucher = TestUtility.Instance.RandomString(9, false);; mock.TransCode = TestUtility.Instance.RandomString(2, false);; mock.AccountId = TestUtility.Instance.RandomString(9, false);; mock.DbAmount = (decimal)TestUtility.Instance.RandomShort(); mock.CrAmount = (decimal)TestUtility.Instance.RandomShort(); mock.UserId = (decimal)TestUtility.Instance.RandomShort(); mock.CorrAcc = TestUtility.Instance.RandomString(9, false);; mock.Remark = TestUtility.Instance.RandomString(99, false);; mock.Name = TestUtility.Instance.RandomString(99, false);; mock.Address = TestUtility.Instance.RandomString(126, false);; mock.PersonId = TestUtility.Instance.RandomString(9, false);; mock.Updated = TestUtility.Instance.RandomBoolean(); mock.Recnum = (decimal)TestUtility.Instance.RandomShort(); mock.Status = TestUtility.Instance.RandomBoolean(); }
/// <summary> /// Make any alterations necessary (i.e. for DB check constraints, special test cases, etc.) /// </summary> /// <param name="mock">Object to be modified</param> static private void SetSpecialTestData(AccTrans mock) { //Code your changes to the data object here. }