示例#1
0
        public void CreateUnloadVirtualEndPointsCommand()
        {
            var endPointID1 = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");
            var endPointID2 = RelationEndPointID.Create(DomainObjectIDs.Order3, typeof(Order), "OrderItems");

            var endPointStub1 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub1.Stub(stub => stub.ID).Return(endPointID1);
            endPointStub1.Stub(stub => stub.CanBeMarkedIncomplete).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub1);

            var endPointStub2 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub2.Stub(stub => stub.ID).Return(endPointID2);
            endPointStub2.Stub(stub => stub.CanBeMarkedIncomplete).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub2);

            var result = _relationEndPointManager.CreateUnloadVirtualEndPointsCommand(new[] { endPointID1, endPointID2 });

            Assert.That(
                result,
                Is.TypeOf <UnloadVirtualEndPointsCommand>()
                .With.Property("VirtualEndPoints").EqualTo(new[] { endPointStub1, endPointStub2 })
                .And.Property("RelationEndPointMap").SameAs(_relationEndPointManager.RelationEndPoints)
                .And.Property("RegistrationAgent").SameAs(_relationEndPointManager.RegistrationAgent));
        }
示例#2
0
        public void CreateUnregisterCommandForDataContainer_WithMultipleUnregisterableEndPoints()
        {
            var dataContainer = DataContainer.CreateNew(DomainObjectIDs.Order1);
            var endPoint1     = MockRepository.GenerateStub <IVirtualObjectEndPoint> ();

            endPoint1.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "OrderTicket"));
            endPoint1.Stub(stub => stub.Definition).Return(endPoint1.ID.Definition);
            endPoint1.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.OrderTicket1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint1);

            var endPoint2 = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            endPoint2.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "Customer"));
            endPoint2.Stub(stub => stub.Definition).Return(endPoint2.ID.Definition);
            endPoint2.Stub(stub => stub.OriginalOppositeObjectID).Return(DomainObjectIDs.Customer1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint2);

            var command = _relationEndPointManager.CreateUnregisterCommandForDataContainer(dataContainer);

            Assert.That(command, Is.TypeOf <ExceptionCommand> ());
            Assert.That(
                ((ExceptionCommand)command).Exception.Message,
                Is.EqualTo(
                    "The relations of object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' cannot be unloaded.\r\n"
                    + "Relation end-point "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket' "
                    + "would leave a dangling reference.\r\n"
                    + "Relation end-point "
                    + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' "
                    + "would leave a dangling reference."));
        }
示例#3
0
        public void CreateUnregisterCommandForDataContainer_WithUnregisterableEndPoint_DueToChangedOpposite()
        {
            var dataContainer = DataContainer.CreateForExisting(DomainObjectIDs.Order1, null, pd => pd.DefaultValue);
            var endPoint      = MockRepository.GenerateStub <IRealObjectEndPoint> ();

            endPoint.Stub(stub => stub.ID).Return(RelationEndPointID.Create(dataContainer.ID, typeof(Order), "Customer"));
            endPoint.Stub(stub => stub.Definition).Return(endPoint.ID.Definition);
            endPoint.Stub(stub => stub.HasChanged).Return(false);
            endPoint.Stub(stub => stub.OppositeObjectID).Return(DomainObjectIDs.Customer1);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPoint);

            var oppositeEndPoint = MockRepository.GenerateStub <IVirtualEndPoint> ();

            oppositeEndPoint.Stub(stub => stub.ID).Return(RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders"));
            oppositeEndPoint.Stub(stub => stub.Definition).Return(oppositeEndPoint.ID.Definition);
            oppositeEndPoint.Stub(stub => stub.HasChanged).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, oppositeEndPoint);

            var command = _relationEndPointManager.CreateUnregisterCommandForDataContainer(dataContainer);

            Assert.That(command, Is.TypeOf <ExceptionCommand> ());
            Assert.That(((ExceptionCommand)command).Exception, Is.TypeOf <InvalidOperationException> ());
            Assert.That(((ExceptionCommand)command).Exception.Message, Is.EqualTo(
                            "The relations of object 'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid' cannot be unloaded.\r\n"
                            + "The opposite relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.Customer.Orders' of relation end-point "
                            + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.Customer' has changed. "
                            + "Non-virtual end-points that are part of changed relations cannot be unloaded."));
        }
示例#4
0
        public void CreateUnregisterCommandForDataContainer_Existing_IncludesRealObjectEndPoints_IgnoresVirtualEndPoints()
        {
            var realEndPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "Customer");
            var dataContainer  = RelationEndPointTestHelper.CreateExistingForeignKeyDataContainer(realEndPointID, DomainObjectIDs.Order3);

            _relationEndPointManager.RegisterEndPointsForDataContainer(dataContainer);
            var realEndPoint = _relationEndPointManager.RelationEndPoints[realEndPointID];

            var virtualObjectEndPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderItems");
            var virtualObjectEndPointStub = MockRepository.GenerateStub <IVirtualObjectEndPoint> ();

            virtualObjectEndPointStub.Stub(stub => stub.ID).Return(virtualObjectEndPointID);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, virtualObjectEndPointStub);

            var collectionEndPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");
            var collectionEndPointStub = MockRepository.GenerateStub <ICollectionEndPoint> ();

            collectionEndPointStub.Stub(stub => stub.ID).Return(collectionEndPointID);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, collectionEndPointStub);

            var command = _relationEndPointManager.CreateUnregisterCommandForDataContainer(dataContainer);

            Assert.That(command, Is.TypeOf <UnregisterEndPointsCommand> ());
            Assert.That(((UnregisterEndPointsCommand)command).RegistrationAgent, Is.SameAs(_relationEndPointManager.RegistrationAgent));
            Assert.That(((UnregisterEndPointsCommand)command).Map, Is.SameAs(_relationEndPointManager.RelationEndPoints));
            Assert.That(((UnregisterEndPointsCommand)command).EndPoints, Has.Member(realEndPoint));
            Assert.That(((UnregisterEndPointsCommand)command).EndPoints, Has.No.Member(virtualObjectEndPointStub));
            Assert.That(((UnregisterEndPointsCommand)command).EndPoints, Has.No.Member(collectionEndPointStub));
        }
示例#5
0
        public void GetRelationEndPointWithoutLoading_EndPointRegistered()
        {
            var endPointID   = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");
            var endPointStub = MockRepository.GenerateStub <IRelationEndPoint> ();

            endPointStub.Stub(stub => stub.ID).Return(endPointID);

            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub);

            var result = _relationEndPointManager.GetRelationEndPointWithoutLoading(endPointID);

            Assert.That(result, Is.SameAs(endPointStub));
        }
示例#6
0
        public void Reset_RaisesUnregisteringEvents()
        {
            var endPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");
            var endPointStub = MockRepository.GenerateStub <IRelationEndPoint> ();

            endPointStub.Stub(stub => stub.ID).Return(endPointID);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub);

            var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(_relationEndPointManager.ClientTransaction);

            _relationEndPointManager.Reset();

            listenerMock.AssertWasCalled(mock => mock.RelationEndPointMapUnregistering(_relationEndPointManager.ClientTransaction, endPointID));
        }
示例#7
0
        public void RollbackAllEndPoints_RollsbackEndPoints()
        {
            RelationEndPointID endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");
            var endPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            endPointMock.Stub(stub => stub.ID).Return(endPointID);
            endPointMock.Expect(mock => mock.Rollback());
            endPointMock.Replay();

            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointMock);

            _relationEndPointManager.RollbackAllEndPoints();

            endPointMock.VerifyAllExpectations();
        }
示例#8
0
        public void Reset_RemovesEndPoints()
        {
            var endPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Customer1, "Orders");
            var endPointMock = MockRepository.GenerateStrictMock <IRelationEndPoint> ();

            endPointMock.Stub(stub => stub.ID).Return(endPointID);
            endPointMock.Expect(mock => mock.Rollback());
            endPointMock.Replay();
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointMock);
            Assert.That(_relationEndPointManager.RelationEndPoints, Is.Not.Empty.And.Member(endPointMock));

            _relationEndPointManager.Reset();

            endPointMock.VerifyAllExpectations();
            Assert.That(_relationEndPointManager.RelationEndPoints, Is.Empty);
        }
示例#9
0
        public void GetOrCreateVirtualEndPoint_AlreadyAvailable()
        {
            var endPointID   = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");
            var endPointMock = MockRepository.GenerateStrictMock <IVirtualEndPoint> ();

            endPointMock.Stub(stub => stub.ID).Return(endPointID);
            endPointMock.Expect(mock => mock.EnsureDataComplete());
            endPointMock.Replay();

            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointMock);

            Assert.That(_relationEndPointManager.RelationEndPoints[endPointID], Is.SameAs(endPointMock));

            var result = _relationEndPointManager.GetOrCreateVirtualEndPoint(endPointID);

            Assert.That(result, Is.SameAs(endPointMock));
            Assert.That(_relationEndPointManager.RelationEndPoints[endPointID], Is.SameAs(endPointMock));
        }
示例#10
0
        public void CreateUnloadVirtualEndPointsCommand_NonUnloadableEndPoints()
        {
            var endPointID1 = RelationEndPointID.Create(DomainObjectIDs.Order1, typeof(Order), "OrderItems");
            var endPointID2 = RelationEndPointID.Create(DomainObjectIDs.Order3, typeof(Order), "OrderItems");
            var endPointID3 = RelationEndPointID.Create(DomainObjectIDs.Order4, typeof(Order), "OrderItems");

            var endPointStub1 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub1.Stub(stub => stub.ID).Return(endPointID1);
            endPointStub1.Stub(stub => stub.CanBeMarkedIncomplete).Return(false);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub1);

            var endPointStub2 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub2.Stub(stub => stub.ID).Return(endPointID2);
            endPointStub2.Stub(stub => stub.CanBeMarkedIncomplete).Return(false);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub2);

            var endPointStub3 = MockRepository.GenerateStub <IVirtualEndPoint> ();

            endPointStub3.Stub(stub => stub.ID).Return(endPointID3);
            endPointStub3.Stub(stub => stub.CanBeMarkedIncomplete).Return(true);
            RelationEndPointManagerTestHelper.AddEndPoint(_relationEndPointManager, endPointStub3);

            var result = _relationEndPointManager.CreateUnloadVirtualEndPointsCommand(new[] { endPointID1, endPointID2, endPointID3 });

            Assert.That(result, Is.TypeOf <CompositeCommand> ());
            var exceptionCommands = ((CompositeCommand)result).GetNestedCommands();

            Assert.That(exceptionCommands[0], Is.TypeOf <ExceptionCommand>());
            Assert.That(((ExceptionCommand)exceptionCommands[0]).Exception, Is.TypeOf <InvalidOperationException>().With.Message.EqualTo(
                            "The end point with ID "
                            + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems' "
                            + "has been changed. Changed end points cannot be unloaded."));
            Assert.That(exceptionCommands[1], Is.TypeOf <ExceptionCommand> ());
            Assert.That(((ExceptionCommand)exceptionCommands[1]).Exception, Is.TypeOf <InvalidOperationException> ().With.Message.EqualTo(
                            "The end point with ID "
                            + "'Order|83445473-844a-4d3f-a8c3-c27f8d98e8ba|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems' "
                            + "has been changed. Changed end points cannot be unloaded."));
        }