Inheritance: ProductBase
Beispiel #1
0
        /// <summary>
        /// Convert a nettiers collection to the ws proxy collection.
        /// </summary>
        public static Nettiers.AdventureWorks.Entities.Product Convert(Nettiers.AdventureWorks.Entities.Product outItem, WsProxy.Product item)
        {
            if (item != null && outItem != null)
            {
                outItem.ProductId             = item.ProductId;
                outItem.Name                  = item.Name;
                outItem.ProductNumber         = item.ProductNumber;
                outItem.MakeFlag              = item.MakeFlag;
                outItem.FinishedGoodsFlag     = item.FinishedGoodsFlag;
                outItem.Color                 = item.Color;
                outItem.SafetyStockLevel      = item.SafetyStockLevel;
                outItem.ReorderPoint          = item.ReorderPoint;
                outItem.StandardCost          = item.StandardCost;
                outItem.ListPrice             = item.ListPrice;
                outItem.Size                  = item.Size;
                outItem.SizeUnitMeasureCode   = item.SizeUnitMeasureCode;
                outItem.WeightUnitMeasureCode = item.WeightUnitMeasureCode;
                outItem.Weight                = item.Weight;
                outItem.DaysToManufacture     = item.DaysToManufacture;
                outItem.ProductLine           = item.ProductLine;
                outItem.SafeNameClass         = item.SafeNameClass;
                outItem.Style                 = item.Style;
                outItem.ProductSubcategoryId  = item.ProductSubcategoryId;
                outItem.ProductModelId        = item.ProductModelId;
                outItem.SellStartDate         = item.SellStartDate;
                outItem.SellEndDate           = item.SellEndDate;
                outItem.DiscontinuedDate      = item.DiscontinuedDate;
                outItem.Rowguid               = item.Rowguid;
                outItem.ModifiedDate          = item.ModifiedDate;

                outItem.AcceptChanges();
            }

            return(outItem);
        }
		/// <summary>
		/// Inserts a mock Product entity into the database.
		/// </summary>
		private void Step_01_Insert_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				mock = CreateMockInstance(tm);
				Assert.IsTrue(DataRepository.ProductProvider.Insert(tm, mock), "Insert failed");
										
				System.Console.WriteLine("DataRepository.ProductProvider.Insert(mock):");			
				System.Console.WriteLine(mock);			
				
				//normally one would commit here
				//tm.Commit();
				//IDisposable will Rollback Transaction since it's left uncommitted
			}
		}
Beispiel #3
0
        /// <summary>
        ///     Inserts a Nettiers.AdventureWorks.Entities.Product object into the datasource using a transaction.
        /// </summary>
        /// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
        /// <param name="entity">Nettiers.AdventureWorks.Entities.Product object to insert.</param>
        /// <remarks></remarks>
        /// <returns>Returns true if operation is successful.</returns>
        public override bool Insert(TransactionManager transactionManager, Nettiers.AdventureWorks.Entities.Product entity)
        {
            WsProxy.AdventureWorksServices proxy = new WsProxy.AdventureWorksServices();
            proxy.Url = Url;

            try
            {
                WsProxy.Product result = proxy.ProductProvider_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;
            }
        }
Beispiel #4
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(Product mock)
        {
            //Code your changes to the data object here.
            mock.ProductLine = "R";
            mock.SafeNameClass = "H";
            mock.Style = "U";
            mock.SellEndDate = mock.SellStartDate.AddDays(1);
        }
Beispiel #5
0
        ///<summary>
        ///  Update the Typed Product Entity with modified mock values.
        ///</summary>
        static public void UpdateMockInstance(TransactionManager tm, Product mock)
        {
            ProductTest.UpdateMockInstance_Generated(tm, mock);
            
			// make any alterations necessary 
            // (i.e. for DB check constraints, special test cases, etc.)
			SetSpecialTestData(mock);
        }
		///<summary>
		///  Update the Typed Product Entity with modified mock values.
		///</summary>
		static public void UpdateMockInstance_Generated(TransactionManager tm, Product mock)
		{
			mock.Name = TestUtility.Instance.RandomString(24, false);;
			mock.ProductNumber = TestUtility.Instance.RandomString(11, false);;
			mock.MakeFlag = TestUtility.Instance.RandomBoolean();
			mock.FinishedGoodsFlag = TestUtility.Instance.RandomBoolean();
			mock.Color = TestUtility.Instance.RandomString(6, false);;
			mock.SafetyStockLevel = TestUtility.Instance.RandomShort();
			mock.ReorderPoint = TestUtility.Instance.RandomShort();
			mock.StandardCost = TestUtility.Instance.RandomShort();
			mock.ListPrice = TestUtility.Instance.RandomShort();
			mock.Size = TestUtility.Instance.RandomString(5, false);;
			mock.Weight = (decimal)TestUtility.Instance.RandomShort();
			mock.DaysToManufacture = TestUtility.Instance.RandomNumber();
			mock.ProductLine = TestUtility.Instance.RandomString(2, false);;
			mock.SafeNameClass = TestUtility.Instance.RandomString(2, false);;
			mock.Style = TestUtility.Instance.RandomString(2, false);;
			mock.SellStartDate = TestUtility.Instance.RandomDateTime();
			mock.SellEndDate = TestUtility.Instance.RandomDateTime();
			mock.DiscontinuedDate = TestUtility.Instance.RandomDateTime();
			mock.ModifiedDate = TestUtility.Instance.RandomDateTime();
			
			int count0 = 0;
			TList<ProductModel> _collection0 = DataRepository.ProductModelProvider.GetPaged(tm, 0, 10, out count0);
			//_collection0.Shuffle();
			if (_collection0.Count > 0)
			{
				mock.ProductModelId = _collection0[0].ProductModelId;
			}
			int count1 = 0;
			TList<ProductSubcategory> _collection1 = DataRepository.ProductSubcategoryProvider.GetPaged(tm, 0, 10, out count1);
			//_collection1.Shuffle();
			if (_collection1.Count > 0)
			{
				mock.ProductSubcategoryId = _collection1[0].ProductSubcategoryId;
			}
			int count2 = 0;
			TList<UnitMeasure> _collection2 = DataRepository.UnitMeasureProvider.GetPaged(tm, 0, 10, out count2);
			//_collection2.Shuffle();
			if (_collection2.Count > 0)
			{
				mock.SizeUnitMeasureCode = _collection2[0].UnitMeasureCode;
			}
			int count3 = 0;
			TList<UnitMeasure> _collection3 = DataRepository.UnitMeasureProvider.GetPaged(tm, 0, 10, out count3);
			//_collection3.Shuffle();
			if (_collection3.Count > 0)
			{
				mock.WeightUnitMeasureCode = _collection3[0].UnitMeasureCode;
			}
		}
		/// <summary>
		/// Test methods exposed by the EntityHelper class.
		/// </summary>
		private void Step_20_TestEntityHelper_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				mock = CreateMockInstance(tm);
				
				Product entity = mock.Copy() as Product;
				entity = (Product)mock.Clone();
				Assert.IsTrue(Product.ValueEquals(entity, mock), "Clone is not working");
			}
		}
		/// <summary>
		/// Serialize a Product 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_ProductCollection.xml");
				
				mock = CreateMockInstance(tm);
				TList<Product> mockCollection = new TList<Product>();
				mockCollection.Add(mock);
			
				EntityHelper.SerializeXml(mockCollection, fileName);
				
				Assert.IsTrue(System.IO.File.Exists(fileName), "Serialized mock collection not found");
				System.Console.WriteLine("TList<Product> correctly serialized to a temporary file.");					
			}
		}
		/// <summary>
		/// Serialize the mock Product 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_Product.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 Product children.
		/// </summary>
		private void Step_03_DeepLoad_Generated()
		{
			using (TransactionManager tm = CreateTransaction())
			{
				int count = -1;
				mock =  CreateMockInstance(tm);
				mockCollection = DataRepository.ProductProvider.GetPaged(tm, 0, 10, out count);
			
				DataRepository.ProductProvider.DeepLoading += new EntityProviderBaseCore<Product, ProductKey>.DeepLoadingEventHandler(
						delegate(object sender, DeepSessionEventArgs e)
						{
							if (e.DeepSession.Count > 3)
								e.Cancel = true;
						}
					);

				if (mockCollection.Count > 0)
				{
					
					DataRepository.ProductProvider.DeepLoad(tm, mockCollection[0]);
					System.Console.WriteLine("Product instance correctly deep loaded at 1 level.");
									
					mockCollection.Add(mock);
					// DataRepository.ProductProvider.DeepSave(tm, mockCollection);
				}
				
				//normally one would commit here
				//tm.Commit();
				//IDisposable will Rollback Transaction since it's left uncommitted
			}
		}
Beispiel #11
0
 /// <summary>
 /// Convert a nettiers collection to the ws proxy collection.
 /// </summary>
 public static Nettiers.AdventureWorks.Entities.Product Convert(WsProxy.Product item)
 {
     Nettiers.AdventureWorks.Entities.Product outItem = item == null ? null : new Nettiers.AdventureWorks.Entities.Product();
     Convert(outItem, item);
     return(outItem);
 }