public void Can_Deserialize_An_Address_Stored_in_ExtendedDataCollection()
        {
            //// Arrange
            var extendedData = new ExtendedDataCollection();
            extendedData.AddAddress(_address, AddressType.Shipping);

            //// Act
            var address = extendedData.GetAddress(AddressType.Shipping);

            //// Assert
            Assert.NotNull(address);
            Assert.AreEqual(typeof(Address), address.GetType());
        }
        /// <summary>
        /// Gets an <see cref="IAddress"/> from the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <param name="addressType">
        /// The address Type.
        /// </param>
        /// <returns>
        /// The <see cref="IAddress"/>.
        /// </returns>
        public static IAddress GetAddress(this ExtendedDataCollection extendedData, AddressType addressType)
        {
            var address = extendedData.GetAddress(addressType == AddressType.Shipping
                                               ? Constants.ExtendedDataKeys.ShippingDestinationAddress
                                               : Constants.ExtendedDataKeys.BillingAddress);

            if (address != null)
            {
                address.AddressType = addressType;
            }

            return(address);
        }
        /// <summary>
        /// Gets (creates a new <see cref="IShipment"/>) from values saved in the <see cref="ExtendedDataCollection"/>
        /// </summary>
        /// <typeparam name="T">
        /// The type of line item
        /// </typeparam>
        /// <param name="extendedData">
        /// The extended Data.
        /// </param>
        /// <returns>
        /// The <see cref="IShipment"/>.
        /// </returns>
        public static IShipment GetShipment <T>(this ExtendedDataCollection extendedData) where T : LineItemBase
        {
            var origin             = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingOriginAddress);
            var destination        = extendedData.GetAddress(Constants.ExtendedDataKeys.ShippingDestinationAddress);
            var lineItemCollection = extendedData.GetLineItemCollection <T>();

            if (origin == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not contain an 'origin shipping address'");
            }
            if (destination == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not container a 'destination shipping address'");
            }
            if (lineItemCollection == null)
            {
                throw new NullReferenceException("ExtendedDataCollection does not contain a 'line item collection'");
            }

            // TODO - this is a total hack since this value can be changed in the database
            var quoted = new ShipmentStatus()
            {
                Key        = Constants.ShipmentStatus.Quoted,
                Alias      = "quoted",
                Name       = "Quoted",
                Active     = true,
                CreateDate = DateTime.Now,
                UpdateDate = DateTime.Now
            };


            return(new Shipment(quoted, origin, destination, lineItemCollection)
            {
                ShipMethodKey = extendedData.ContainsKey(Constants.ExtendedDataKeys.ShipMethodKey) ?
                                extendedData.GetShipMethodKey() :
                                Guid.Empty
            });
        }
Example #4
0
        public void Can_Deserialize_An_Address_Stored_in_ExtendedDataCollection()
        {
            //// Arrange
            var extendedData = new ExtendedDataCollection();

            extendedData.AddAddress(_address, AddressType.Shipping);

            //// Act
            var address = extendedData.GetAddress(AddressType.Shipping);

            //// Assert
            Assert.NotNull(address);
            Assert.AreEqual(typeof(Address), address.GetType());
        }