public override void SetUp() { base.SetUp(); _owningOrder = DomainObjectIDs.Order1.GetObject <Order> (); _endPointID = RelationEndPointID.Resolve(_owningOrder, o => o.OrderItems); _collectionEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint>(); StubCollectionEndPoint(_collectionEndPointMock, TestableClientTransaction, _owningOrder); _virtualEndPointProviderStub = MockRepository.GenerateStub <IVirtualEndPointProvider> (); _virtualEndPointProviderStub .Stub(stub => stub.GetOrCreateVirtualEndPoint(_endPointID)) .Return(_collectionEndPointMock); _endPointDataStub = MockRepository.GenerateStub <IDomainObjectCollectionData>(); _endPointDataDecorator = new ReadOnlyCollectionDataDecorator(_endPointDataStub); _commandStub = MockRepository.GenerateStub <IDataManagementCommand>(); _nestedCommandMock = MockRepository.GenerateMock <IDataManagementCommand> (); _nestedCommandMock.Stub(stub => stub.GetAllExceptions()).Return(new Exception[0]); _expandedCommandFake = new ExpandedCommand(_nestedCommandMock); _delegatingData = new EndPointDelegatingCollectionData(_endPointID, _virtualEndPointProviderStub); _orderItem1 = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); _orderItem2 = DomainObjectIDs.OrderItem2.GetObject <OrderItem>(); ClientTransactionScope.EnterNullScope(); // no active transaction }
public void ExpandToAllRelatedObjects() { var fakeExpandedCommand = new ExpandedCommand(); _decoratedCommandMock .Stub(stub => stub.ExpandToAllRelatedObjects()) .Return(fakeExpandedCommand); _mockRepository.ReplayAll(); var result = _decorator.ExpandToAllRelatedObjects(); Assert.That(result, Is.Not.Null); var nestedCommands = result.GetNestedCommands(); Assert.That(nestedCommands.Count, Is.EqualTo(1)); Assert.That(nestedCommands[0], Is.TypeOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var innerExpandedCommand = (RealObjectEndPointRegistrationCommandDecorator)nestedCommands[0]; Assert.That(innerExpandedCommand.DecoratedCommand, Is.SameAs(fakeExpandedCommand)); Assert.That(innerExpandedCommand.RealObjectEndPoint, Is.SameAs(_realObjectEndPointStub)); Assert.That(innerExpandedCommand.OldRelatedEndPoint, Is.SameAs(_oldRelatedEndPointMock)); Assert.That(innerExpandedCommand.NewRelatedEndPoint, Is.SameAs(_newRelatedEndPointMock)); }
private void ExpandedItemCallback(object sender, RoutedEventArgs e) { var item = e.OriginalSource as TreeViewItem; if (ExpandedCommand != null && item != null && ExpandedCommand.CanExecute(item.DataContext)) { ExpandedCommand.Execute(item.DataContext); } }
/// <summary> /// Creates all commands needed to perform a bidirectional 1:n set operation on this <see cref="ObjectEndPoint"/>. One of the steps is /// this command, the other steps are the opposite commands on the new/old related objects. /// </summary> /// <remarks> /// A 1:n set operation of the form "order.Customer = newCustomer" needs three steps: /// <list type="bullet"> /// <item>order.Customer = newCustomer,</item> /// <item>newCustomer.Orders.Add (order), and</item> /// <item>oldCustomer.Orders.Remove (order).</item> /// </list> /// </remarks> public override ExpandedCommand ExpandToAllRelatedObjects() { var newRelatedEndPoint = (ICollectionEndPoint)GetOppositeEndPoint(ModifiedEndPoint, NewRelatedObject, _endPointProvider); var oldRelatedEndPoint = (ICollectionEndPoint)GetOppositeEndPoint(ModifiedEndPoint, OldRelatedObject, _endPointProvider); var bidirectionalModification = new ExpandedCommand( // => order.Customer = newCustomer this, // => newCustomer.Orders.Add (order) newRelatedEndPoint.CreateAddCommand(ModifiedEndPoint.GetDomainObject()), // => oldCustomer.Orders.Remove (order) (remove) oldRelatedEndPoint.CreateRemoveCommand(ModifiedEndPoint.GetDomainObject())); return(bidirectionalModification); }
public void ExpandToAllRelatedObjects() { var fakeExpanded = new ExpandedCommand(); _decoratedCommandMock.Stub(stub => stub.ExpandToAllRelatedObjects()).Return(fakeExpanded); var result = _decorator.ExpandToAllRelatedObjects(); var nestedCommands = result.GetNestedCommands(); Assert.That(nestedCommands, Has.Count.EqualTo(1)); var nestedCommand = nestedCommands.Single(); Assert.That(nestedCommand, Is.TypeOf <TestableDataManagementCommandDecoratorBase> ()); Assert.That(((TestableDataManagementCommandDecoratorBase)nestedCommand).DecoratedCommand, Is.SameAs(fakeExpanded)); }
public void ExpandToAllRelatedObjects() { var fakeExpandedCommand = new ExpandedCommand(); _decoratedCommandMock.Expect(mock => mock.ExpandToAllRelatedObjects()).Return(fakeExpandedCommand); _decoratedCommandMock.Replay(); var result = _commandDecorator.ExpandToAllRelatedObjects(); _decoratedCommandMock.VerifyAllExpectations(); var nestedCommands = result.GetNestedCommands(); Assert.That(nestedCommands.Count, Is.EqualTo(1)); Assert.That(nestedCommands[0], Is.TypeOf(typeof(VirtualEndPointStateUpdatedRaisingCommandDecorator))); var innerExpandedCommand = (VirtualEndPointStateUpdatedRaisingCommandDecorator)nestedCommands[0]; Assert.That(innerExpandedCommand.DecoratedCommand, Is.SameAs(fakeExpandedCommand)); Assert.That(innerExpandedCommand.ModifiedEndPointID, Is.EqualTo(_modifiedEndPointID)); Assert.That(innerExpandedCommand.Listener, Is.SameAs(_stateUpdateListenerMock)); Assert.That(innerExpandedCommand.ChangeStateProvider, Is.SameAs(_commandDecorator.ChangeStateProvider)); }