///<summary> /// Returns a Typed Orders Entity with mock values. ///</summary> public static Orders CreateMockInstance_Generated(TransactionManager tm) { Orders mock = new Orders(); mock.OrderDate = TestUtility.Instance.RandomDateTime(); mock.RequiredDate = TestUtility.Instance.RandomDateTime(); mock.ShippedDate = TestUtility.Instance.RandomDateTime(); mock.Freight = TestUtility.Instance.RandomShort(); mock.ShipName = TestUtility.Instance.RandomString(19, false);; mock.ShipAddress = TestUtility.Instance.RandomString(29, false);; mock.ShipCity = TestUtility.Instance.RandomString(6, false);; mock.ShipRegion = TestUtility.Instance.RandomString(6, false);; mock.ShipPostalCode = TestUtility.Instance.RandomString(10, false);; mock.ShipCountry = TestUtility.Instance.RandomString(6, false);; int count0 = 0; TList<Customers> _collection0 = DataRepository.CustomersProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.CustomerId = _collection0[0].CustomerId; } int count1 = 0; TList<Employees> _collection1 = DataRepository.EmployeesProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.EmployeeId = _collection1[0].EmployeeId; } int count2 = 0; TList<Shippers> _collection2 = DataRepository.ShippersProvider.GetPaged(tm, 0, 10, out count2); //_collection2.Shuffle(); if (_collection2.Count > 0) { mock.ShipVia = _collection2[0].ShipperId; } // create a temporary collection and add the item to it TList<Orders> tempMockCollection = new TList<Orders>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return (Orders)mock; }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Orders entity = mock.Copy() as Orders; entity = (Orders)mock.Clone(); Assert.IsTrue(Orders.ValueEquals(entity, mock), "Clone is not working"); } }
/// <summary> /// Serialize a Orders 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_OrdersCollection.xml"); mock = CreateMockInstance(tm); TList<Orders> mockCollection = new TList<Orders>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<Orders> correctly serialized to a temporary file."); } }
/// <summary> /// Serialize the mock Orders 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_Orders.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> /// Delete the mock Orders entity into the database. /// </summary> private void Step_05_Delete_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = (Orders)CreateMockInstance(tm); DataRepository.OrdersProvider.Insert(tm, mock); Assert.IsTrue(DataRepository.OrdersProvider.Delete(tm, mock), "Delete failed."); System.Console.WriteLine("DataRepository.OrdersProvider.Delete(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Deep load all Orders children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.OrdersProvider.GetPaged(tm, 0, 10, out count); DataRepository.OrdersProvider.DeepLoading += new EntityProviderBaseCore<Orders, OrdersKey>.DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) e.Cancel = true; } ); if (mockCollection.Count > 0) { DataRepository.OrdersProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("Orders instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.OrdersProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
///<summary> /// Update the Typed Orders Entity with modified mock values. ///</summary> public static void UpdateMockInstance_Generated(TransactionManager tm, Orders mock) { mock.OrderDate = TestUtility.Instance.RandomDateTime(); mock.RequiredDate = TestUtility.Instance.RandomDateTime(); mock.ShippedDate = TestUtility.Instance.RandomDateTime(); mock.Freight = TestUtility.Instance.RandomShort(); mock.ShipName = TestUtility.Instance.RandomString(19, false);; mock.ShipAddress = TestUtility.Instance.RandomString(29, false);; mock.ShipCity = TestUtility.Instance.RandomString(6, false);; mock.ShipRegion = TestUtility.Instance.RandomString(6, false);; mock.ShipPostalCode = TestUtility.Instance.RandomString(10, false);; mock.ShipCountry = TestUtility.Instance.RandomString(6, false);; int count0 = 0; TList<Customers> _collection0 = DataRepository.CustomersProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.CustomerId = _collection0[0].CustomerId; } int count1 = 0; TList<Employees> _collection1 = DataRepository.EmployeesProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.EmployeeId = _collection1[0].EmployeeId; } int count2 = 0; TList<Shippers> _collection2 = DataRepository.ShippersProvider.GetPaged(tm, 0, 10, out count2); //_collection2.Shuffle(); if (_collection2.Count > 0) { mock.ShipVia = _collection2[0].ShipperId; } }