/// <summary> /// Convert a nettiers collection to the ws proxy collection. /// </summary> public static Nettiers.AdventureWorks.Entities.Employee Convert(Nettiers.AdventureWorks.Entities.Employee outItem, WsProxy.Employee item) { if (item != null && outItem != null) { outItem.EmployeeId = item.EmployeeId; outItem.NationalIdNumber = item.NationalIdNumber; outItem.ContactId = item.ContactId; outItem.LoginId = item.LoginId; outItem.ManagerId = item.ManagerId; outItem.Title = item.Title; outItem.BirthDate = item.BirthDate; outItem.MaritalStatus = item.MaritalStatus; outItem.Gender = item.Gender; outItem.HireDate = item.HireDate; outItem.SalariedFlag = item.SalariedFlag; outItem.VacationHours = item.VacationHours; outItem.SickLeaveHours = item.SickLeaveHours; outItem.CurrentFlag = item.CurrentFlag; outItem.Rowguid = item.Rowguid; outItem.ModifiedDate = item.ModifiedDate; outItem.AcceptChanges(); } return(outItem); }
/// <summary> /// Inserts a mock Employee entity into the database. /// </summary> private void Step_01_Insert_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Assert.IsTrue(DataRepository.EmployeeProvider.Insert(tm, mock), "Insert failed"); System.Console.WriteLine("DataRepository.EmployeeProvider.Insert(mock):"); System.Console.WriteLine(mock); //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }
/// <summary> /// Inserts a Nettiers.AdventureWorks.Entities.Employee object into the datasource using a transaction. /// </summary> /// <param name="transactionManager"><see cref="TransactionManager"/> object</param> /// <param name="entity">Nettiers.AdventureWorks.Entities.Employee object to insert.</param> /// <remarks></remarks> /// <returns>Returns true if operation is successful.</returns> public override bool Insert(TransactionManager transactionManager, Nettiers.AdventureWorks.Entities.Employee entity) { WsProxy.AdventureWorksServices proxy = new WsProxy.AdventureWorksServices(); proxy.Url = Url; try { WsProxy.Employee result = proxy.EmployeeProvider_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.Employee Convert(WsProxy.Employee item) { Nettiers.AdventureWorks.Entities.Employee outItem = item == null ? null : new Nettiers.AdventureWorks.Entities.Employee(); 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(Employee mock) { //Code your changes to the data object here. mock.BirthDate = DateTime.Now.AddYears(-20); if (TestUtility.Instance.RandomBoolean()) { mock.MaritalStatus = "S"; } else { mock.MaritalStatus = "M"; } if (TestUtility.Instance.RandomBoolean()) { mock.Gender = "F"; } else { mock.Gender = "M"; } mock.HireDate = DateTime.Now.AddDays(-2); mock.VacationHours = TestUtility.Instance.RandomShort(-40, 240); mock.SickLeaveHours = TestUtility.Instance.RandomShort(0, 120); }
///<summary> /// Update the Typed Employee Entity with modified mock values. ///</summary> static public void UpdateMockInstance(TransactionManager tm, Employee mock) { EmployeeTest.UpdateMockInstance_Generated(tm, mock); // make any alterations necessary // (i.e. for DB check constraints, special test cases, etc.) SetSpecialTestData(mock); }
///<summary> /// Update the Typed Employee Entity with modified mock values. ///</summary> static public void UpdateMockInstance_Generated(TransactionManager tm, Employee mock) { mock.NationalIdNumber = TestUtility.Instance.RandomString(6, false);; mock.LoginId = TestUtility.Instance.RandomString(127, false);; mock.Title = TestUtility.Instance.RandomString(24, false);; mock.BirthDate = TestUtility.Instance.RandomDateTime(); mock.MaritalStatus = TestUtility.Instance.RandomString(1, false);; mock.Gender = TestUtility.Instance.RandomString(1, false);; mock.HireDate = TestUtility.Instance.RandomDateTime(); mock.SalariedFlag = TestUtility.Instance.RandomBoolean(); mock.VacationHours = TestUtility.Instance.RandomShort(); mock.SickLeaveHours = TestUtility.Instance.RandomShort(); mock.CurrentFlag = TestUtility.Instance.RandomBoolean(); mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); int count0 = 0; TList<Contact> _collection0 = DataRepository.ContactProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.ContactId = _collection0[0].ContactId; } int count1 = 0; TList<Employee> _collection1 = DataRepository.EmployeeProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.ManagerId = _collection1[0].EmployeeId; } }
///<summary> /// Returns a Typed Employee Entity with mock values. ///</summary> static public Employee CreateMockInstance_Generated(TransactionManager tm) { Employee mock = new Employee(); mock.NationalIdNumber = TestUtility.Instance.RandomString(6, false);; mock.LoginId = TestUtility.Instance.RandomString(127, false);; mock.Title = TestUtility.Instance.RandomString(24, false);; mock.BirthDate = TestUtility.Instance.RandomDateTime(); mock.MaritalStatus = TestUtility.Instance.RandomString(1, false);; mock.Gender = TestUtility.Instance.RandomString(1, false);; mock.HireDate = TestUtility.Instance.RandomDateTime(); mock.SalariedFlag = TestUtility.Instance.RandomBoolean(); mock.VacationHours = TestUtility.Instance.RandomShort(); mock.SickLeaveHours = TestUtility.Instance.RandomShort(); mock.CurrentFlag = TestUtility.Instance.RandomBoolean(); mock.ModifiedDate = TestUtility.Instance.RandomDateTime(); int count0 = 0; TList<Contact> _collection0 = DataRepository.ContactProvider.GetPaged(tm, 0, 10, out count0); //_collection0.Shuffle(); if (_collection0.Count > 0) { mock.ContactId = _collection0[0].ContactId; } int count1 = 0; TList<Employee> _collection1 = DataRepository.EmployeeProvider.GetPaged(tm, 0, 10, out count1); //_collection1.Shuffle(); if (_collection1.Count > 0) { mock.ManagerId = _collection1[0].EmployeeId; } // create a temporary collection and add the item to it TList<Employee> tempMockCollection = new TList<Employee>(); tempMockCollection.Add(mock); tempMockCollection.Remove(mock); return (Employee)mock; }
/// <summary> /// Test methods exposed by the EntityHelper class. /// </summary> private void Step_20_TestEntityHelper_Generated() { using (TransactionManager tm = CreateTransaction()) { mock = CreateMockInstance(tm); Employee entity = mock.Copy() as Employee; entity = (Employee)mock.Clone(); Assert.IsTrue(Employee.ValueEquals(entity, mock), "Clone is not working"); } }
/// <summary> /// Serialize a Employee 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_EmployeeCollection.xml"); mock = CreateMockInstance(tm); TList<Employee> mockCollection = new TList<Employee>(); mockCollection.Add(mock); EntityHelper.SerializeXml(mockCollection, fileName); Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found"); System.Console.WriteLine("TList<Employee> correctly serialized to a temporary file."); } }
/// <summary> /// Serialize the mock Employee 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_Employee.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 Employee children. /// </summary> private void Step_03_DeepLoad_Generated() { using (TransactionManager tm = CreateTransaction()) { int count = -1; mock = CreateMockInstance(tm); mockCollection = DataRepository.EmployeeProvider.GetPaged(tm, 0, 10, out count); DataRepository.EmployeeProvider.DeepLoading += new EntityProviderBaseCore<Employee, EmployeeKey>.DeepLoadingEventHandler( delegate(object sender, DeepSessionEventArgs e) { if (e.DeepSession.Count > 3) e.Cancel = true; } ); if (mockCollection.Count > 0) { DataRepository.EmployeeProvider.DeepLoad(tm, mockCollection[0]); System.Console.WriteLine("Employee instance correctly deep loaded at 1 level."); mockCollection.Add(mock); // DataRepository.EmployeeProvider.DeepSave(tm, mockCollection); } //normally one would commit here //tm.Commit(); //IDisposable will Rollback Transaction since it's left uncommitted } }