public void Can_Deserialize_A_LineItemCollection_From_ExtendedDataCollection() { //// Arrange var extendedData = new ExtendedDataCollection(); extendedData.AddLineItemCollection(_shipment.Items); Console.Write(extendedData.GetValue(Constants.ExtendedDataKeys.LineItemCollection)); //// Act var lineItemCollection = extendedData.GetLineItemCollection <ItemCacheLineItem>(); //// Assert Assert.NotNull(lineItemCollection); Assert.IsTrue(lineItemCollection.Any()); }
/// <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 }); }
public void Can_Deserialize_A_LineItemCollection_From_ExtendedDataCollection() { //// Arrange var extendedData = new ExtendedDataCollection(); extendedData.AddLineItemCollection(_shipment.Items); Console.Write(extendedData.GetValue(Constants.ExtendedDataKeys.LineItemCollection)); //// Act var lineItemCollection = extendedData.GetLineItemCollection<ItemCacheLineItem>(); //// Assert Assert.NotNull(lineItemCollection); Assert.IsTrue(lineItemCollection.Any()); }