/// <summary> /// Inserts a mock BillOfMaterials entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.BillOfMaterialsProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.BillOfMaterialsProvider.Insert(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Convert a nettiers entity to the ws proxy entity. /// </summary> public static WsProxy.BillOfMaterials Convert(Nettiers.AdventureWorks.Entities.BillOfMaterials item) { WsProxy.BillOfMaterials outItem = new WsProxy.BillOfMaterials(); outItem.BillOfMaterialsId = item.BillOfMaterialsId; outItem.ProductAssemblyId = item.ProductAssemblyId; outItem.ComponentId = item.ComponentId; outItem.StartDate = item.StartDate; outItem.EndDate = item.EndDate; outItem.UnitMeasureCode = item.UnitMeasureCode; outItem.BomLevel = item.BomLevel; outItem.PerAssemblyQty = item.PerAssemblyQty; outItem.ModifiedDate = item.ModifiedDate; return(outItem); }
/// <summary> /// Convert a nettiers collection to the ws proxy collection. /// </summary> public static Nettiers.AdventureWorks.Entities.BillOfMaterials Convert(Nettiers.AdventureWorks.Entities.BillOfMaterials outItem, WsProxy.BillOfMaterials item) { if (item != null && outItem != null) { outItem.BillOfMaterialsId = item.BillOfMaterialsId; outItem.ProductAssemblyId = item.ProductAssemblyId; outItem.ComponentId = item.ComponentId; outItem.StartDate = item.StartDate; outItem.EndDate = item.EndDate; outItem.UnitMeasureCode = item.UnitMeasureCode; outItem.BomLevel = item.BomLevel; outItem.PerAssemblyQty = item.PerAssemblyQty; outItem.ModifiedDate = item.ModifiedDate; outItem.AcceptChanges(); } return(outItem); }
/// <summary> /// Inserts a Nettiers.AdventureWorks.Entities.BillOfMaterials object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Nettiers.AdventureWorks.Entities.BillOfMaterials object to insert.</param> /// <remarks></remarks> /// <returns>Returns true if operation is successful.</returns> public override bool Insert(TransactionManager transactionManager, Nettiers.AdventureWorks.Entities.BillOfMaterials entity) { WsProxy.AdventureWorksServices proxy = new WsProxy.AdventureWorksServices(); proxy.Url = Url; try { WsProxy.BillOfMaterials result = proxy.BillOfMaterialsProvider_Insert(Convert(entity)); Convert(entity, result); return(true); } catch (SoapException soex) { System.Diagnostics.Debug.WriteLine(soex); throw soex; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); throw ex; } }
///<summary> /// Update the Typed BillOfMaterials Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, BillOfMaterials mock) { mock.StartDate = TestUtility.Instance.RandomDateTime(); mock.EndDate = TestUtility.Instance.RandomDateTime(); mock.BomLevel = TestUtility.Instance.RandomShort(); mock.PerAssemblyQty = (decimal)TestUtility.Instance.RandomShort(); mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); //OneToOneRelationship Product mockProductByComponentId = ProductTest.CreateMockInstance(tm); DataRepository.ProductProvider.Insert(tm, mockProductByComponentId); mock.ComponentId = mockProductByComponentId.ProductId; //OneToOneRelationship Product mockProductByProductAssemblyId = ProductTest.CreateMockInstance(tm); DataRepository.ProductProvider.Insert(tm, mockProductByProductAssemblyId); mock.ProductAssemblyId = mockProductByProductAssemblyId.ProductId; //OneToOneRelationship UnitMeasure mockUnitMeasureByUnitMeasureCode = UnitMeasureTest.CreateMockInstance(tm); DataRepository.UnitMeasureProvider.Insert(tm, mockUnitMeasureByUnitMeasureCode); mock.UnitMeasureCode = mockUnitMeasureByUnitMeasureCode.UnitMeasureCode; }
///<summary> /// Returns a Typed BillOfMaterials Entity with mock values. ///</summary> static public BillOfMaterials CreateMockInstance_Generated(TransactionManager tm) { BillOfMaterials mock = new BillOfMaterials(); mock.StartDate = TestUtility.Instance.RandomDateTime(); mock.EndDate = TestUtility.Instance.RandomDateTime(); mock.BomLevel = TestUtility.Instance.RandomShort(); mock.PerAssemblyQty = (decimal)TestUtility.Instance.RandomShort(); mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); //OneToOneRelationship Product mockProductByComponentId = ProductTest.CreateMockInstance(tm); DataRepository.ProductProvider.Insert(tm, mockProductByComponentId); mock.ComponentId = mockProductByComponentId.ProductId; //OneToOneRelationship Product mockProductByProductAssemblyId = ProductTest.CreateMockInstance(tm); DataRepository.ProductProvider.Insert(tm, mockProductByProductAssemblyId); mock.ProductAssemblyId = mockProductByProductAssemblyId.ProductId; //OneToOneRelationship UnitMeasure mockUnitMeasureByUnitMeasureCode = UnitMeasureTest.CreateMockInstance(tm); DataRepository.UnitMeasureProvider.Insert(tm, mockUnitMeasureByUnitMeasureCode); mock.UnitMeasureCode = mockUnitMeasureByUnitMeasureCode.UnitMeasureCode; // create a temporary collection and add the item to it TList<BillOfMaterials> tempMockCollection = new TList<BillOfMaterials>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return (BillOfMaterials)mock; }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); BillOfMaterials entity = mock.Copy() as BillOfMaterials; entity = (BillOfMaterials)mock.Clone(); Assert.IsTrue(BillOfMaterials.ValueEquals(entity, mock), "Clone is not working"); } }
/// <summary> /// Serialize a BillOfMaterials 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_BillOfMaterialsCollection.xml"); mock = CreateMockInstance(tm); TList<BillOfMaterials> mockCollection = new TList<BillOfMaterials>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<BillOfMaterials> correctly serialized to a temporary file."); } }
/// <summary> /// Serialize the mock BillOfMaterials 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_BillOfMaterials.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> /// Deep load all BillOfMaterials children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.BillOfMaterialsProvider.GetPaged(tm, 0, 10, out count); DataRepository.BillOfMaterialsProvider.DeepLoading += new EntityProviderBaseCore<BillOfMaterials, BillOfMaterialsKey>.DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) e.Cancel = true; } ); if (mockCollection.Count > 0) { DataRepository.BillOfMaterialsProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("BillOfMaterials instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.BillOfMaterialsProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Convert a nettiers collection to the ws proxy collection. /// </summary> public static Nettiers.AdventureWorks.Entities.BillOfMaterials Convert(WsProxy.BillOfMaterials item) { Nettiers.AdventureWorks.Entities.BillOfMaterials outItem = item == null ? null : new Nettiers.AdventureWorks.Entities.BillOfMaterials(); Convert(outItem, item); return(outItem); }
/// <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(BillOfMaterials mock) { //Code your changes to the data object here. //Add 1 day to the StartDate. EndDate has to be greater than start date mock.EndDate = mock.StartDate.AddDays(1); }
///<summary> /// Update the Typed BillOfMaterials Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, BillOfMaterials mock) { BillOfMaterialsTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }