///<summary> /// Update the Typed Products Entity with modified mock values. ///</summary> public static void UpdateMockInstance(TransactionManager tm, Products mock) { ProductsTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
///<summary> /// Returns a Typed Products Entity with mock values. ///</summary> public static Products CreateMockInstance_Generated(TransactionManager tm) { Products mock = new Products(); mock.ProductName = TestUtility.Instance.RandomString(19, false);; mock.QuantityPerUnit = TestUtility.Instance.RandomString(9, false);; mock.UnitPrice = TestUtility.Instance.RandomShort(); mock.UnitsInStock = TestUtility.Instance.RandomShort(); mock.UnitsOnOrder = TestUtility.Instance.RandomShort(); mock.ReorderLevel = TestUtility.Instance.RandomShort(); mock.Discontinued = TestUtility.Instance.RandomBoolean(); int count0 = 0; TList<Categories> _collection0 = DataRepository.CategoriesProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.CategoryId = _collection0[0].CategoryId; } int count1 = 0; TList<Suppliers> _collection1 = DataRepository.SuppliersProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.SupplierId = _collection1[0].SupplierId; } // create a temporary collection and add the item to it TList<Products> tempMockCollection = new TList<Products>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return (Products)mock; }
/// <summary> /// Make any alterations necessary (i.e. for DB check constraints, special test cases, etc.) /// </summary> /// <param name="mock">Object to be modified</param> private static void SetSpecialTestData(Products mock) { //Code your changes to the data object here. }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Products entity = mock.Copy() as Products; entity = (Products)mock.Clone(); Assert.IsTrue(Products.ValueEquals(entity, mock), "Clone is not working"); } }
/// <summary> /// Serialize a Products 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_ProductsCollection.xml"); mock = CreateMockInstance(tm); TList<Products> mockCollection = new TList<Products>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<Products> correctly serialized to a temporary file."); } }
/// <summary> /// Serialize the mock Products 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_Products.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 Products entity into the database. /// </summary> private void Step_05_Delete_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = (Products)CreateMockInstance(tm); DataRepository.ProductsProvider.Insert(tm, mock); Assert.IsTrue(DataRepository.ProductsProvider.Delete(tm, mock), "Delete failed."); System.Console.WriteLine("DataRepository.ProductsProvider.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 Products children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.ProductsProvider.GetPaged(tm, 0, 10, out count); DataRepository.ProductsProvider.DeepLoading += new EntityProviderBaseCore<Products, ProductsKey>.DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) e.Cancel = true; } ); if (mockCollection.Count > 0) { DataRepository.ProductsProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("Products instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.ProductsProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
///<summary> /// Update the Typed Products Entity with modified mock values. ///</summary> public static void UpdateMockInstance_Generated(TransactionManager tm, Products mock) { mock.ProductName = TestUtility.Instance.RandomString(19, false);; mock.QuantityPerUnit = TestUtility.Instance.RandomString(9, false);; mock.UnitPrice = TestUtility.Instance.RandomShort(); mock.UnitsInStock = TestUtility.Instance.RandomShort(); mock.UnitsOnOrder = TestUtility.Instance.RandomShort(); mock.ReorderLevel = TestUtility.Instance.RandomShort(); mock.Discontinued = TestUtility.Instance.RandomBoolean(); int count0 = 0; TList<Categories> _collection0 = DataRepository.CategoriesProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.CategoryId = _collection0[0].CategoryId; } int count1 = 0; TList<Suppliers> _collection1 = DataRepository.SuppliersProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.SupplierId = _collection1[0].SupplierId; } }