public void CommitSavesRelatedObjectsToParentTransaction() { Order order = Order.NewObject(); Official official = DomainObjectIDs.Official1.GetObject <Official>(); order.Official = official; order.Customer = DomainObjectIDs.Customer1.GetObject <Customer> (); OrderItem orderItem = OrderItem.NewObject(); order.OrderItems.Add(orderItem); Assert.That(order.Official, Is.SameAs(official)); Assert.That(order.OrderItems.Count, Is.EqualTo(1)); Assert.That(order.OrderItems.ContainsObject(orderItem), Is.True); Assert.That(order.OrderTicket, Is.Null); OrderItem newOrderItem; OrderTicket newOrderTicket; using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { newOrderItem = OrderItem.NewObject(); orderItem.Delete(); order.OrderItems.Add(newOrderItem); order.OrderItems.Add(OrderItem.NewObject()); newOrderTicket = OrderTicket.NewObject(); order.OrderTicket = newOrderTicket; Assert.That(order.Official, Is.SameAs(official)); Assert.That(order.OrderItems.Count, Is.EqualTo(2)); Assert.That(order.OrderItems.ContainsObject(orderItem), Is.False); Assert.That(order.OrderItems.ContainsObject(newOrderItem), Is.True); Assert.That(order.OrderTicket, Is.Not.Null); Assert.That(order.OrderTicket, Is.SameAs(newOrderTicket)); ClientTransactionScope.CurrentTransaction.Commit(); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); Assert.That(order.Official, Is.SameAs(official)); Assert.That(order.OrderItems.Count, Is.EqualTo(2)); Assert.That(order.OrderItems.ContainsObject(orderItem), Is.False); Assert.That(order.OrderItems.ContainsObject(newOrderItem), Is.True); Assert.That(order.OrderTicket, Is.Not.Null); Assert.That(order.OrderTicket, Is.SameAs(newOrderTicket)); } Assert.That(order.Official, Is.SameAs(official)); Assert.That(order.OrderItems.Count, Is.EqualTo(2)); Assert.That(order.OrderItems.ContainsObject(orderItem), Is.False); Assert.That(order.OrderItems.ContainsObject(newOrderItem), Is.True); Assert.That(order.OrderTicket, Is.Not.Null); Assert.That(order.OrderTicket, Is.SameAs(newOrderTicket)); }
public void Remove(int id) { OrderItem oi = OrderItem.SingleOrDefault(e => e.id == id); if (oi != null) { oi.Delete(); } }
public void DeleteOrderItemEvents() { _orderItem.Delete(); ChangeState[] expectedStates = new ChangeState[] { new ObjectDeletionState(_orderItem, "1. Deleting event of orderItem"), new CollectionChangeState(_order.OrderItems, _orderItem, "2. Removing event of order.OrderItems"), new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems", _orderItem, null, "3. Relation changing event of order"), new RelationChangeState(_order, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems", null, null, "4. Relation changed event of order"), new CollectionChangeState(_order.OrderItems, _orderItem, "5. Removed event of order.OrderItems"), new ObjectDeletionState(_orderItem, "6. Deleted event of orderItem"), }; _eventReceiver.Check(expectedStates); }
/// <summary> /// Delete an OrderItem /// </summary> /// <param name="ID"></param> /// <returns></returns> public Task <bool> DeleteOrderItemAsync(int ID) { return(Task.Run(async() => { OrderItem orderItem = OrderItem.ExecuteCreate(ID); orderItem.Delete(); await UpdateTotalOfOrder(orderItem.OrderID); orderItem = OrderItem.ExecuteCreate(ID); return (orderItem == null) ? true : false; })); }
public void DeleteTest() { OrderItemList orderItems = new OrderItemList(); orderItems.LoadByOrderId(-99); //Find the order with the description testingorder OrderItem orderItem = orderItems.FirstOrDefault(f => f.Quantity == -98); //Delete it int result = orderItem.Delete(); Assert.IsTrue(result == 1); }
public void DomainObjectWithManyToOneRelation() { OrderItem orderItem = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); orderItem.Delete(); Order order = DomainObjectIDs.Order1.GetObject <Order> (); Assert.That(orderItem.Order, Is.Null); Assert.That(order.OrderItems.Count, Is.EqualTo(1)); Assert.That(order.OrderItems.Contains(orderItem.ID), Is.False); Assert.That(orderItem.Properties[typeof(OrderItem), "Order"].GetRelatedObjectID(), Is.Null); Assert.That(order.State, Is.EqualTo(StateType.Changed)); Assert.That(order.InternalDataContainer.State, Is.EqualTo(StateType.Unchanged)); }
public void SubTransactionCanGetRelatedObjectCollectionEvenWhenObjectsHaveBeenDiscarded() { Order loadedOrder = DomainObjectIDs.Order1.GetObject <Order> (); using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { OrderItem orderItem1 = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); orderItem1.Delete(); ClientTransactionScope.CurrentTransaction.Commit(); Assert.That(orderItem1.State, Is.EqualTo(StateType.Invalid)); ObjectList <OrderItem> orderItems = loadedOrder.OrderItems; Assert.That(orderItems.Count, Is.EqualTo(1)); Assert.That(orderItems[0].ID, Is.EqualTo(DomainObjectIDs.OrderItem2)); } }
public void CascadedDeleteForNewObjects() { Order newOrder = Order.NewObject(); OrderTicket newOrderTicket = OrderTicket.NewObject(newOrder); Assert.That(newOrder.OrderTicket, Is.SameAs(newOrderTicket)); OrderItem newOrderItem = OrderItem.NewObject(newOrder); Assert.That(newOrder.OrderItems, Has.Member(newOrderItem)); newOrder.Deleted += delegate { newOrderTicket.Delete(); newOrderItem.Delete(); }; newOrder.Delete(); //Expectation: no exception Assert.That(newOrder.State, Is.EqualTo(StateType.Invalid)); Assert.That(newOrderTicket.State, Is.EqualTo(StateType.Invalid)); Assert.That(newOrderItem.State, Is.EqualTo(StateType.Invalid)); }