Example #1
0
        public void GroupAndRegisterRelatedObjects_PropertyOnDerivedType()
        {
            var endPointDefinition = GetEndPointDefinition(typeof(Customer), "ContactPerson");

            var originatingCustomer     = DomainObjectMother.CreateFakeObject <Customer>();
            var originatingCustomerData = LoadedObjectDataObjectMother.CreateLoadedObjectDataStub(originatingCustomer);

            var originatingCompany     = DomainObjectMother.CreateFakeObject <Company>();
            var originatingCompanyData = LoadedObjectDataObjectMother.CreateLoadedObjectDataStub(originatingCompany);

            var originatingSupplier     = DomainObjectMother.CreateFakeObject <Supplier>();
            var originatingSupplierData = LoadedObjectDataObjectMother.CreateLoadedObjectDataStub(originatingSupplier);

            var fetchedPerson     = DomainObjectMother.CreateFakeObject <Person>();
            var fetchedPersonData = LoadedObjectDataObjectMother.CreateLoadedObjectDataWithDataSourceData(fetchedPerson);

            fetchedPersonData.DataSourceData.SetValue(GetPropertyDefinition(typeof(Person), "AssociatedCustomerCompany"), originatingCustomer.ID);

            _loadedDataContainerProviderStub.Stub(stub => stub.GetDataContainerWithoutLoading(fetchedPerson.ID)).Return(fetchedPersonData.DataSourceData);

            var endPointMock = MockRepository.GenerateStrictMock <IVirtualObjectEndPoint> ();

            ExpectGetEndPoint(originatingCustomer.ID, endPointDefinition, _virtualEndPointProviderMock, endPointMock, false);
            endPointMock.Expect(mock => mock.MarkDataComplete(fetchedPerson));

            _virtualEndPointProviderMock.Replay();
            endPointMock.Replay();

            _agent.GroupAndRegisterRelatedObjects(
                endPointDefinition,
                new[] { originatingCustomerData, originatingCompanyData, originatingSupplierData },
                new[] { fetchedPersonData });

            _virtualEndPointProviderMock.VerifyAllExpectations();
            endPointMock.VerifyAllExpectations();
        }
        public void CreateSetCommand_NotSame()
        {
            _dataManagerMock.Stub(stub => stub.CurrentOppositeObject).Return(_relatedObject);
            _dataManagerMock.Stub(stub => stub.OriginalItemWithoutEndPoint).Return(null);
            _dataManagerMock.Replay();

            _virtualObjectEndPointMock.Stub(mock => mock.GetDomainObject()).Return(_owningObject);
            _virtualObjectEndPointMock.Stub(mock => mock.GetOppositeObject()).Return(_relatedObject);
            _virtualObjectEndPointMock.Stub(mock => mock.IsNull).Return(false);
            _virtualObjectEndPointMock.Stub(mock => mock.Definition).Return(_definition);
            _virtualObjectEndPointMock.Replay();

            var newRelatedObject = DomainObjectMother.CreateFakeObject <OrderTicket> ();

            var command = (RelationEndPointModificationCommand)_loadState.CreateSetCommand(_virtualObjectEndPointMock, newRelatedObject);

            Assert.That(command, Is.TypeOf(typeof(ObjectEndPointSetOneOneCommand)));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_virtualObjectEndPointMock));
            Assert.That(command.NewRelatedObject, Is.SameAs(newRelatedObject));
            Assert.That(command.OldRelatedObject, Is.SameAs(_relatedObject));
            Assert.That(command.TransactionEventSink, Is.SameAs(_transactionEventSinkStub));

            CheckOppositeObjectIDSetter((ObjectEndPointSetCommand)command);
        }
Example #3
0
        public override void SetUp()
        {
            base.SetUp();

            _endPointID             = RelationEndPointID.Create(DomainObjectIDs.Customer1, typeof(Customer), "Orders");
            _collectionEndPointMock = MockRepository.GenerateStrictMock <ICollectionEndPoint> ();

            _endPointLoaderMock     = MockRepository.GenerateStrictMock <IncompleteCollectionEndPointLoadState.IEndPointLoader> ();
            _dataManagerFactoryStub = MockRepository.GenerateStub <ICollectionEndPointDataManagerFactory> ();

            var dataManagerStub = MockRepository.GenerateStub <ICollectionEndPointDataManager> ();

            dataManagerStub.Stub(stub => stub.HasDataChanged()).Return(false);

            _loadState = new IncompleteCollectionEndPointLoadState(_endPointLoaderMock, _dataManagerFactoryStub);

            _relatedObject       = DomainObjectMother.CreateFakeObject <Order> ();
            _relatedEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _relatedEndPointStub.Stub(stub => stub.ObjectID).Return(_relatedObject.ID);

            _relatedObject2       = DomainObjectMother.CreateFakeObject <Order> ();
            _relatedEndPointStub2 = MockRepository.GenerateStub <IRealObjectEndPoint> ();
            _relatedEndPointStub2.Stub(stub => stub.ObjectID).Return(_relatedObject2.ID);
        }
        public override void SetUp()
        {
            base.SetUp();

            _endPointID = RelationEndPointObjectMother.CreateRelationEndPointID(DomainObjectIDs.Order1, "OrderTicket");

            _lazyLoaderMock           = MockRepository.GenerateStrictMock <ILazyLoader>();
            _endPointProviderStub     = MockRepository.GenerateStub <IRelationEndPointProvider> ();
            _transactionEventSinkStub = MockRepository.GenerateStub <IClientTransactionEventSink>();
            _dataManagerFactory       = new VirtualObjectEndPointDataManagerFactory();
            _loadStateMock            = MockRepository.GenerateStrictMock <IVirtualObjectEndPointLoadState> ();

            _endPoint = new VirtualObjectEndPoint(
                ClientTransaction.Current,
                _endPointID,
                _lazyLoaderMock,
                _endPointProviderStub,
                _transactionEventSinkStub,
                _dataManagerFactory);
            PrivateInvoke.SetNonPublicField(_endPoint, "_loadState", _loadStateMock);

            _oppositeEndPointStub = MockRepository.GenerateStub <IRealObjectEndPoint>();
            _oppositeObject       = DomainObjectMother.CreateFakeObject <OrderTicket>();
        }
Example #5
0
        public static PersistableData Create()
        {
            var domainObject = DomainObjectMother.CreateFakeObject <Order>();

            return(new PersistableData(domainObject, StateType.New, DataContainer.CreateNew(domainObject.ID), new IRelationEndPoint[0]));
        }
        public void CreateSetCommand()
        {
            var orderTicket = DomainObjectMother.CreateFakeObject <OrderTicket> ();

            CheckCreateStateUpdateRaisingCommand(ep => ep.CreateSetCommand(orderTicket));
        }
        public void Resolve_Expression_NonExistingProperty()
        {
            var instance = DomainObjectMother.CreateFakeObject <Order> (_objectID);

            RelationEndPointID.Resolve(instance, o => ((OrderItem)(object)o).Product);
        }
Example #8
0
 public static LoadedObjectDataWithDataSourceData CreateLoadedObjectDataWithDataSourceData()
 {
     return(CreateLoadedObjectDataWithDataSourceData(DomainObjectMother.CreateFakeObject <Order>()));
 }
Example #9
0
        private InvalidLoadedObjectData GetInvalidLoadedObject()
        {
            var domainObject = DomainObjectMother.CreateFakeObject <Order> ();

            return(new InvalidLoadedObjectData(domainObject));
        }
        public void CreateSetCommand()
        {
            var relatedObject = DomainObjectMother.CreateFakeObject <OrderTicket> ();

            _state.CreateSetCommand(_endPointStub, relatedObject, domainObject => { });
        }
        public void OnAfterObjectRegistration_ExceptionInEventSink_HierarchyManager_IsStillNotified()
        {
            var loadedObjectIDs             = Array.AsReadOnly(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3 });
            var actuallyLoadedDomainObjects = Array.AsReadOnly(new[] { DomainObjectMother.CreateFakeObject(), DomainObjectMother.CreateFakeObject() });

            var exception = new Exception("Test");

            using (_mockRepository.Ordered())
            {
                _eventSinkWithMock.Expect(mock => mock.RaiseObjectsLoadedEvent(actuallyLoadedDomainObjects))
                .Throw(exception);
                _hierarchyManagerMock.Expect(mock => mock.OnAfterObjectRegistration(loadedObjectIDs));
            }
            _mockRepository.ReplayAll();

            Assert.That(() => _decorator.OnAfterObjectRegistration(loadedObjectIDs, actuallyLoadedDomainObjects), Throws.Exception.SameAs(exception));

            _mockRepository.VerifyAll();
        }
        public void OnAfterObjectRegistration()
        {
            var loadedObjectIDs             = Array.AsReadOnly(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3 });
            var actuallyLoadedDomainObjects = Array.AsReadOnly(new[] { DomainObjectMother.CreateFakeObject(), DomainObjectMother.CreateFakeObject() });

            using (_mockRepository.Ordered())
            {
                _eventSinkWithMock.Expect(mock => mock.RaiseObjectsLoadedEvent(actuallyLoadedDomainObjects));
                _hierarchyManagerMock.Expect(mock => mock.OnAfterObjectRegistration(loadedObjectIDs));
            }
            _mockRepository.ReplayAll();

            _decorator.OnAfterObjectRegistration(loadedObjectIDs, actuallyLoadedDomainObjects);

            _mockRepository.VerifyAll();
        }
        public void UnregisterOriginalItemWithoutEndPoint_InvalidID()
        {
            _dataManager.RegisterOriginalItemWithoutEndPoint(_oppositeObject);

            _dataManager.UnregisterOriginalItemWithoutEndPoint(DomainObjectMother.CreateFakeObject <OrderTicket> (DomainObjectIDs.OrderTicket2));
        }
Example #14
0
 public static QueryResult <T> CreateQueryResult <T> () where T : DomainObject
 {
     return(new QueryResult <T> (QueryObjectMother.Create(), new[] { DomainObjectMother.CreateFakeObject <T>() }));
 }
        public void CreateInsertCommand()
        {
            var orderItem = DomainObjectMother.CreateFakeObject <OrderItem> ();

            CheckCreateStateUpdateRaisingCommand(ep => ep.CreateInsertCommand(orderItem, 0));
        }
Example #16
0
        public void ContainsObject_False_SameID_DifferentReference()
        {
            var customer1InOtherTransaction = DomainObjectMother.GetObjectInOtherTransaction <Customer> (_collection[0].ID);

            Assert.That(_collection.ContainsObject(customer1InOtherTransaction), Is.False);
        }
        public void CreateReplaceCommand()
        {
            var orderItem = DomainObjectMother.CreateFakeObject <OrderItem> ();

            CheckCreateStateUpdateRaisingCommand(ep => ep.CreateReplaceCommand(0, orderItem));
        }
Example #18
0
        public void IndexOf_Object_OtherTransaction()
        {
            var customer1InOtherTransaction = DomainObjectMother.GetObjectInOtherTransaction <Customer> (_collection[0].ID);

            Assert.That(_collection.IndexOf(customer1InOtherTransaction), Is.EqualTo(-1));
        }
Example #19
0
 public static LoadedObjectDataWithDataSourceData CreateLoadedObjectDataWithDataSourceData(ObjectID objectID)
 {
     return(CreateLoadedObjectDataWithDataSourceData(DomainObjectMother.CreateFakeObject(objectID)));
 }
        public void SetEquals_UsesReferenceComparison()
        {
            var order1FromOtherTransaction = DomainObjectMother.GetObjectInOtherTransaction <Order> (_order1.ID);

            Assert.That(_data.SetEquals(new[] { order1FromOtherTransaction, _order2 }), Is.False);
        }
        public void Resolve_Expression_NonRelationProperty()
        {
            var instance = DomainObjectMother.CreateFakeObject <Order> (_objectID);

            RelationEndPointID.Resolve(instance, o => o.OrderNumber);
        }
        public void CreateAddCommand()
        {
            var fakeCollectionData =
                new DomainObjectCollectionData(new[] { DomainObjectMother.CreateFakeObject <Order> (), DomainObjectMother.CreateFakeObject <Order> () });

            _dataManagerMock.Stub(stub => stub.CollectionData).Return(fakeCollectionData);
            _dataManagerMock.Stub(stub => stub.ContainsOriginalItemWithoutEndPoint(_relatedObject)).Return(false);

            var fakeCollection = new DomainObjectCollection();

            _collectionEndPointMock.Stub(mock => mock.IsNull).Return(false);
            _collectionEndPointMock.Stub(mock => mock.Collection).Return(fakeCollection);
            _collectionEndPointMock.Stub(mock => mock.GetDomainObject()).Return(_owningObject);

            var command = (RelationEndPointModificationCommand)_loadState.CreateAddCommand(_collectionEndPointMock, _relatedObject);

            Assert.That(command, Is.InstanceOf(typeof(CollectionEndPointInsertCommand)));
            Assert.That(command.ModifiedEndPoint, Is.SameAs(_collectionEndPointMock));
            Assert.That(command.NewRelatedObject, Is.SameAs(_relatedObject));
            Assert.That(((CollectionEndPointInsertCommand)command).Index, Is.EqualTo(2));

            Assert.That(((CollectionEndPointInsertCommand)command).ModifiedCollectionData, Is.SameAs(fakeCollectionData));
            Assert.That(((CollectionEndPointInsertCommand)command).ModifiedCollection, Is.SameAs(fakeCollection));
            Assert.That(((CollectionEndPointInsertCommand)command).EndPointProvider, Is.SameAs(_endPointProviderStub));
        }