Beispiel #1
0
        /// <summary>
        /// Dispatches the visit to specialized visitor functions
        /// </summary>
        public TResult Visit(ImmutableProduct product)
        {
            var compositeProduct = product as ImmutableCompositeProduct;

            return(compositeProduct != null
                                ? this.VisitCompositeProduct(compositeProduct)
                                : this.VisitProduct(product));
        }
		public void TestProductCreation()
		{
			// Create an immutable product
			var ip = new ImmutableProduct(Guid.NewGuid(), "Test", 1M);
			Assert.IsNotNull(ip);

			// Create an immutable composite product. Note that both parts
			// refer to the same product. Therefore the ImmutableProduct
			// object has to be reused.
			var icp = new ImmutableCompositeProduct(
				Guid.NewGuid(), "Test", 1M,
				new[] {
					new Part() { ComponentProductID = ip.ProductID, Amount = 5 },
					new Part() { ComponentProductID = ip.ProductID, Amount = 10 }
				},
				new[] { ip });
			Assert.IsNotNull(ip);
			Assert.AreSame(ip, icp.Parts[0].Part);
			Assert.AreSame(icp.Parts[0].Part, icp.Parts[1].Part);

			// Create an immutable composite product. Note that the part
			// list as already immutable. Therefore it has to be reused
			// and must not be copied.
			var iplist = ImmutableList<ImmutablePart>.Empty
				.Add(new ImmutablePart(ip.ProductID, 5, new[] { ip }));
			icp = new ImmutableCompositeProduct(
				Guid.NewGuid(), "Test", 1M, iplist, new[] { ip });
			Assert.AreSame(icp.Parts, iplist);

			// Create an immutable composite product. Note that the part
			// inside the part list is already immutable. Therefore it has 
			// to be reused and must not be copied.
			icp = new ImmutableCompositeProduct(
				Guid.NewGuid(), "Test", 1M, new[] { iplist[0] }, new[] { ip });
			Assert.AreSame(icp.Parts[0], iplist[0]);
		}
Beispiel #3
0
 public abstract TResult VisitProduct(ImmutableProduct product);