Inheritance: CustomerBase
		/// <summary>
		/// Inserts a mock Customer entity into the database.
		/// </summary>
		private void Step_01_Insert_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				mock = CreateMockInstance(tm);
				Assert.IsTrue(DataRepository.CustomerProvider.Insert(tm, mock), "Insert failed");
										
				System.Console.WriteLine("DataRepository.CustomerProvider.Insert(mock):");			
				System.Console.WriteLine(mock);			
				
				//normally one would commit here
				//tm.Commit();
				//IDisposable will Rollback Transaction since it's left uncommitted
			}
		}
示例#2
0
		/// <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(Customer mock)
        {
            //Code your changes to the data object here.

            //Set a random customer type
            if (TestUtility.Instance.RandomBoolean())
            {
                mock.CustomerType = "S";
            }
            else
            {
                mock.CustomerType = "I";
            }
        }
示例#3
0
        ///<summary>
        ///  Update the Typed Customer Entity with modified mock values.
        ///</summary>
        static public void UpdateMockInstance(TransactionManager tm, Customer mock)
        {
            CustomerTest.UpdateMockInstance_Generated(tm, mock);
            
			// make any alterations necessary 
            // (i.e. for DB check constraints, special test cases, etc.)
			SetSpecialTestData(mock);
        }
		///<summary>
		///  Update the Typed Customer Entity with modified mock values.
		///</summary>
		static public void UpdateMockInstance_Generated(TransactionManager tm, Customer mock)
		{
			mock.CustomerType = TestUtility.Instance.RandomString(1, false);;
			mock.ModifiedDate = TestUtility.Instance.RandomDateTime();
			
			int count0 = 0;
			TList<SalesTerritory> _collection0 = DataRepository.SalesTerritoryProvider.GetPaged(tm, 0, 10, out count0);
			//_collection0.Shuffle();
			if (_collection0.Count > 0)
			{
				mock.TerritoryId = _collection0[0].TerritoryId;
			}
		}
		///<summary>
		///  Returns a Typed Customer Entity with mock values.
		///</summary>
		static public Customer CreateMockInstance_Generated(TransactionManager tm)
		{		
			Customer mock = new Customer();
						
			mock.CustomerType = TestUtility.Instance.RandomString(1, false);;
			mock.ModifiedDate = TestUtility.Instance.RandomDateTime();
			
			int count0 = 0;
			TList<SalesTerritory> _collection0 = DataRepository.SalesTerritoryProvider.GetPaged(tm, 0, 10, out count0);
			//_collection0.Shuffle();
			if (_collection0.Count > 0)
			{
				mock.TerritoryId = _collection0[0].TerritoryId;
						
			}
		
			// create a temporary collection and add the item to it
			TList<Customer> tempMockCollection = new TList<Customer>();
			tempMockCollection.Add(mock);
			tempMockCollection.Remove(mock);
			
		
		   return (Customer)mock;
		}
		/// <summary>
		/// Test methods exposed by the EntityHelper class.
		/// </summary>
		private void Step_20_TestEntityHelper_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				mock = CreateMockInstance(tm);
				
				Customer entity = mock.Copy() as Customer;
				entity = (Customer)mock.Clone();
				Assert.IsTrue(Customer.ValueEquals(entity, mock), "Clone is not working");
			}
		}
		/// <summary>
		/// Serialize a Customer 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_CustomerCollection.xml");
				
				mock = CreateMockInstance(tm);
				TList<Customer> mockCollection = new TList<Customer>();
				mockCollection.Add(mock);
			
				EntityHelper.SerializeXml(mockCollection, fileName);
				
				Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found");
				System.Console.WriteLine("TList<Customer> correctly serialized to a temporary file.");					
			}
		}
		/// <summary>
		/// Serialize the mock Customer 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_Customer.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 Customer children.
		/// </summary>
		private void Step_03_DeepLoad_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				int count = -1;
				mock =  CreateMockInstance(tm);
				mockCollection = DataRepository.CustomerProvider.GetPaged(tm, 0, 10, out count);
			
				DataRepository.CustomerProvider.DeepLoading += new EntityProviderBaseCore<Customer, CustomerKey>.DeepLoadingEventHandler(
						delegate(object sender, DeepSessionEventArgs e)
						{
							if (e.DeepSession.Count > 3)
								e.Cancel = true;
						}
					);

				if (mockCollection.Count > 0)
				{
					
					DataRepository.CustomerProvider.DeepLoad(tm, mockCollection[0]);
					System.Console.WriteLine("Customer instance correctly deep loaded at 1 level.");
									
					mockCollection.Add(mock);
					// DataRepository.CustomerProvider.DeepSave(tm, mockCollection);
				}
				
				//normally one would commit here
				//tm.Commit();
				//IDisposable will Rollback Transaction since it's left uncommitted
			}
		}