public void AddToCollection() { var newOrder = Order.NewObject(); _customerEndPoint.Collection.Add(newOrder); Assert.That(_customerEndPoint.Collection, Is.EqualTo(new[] { _order1, _order2, newOrder }), "changes go down to actual data store"); Assert.That(newOrder.Customer, Is.SameAs(_customerEndPoint.GetDomainObject()), "bidirectional modification"); }
public void ExpandToAllRelatedObjects() { Assert.That(_order1.Customer, Is.SameAs(CollectionEndPoint.GetDomainObject())); Assert.That(_order2.Customer, Is.SameAs(CollectionEndPoint.GetDomainObject())); var customer3 = DomainObjectIDs.Customer3.GetObject <Customer> (Transaction); Assert.That(_order3.Customer, Is.SameAs(customer3)); var bidirectionalModification = _command.ExpandToAllRelatedObjects(); // DomainObject.Orders = _newCollection var steps = bidirectionalModification.GetNestedCommands(); Assert.That(steps.Count, Is.EqualTo(4)); // order2.Customer = null; // order3.Customer.Orders.Remove (order3); // order3.Customer = DomainObject; // DomainObject.Orders = _newCollection // order2.Customer = null; Assert.That(steps[0], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrder5CustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[0]).DecoratedCommand); Assert.That(setOrder5CustomerCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Order).FullName + ".Customer")); Assert.That(setOrder5CustomerCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(_order2.ID)); Assert.That(setOrder5CustomerCommand.OldRelatedObject, Is.SameAs(DomainObject)); Assert.That(setOrder5CustomerCommand.NewRelatedObject, Is.Null); // order3.Customer.Orders.Remove (order3); Assert.That(steps[1], Is.TypeOf <VirtualEndPointStateUpdatedRaisingCommandDecorator> ()); var order2CustomerOrdersRemoveCommand = ((CollectionEndPointRemoveCommand)((VirtualEndPointStateUpdatedRaisingCommandDecorator)steps[1]).DecoratedCommand); Assert.That(order2CustomerOrdersRemoveCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Customer).FullName + ".Orders")); Assert.That(order2CustomerOrdersRemoveCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(customer3.ID)); Assert.That(order2CustomerOrdersRemoveCommand.OldRelatedObject, Is.SameAs(_order3)); Assert.That(order2CustomerOrdersRemoveCommand.NewRelatedObject, Is.Null); // order3.Customer = DomainObject Assert.That(steps[2], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrder2CustomerCommand = ((ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[2]).DecoratedCommand); Assert.That(setOrder2CustomerCommand.ModifiedEndPoint.ID.Definition.PropertyName, Is.EqualTo(typeof(Order).FullName + ".Customer")); Assert.That(setOrder2CustomerCommand.ModifiedEndPoint.ID.ObjectID, Is.EqualTo(_order3.ID)); Assert.That(setOrder2CustomerCommand.OldRelatedObject, Is.SameAs(customer3)); Assert.That(setOrder2CustomerCommand.NewRelatedObject, Is.SameAs(DomainObject)); // DomainObject.Orders = _newCollection Assert.That(steps[3], Is.SameAs(_command)); }