Пример #1
0
		/// <summary>
		/// Creates a new address object
		/// </summary>
		/// <param name="number">can be 1 or 2. If 1, the first address constants are used otherwise the second</param>
		/// <returns></returns>
		public static Address CreateNewAddress(int number)
		{
			Address toReturn = new Address();
			switch(number)
			{
				case 1:
					toReturn.StreetName = ConstantsEnums.StreetName1;
					toReturn.HouseNumber = ConstantsEnums.HouseNumber1;
					toReturn.Zipcode = ConstantsEnums.ZipCode1;
					toReturn.City = ConstantsEnums.City1;
					toReturn.Country = ConstantsEnums.Country1;
					break;
				case 2:
					toReturn.StreetName = ConstantsEnums.StreetName2;
					toReturn.HouseNumber = ConstantsEnums.HouseNumber2;
					toReturn.Zipcode = ConstantsEnums.ZipCode2;
					toReturn.City = ConstantsEnums.City2;
					toReturn.Country = ConstantsEnums.Country2;
					break;
				case 3:
					toReturn.StreetName = ConstantsEnums.StreetName3;
					toReturn.HouseNumber = ConstantsEnums.HouseNumber3;
					toReturn.Zipcode = ConstantsEnums.ZipCode3;
					toReturn.City = ConstantsEnums.City3;
					toReturn.Country = ConstantsEnums.Country3;
					break;
				case 4:
					toReturn.StreetName = ConstantsEnums.StreetName4;
					toReturn.HouseNumber = ConstantsEnums.HouseNumber4;
					toReturn.Zipcode = ConstantsEnums.ZipCode4;
					toReturn.City = ConstantsEnums.City4;
					toReturn.Country = ConstantsEnums.Country4;
					break;
				default:
					throw new ArgumentException("number should be 1 - 4", "number");
			}

			return toReturn;
		}
Пример #2
0
		public void PhantomInsertPreventionTest()
		{
			var newCustomer = new Customer();
			var ba = new Address();
			var va = new Address();
			newCustomer.VisitingAddress = va;
			newCustomer.BillingAddress = ba;

			// as everything is empty, and Address isn't saved because it's not dirty, customer shouldn't be saved as well.
			using(var ctx = GetContext())
			{
				ctx.Customers.InsertOnSubmit(newCustomer);
				ctx.SubmitChanges();
				Assert.AreEqual(0, ba.AddressId);
				Assert.AreEqual(0, va.AddressId);
			}
		}