static void Main(string[] args) { var carOrder = new Order(); var carItem = new OrderItem("Audi B4"); var alternativeCarItem = new OrderItem("Mitsubishi Lancer"); var orderItemProcessor = new OrderItemProcessor(); //return multiple results from function using out carOrder.addOrderItem(carItem); int carItemCount; var orderItems = carOrder.getOrderItems(out carItemCount); Console.WriteLine($"Order item count is {carItemCount}", carItemCount); //swap two OrderItem instances using ref printCarTitles("Before swap:", carItem.Title, alternativeCarItem.Title); orderItemProcessor.swapOrderItems(ref carItem, ref alternativeCarItem); printCarTitles("After swap:", carItem.Title, alternativeCarItem.Title); //duplicateOrderItem receives a copy of object reference. original object does not change var duplicateCarItem = orderItemProcessor.duplicateOrderItem(carItem); var isSameObject = carItem.Equals(duplicateCarItem); printCarComparisonResut(isSameObject, carItem.Title, duplicateCarItem.Title); }
public void duplicatesOrderItems() { var carItem = new OrderItem("Audi B4"); var orderItemProcessor = new OrderItemProcessor(); var duplicateCarItem = orderItemProcessor.duplicateOrderItem(carItem); Assert.AreNotEqual(carItem, duplicateCarItem); }
public void swapsOrderItems() { var carItem = new OrderItem("Audi B4"); var alternativeCarItem = new OrderItem("Mitsubishi Lancer"); var orderItemProcessor = new OrderItemProcessor(); orderItemProcessor.swapOrderItems(ref carItem, ref alternativeCarItem); Assert.AreEqual("Mitsubishi Lancer", carItem.Title); Assert.AreEqual("Audi B4", alternativeCarItem.Title); }
public void addOrderItems() { var order = new Order(); var orderItem = new OrderItem("Volvo XC90"); var anotherOrderItem = new OrderItem("Mazda 6"); order.addOrderItem(orderItem); order.addOrderItem(anotherOrderItem); int itemCount; var items = order.getOrderItems(out itemCount); Assert.AreEqual(2, itemCount); }
public void swapOrderItems(ref OrderItem item, ref OrderItem alternativeItem) { var temp = item; item = alternativeItem; alternativeItem = temp; }
public OrderItem duplicateOrderItem(OrderItem item) { var title = item.Title; item = new OrderItem("new " + title); return item; }
public void addOrderItem(OrderItem item) { orderItems.Add(item); }