/// <summary> /// Convert a nettiers entity to the ws proxy entity. /// </summary> public static WsProxy.Address Convert(Nettiers.AdventureWorks.Entities.Address item) { WsProxy.Address outItem = new WsProxy.Address(); outItem.AddressId = item.AddressId; outItem.AddressLine1 = item.AddressLine1; outItem.AddressLine2 = item.AddressLine2; outItem.City = item.City; outItem.StateProvinceId = item.StateProvinceId; outItem.PostalCode = item.PostalCode; outItem.Rowguid = item.Rowguid; outItem.ModifiedDate = item.ModifiedDate; return(outItem); }
/// <summary> /// Inserts a mock Address entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.AddressProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.AddressProvider.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 collection to the ws proxy collection. /// </summary> public static Nettiers.AdventureWorks.Entities.Address Convert(Nettiers.AdventureWorks.Entities.Address outItem, WsProxy.Address item) { if (item != null && outItem != null) { outItem.AddressId = item.AddressId; outItem.AddressLine1 = item.AddressLine1; outItem.AddressLine2 = item.AddressLine2; outItem.City = item.City; outItem.StateProvinceId = item.StateProvinceId; outItem.PostalCode = item.PostalCode; outItem.Rowguid = item.Rowguid; outItem.ModifiedDate = item.ModifiedDate; outItem.AcceptChanges(); } return(outItem); }
/// <summary> /// Inserts a Nettiers.AdventureWorks.Entities.Address object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Nettiers.AdventureWorks.Entities.Address object to insert.</param> /// <remarks></remarks> /// <returns>Returns true if operation is successful.</returns> public override bool Insert(TransactionManager transactionManager, Nettiers.AdventureWorks.Entities.Address entity) { WsProxy.AdventureWorksServices proxy = new WsProxy.AdventureWorksServices(); proxy.Url = Url; try { WsProxy.Address result = proxy.AddressProvider_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> /// Convert a nettiers collection to the ws proxy collection. /// </summary> public static Nettiers.AdventureWorks.Entities.Address Convert(WsProxy.Address item) { Nettiers.AdventureWorks.Entities.Address outItem = item == null ? null : new Nettiers.AdventureWorks.Entities.Address(); 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(Address mock) { //Code your changes to the data object here. }
///<summary> /// Update the Typed Address Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, Address mock) { AddressTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
///<summary> /// Update the Typed Address Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, Address mock) { mock.AddressLine1 = TestUtility.Instance.RandomString(29, false);; mock.AddressLine2 = TestUtility.Instance.RandomString(29, false);; mock.City = TestUtility.Instance.RandomString(14, false);; mock.PostalCode = TestUtility.Instance.RandomString(6, false);; mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); int count0 = 0; TList<StateProvince> _collection0 = DataRepository.StateProvinceProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.StateProvinceId = _collection0[0].StateProvinceId; } }
///<summary> /// Returns a Typed Address Entity with mock values. ///</summary> static public Address CreateMockInstance_Generated(TransactionManager tm) { Address mock = new Address(); mock.AddressLine1 = TestUtility.Instance.RandomString(29, false);; mock.AddressLine2 = TestUtility.Instance.RandomString(29, false);; mock.City = TestUtility.Instance.RandomString(14, false);; mock.PostalCode = TestUtility.Instance.RandomString(6, false);; mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); int count0 = 0; TList<StateProvince> _collection0 = DataRepository.StateProvinceProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.StateProvinceId = _collection0[0].StateProvinceId; } // create a temporary collection and add the item to it TList<Address> tempMockCollection = new TList<Address>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return (Address)mock; }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Address entity = mock.Copy() as Address; entity = (Address)mock.Clone(); Assert.IsTrue(Address.ValueEquals(entity, mock), "Clone is not working"); } }
/// <summary> /// Serialize a Address 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_AddressCollection.xml"); mock = CreateMockInstance(tm); TList<Address> mockCollection = new TList<Address>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<Address> correctly serialized to a temporary file."); } }
/// <summary> /// Serialize the mock Address 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_Address.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 Address children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.AddressProvider.GetPaged(tm, 0, 10, out count); DataRepository.AddressProvider.DeepLoading += new EntityProviderBaseCore<Address, AddressKey>.DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) e.Cancel = true; } ); if (mockCollection.Count > 0) { DataRepository.AddressProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("Address instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.AddressProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }