/// <summary> /// Creates a <see cref="IShipment"/> without persisting it to the database. /// </summary> /// <param name="shipmentStatus"> /// The shipment status. /// </param> /// <param name="origin"> /// The origin. /// </param> /// <param name="destination"> /// The destination. /// </param> /// <param name="items"> /// The items. /// </param> /// <param name="raiseEvents"> /// Optional boolean indicating whether or not to raise events /// </param> /// <returns> /// The <see cref="IShipment"/>. /// </returns> public IShipment CreateShipment(IShipmentStatus shipmentStatus, IAddress origin, IAddress destination, LineItemCollection items, bool raiseEvents = true) { Mandate.ParameterNotNull(shipmentStatus, "shipmentStatus"); Mandate.ParameterNotNull(origin, "origin"); Mandate.ParameterNotNull(destination, "destination"); Mandate.ParameterNotNull(items, "items"); // Use the visitor to filter out and validate shippable line items var visitor = new ShippableProductVisitor(); items.Accept(visitor); var lineItemCollection = new LineItemCollection(); foreach (var item in visitor.ShippableItems) { lineItemCollection.Add(item); } var shipment = new Shipment(shipmentStatus, origin, destination, lineItemCollection) { VersionKey = Guid.NewGuid() }; if (!raiseEvents) { return(shipment); } Creating.RaiseEvent(new Events.NewEventArgs <IShipment>(shipment), this); return(shipment); }
public void ShippableProductVisitor_Returns_Only_Shippable_Products() { //// Arrange const int expected = 4; var visitor = new ShippableProductVisitor(); //// Act _basket.Accept(visitor); //// Assert Assert.AreEqual(expected, visitor.ShippableItems.Count()); }
public void ShippableProductVisitor_Returns_Only_Shippable_Products() { //// Arrange var notShippable = PreTestDataWorker.MakeExistingProduct(false); _basket.AddItem(notShippable); const int expected = 4; var visitor = new ShippableProductVisitor(); //// Act _basket.Accept(visitor); //// Assert Assert.AreEqual(expected, visitor.ShippableItems.Count()); }