Beispiel #1
0
 public virtual void AddItem(OrderItem newItem)
 {
     if (newItem != null && !_items.Contains(newItem))
       {
     _items.Add(newItem);
     newItem.SetOrder(this);
       }
 }
 public void SetOrder_instance_adds_to_Order_Items()
 {
     var order = new Order();
       var item = new OrderItem();
       item.SetOrder(order);
       Assert.AreSame(order, item.Order);
       Assert.That(order.Items.Contains(item));
       Assert.AreEqual(1, order.Items.Count());
 }
 public void RemoveItem_sets_Item_Order_null()
 {
     var order = new Order();
       var item = new OrderItem();
       order.AddItem(item);
       order.RemoveItem(item);
       Assert.IsNull(item.Order);
       Assert.False(order.Items.Any());
 }
        public void AddItem_sets_Item_Order()
        {
            var order = new Order();
              var item = new OrderItem();

              order.AddItem(item);

              Assert.AreSame(order, item.Order);
              Assert.That(order.Items.Contains(item));
              Assert.AreEqual(1, order.Items.Count());
        }
        public void SetOrder_can_switch_orders()
        {
            var order1 = new Order();
              var order2 = new Order();
              var item = new OrderItem();
              order1.AddItem(item);
              Assert.AreSame(order1, item.Order);
              Assert.True(order1.Items.Contains(item));
              Assert.False(order2.Items.Any());

              item.SetOrder(order2);

              Assert.AreSame(order2, item.Order);
              Assert.True(order2.Items.Contains(item));
              Assert.AreEqual(1, order2.Items.Count());
              Assert.False(order1.Items.Any());
        }
Beispiel #6
0
        public void Order_cascades_to_OrderItem()
        {
            var order = new Order();
              var item = new OrderItem();
              order.AddItem(item);

              using (var tx = Session.BeginTransaction())
              {
            Session.Save(order);
            tx.Commit();
              }

              Session.Clear();

              using (var tx = Session.BeginTransaction())
              {
            order = Session.Get<Order>(order.Id);
            tx.Commit();
              }

              Assert.True(order.Items.Count() == 1);
        }
Beispiel #7
0
 public virtual void RemoveItem(OrderItem itemToRemove)
 {
     if (itemToRemove != null && _items.Remove(itemToRemove))
     itemToRemove.SetOrder(null);
 }
        public void SetOrder_null_removes_from_order_Items()
        {
            var order = new Order();
              var item = new OrderItem();
              item.SetOrder(order);
              item.SetOrder(null);

              Assert.IsNull(item.Order);
              Assert.False(order.Items.Any());
        }