Exemple #1
0
        public override void SetUp()
        {
            base.SetUp();

            _parentTransactionContextMock         = MockRepository.GenerateStrictMock <IParentTransactionContext> ();
            _unlockedParentTransactionContextMock = MockRepository.GenerateStrictMock <IUnlockedParentTransactionContext> ();
            _persistenceStrategy = new SubPersistenceStrategy(_parentTransactionContextMock);

            _queryStub = MockRepository.GenerateStub <IQuery>();

            _orderNumberPropertyDefinition = GetPropertyDefinition(typeof(Order), "OrderNumber");
            _fileNamePropertyDefinition    = GetPropertyDefinition(typeof(OrderTicket), "FileName");
            _productPropertyDefinition     = GetPropertyDefinition(typeof(OrderItem), "Product");

            _virtualObjectRelationEndPointID = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "OrderTicket"));
            _collectionEndPointID            = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "OrderItems"));
            _nonVirtualEndPointID            = RelationEndPointID.Create(DomainObjectIDs.Order1, GetEndPointDefinition(typeof(Order), "Customer"));

            _alreadyLoadedObjectDataProviderMock = MockRepository.GenerateStrictMock <ILoadedObjectDataProvider>();
        }
Exemple #2
0
        private void PersistNewDataContainer(DataContainer dataContainer, IUnlockedParentTransactionContext unlockedParentTransactionContext)
        {
            Assertion.IsTrue(_parentTransactionContext.IsInvalid(dataContainer.ID));
            unlockedParentTransactionContext.MarkNotInvalid(dataContainer.ID);

            Assertion.IsNull(
                _parentTransactionContext.GetDataContainerWithoutLoading(dataContainer.ID),
                "a new data container cannot be known to the parent");
            Assertion.IsFalse(dataContainer.IsDiscarded);

            var parentDataContainer = DataContainer.CreateNew(dataContainer.ID);

            parentDataContainer.SetDomainObject(dataContainer.DomainObject);

            parentDataContainer.SetPropertyDataFromSubTransaction(dataContainer);

            Assertion.IsFalse(dataContainer.HasBeenMarkedChanged);
            Assertion.IsNull(dataContainer.Timestamp);

            unlockedParentTransactionContext.RegisterDataContainer(parentDataContainer);
        }
Exemple #3
0
        private void PersistDeletedDataContainer(DataContainer dataContainer, IUnlockedParentTransactionContext unlockedParentTransactionContext)
        {
            var parentDataContainer = _parentTransactionContext.GetDataContainerWithoutLoading(dataContainer.ID);

            Assertion.IsNotNull(
                parentDataContainer,
                "a deleted DataContainer must have been loaded through ParentTransaction, so the ParentTransaction must know it");

            Assertion.IsTrue(
                parentDataContainer.State != StateType.Invalid && parentDataContainer.State != StateType.Deleted,
                "deleted DataContainers cannot be discarded or deleted in the ParentTransaction");
            Assertion.IsTrue(parentDataContainer.DomainObject == dataContainer.DomainObject, "invariant");

            if (parentDataContainer.State == StateType.New)
            {
                unlockedParentTransactionContext.Discard(parentDataContainer);
            }
            else
            {
                parentDataContainer.Delete();
            }
        }
Exemple #4
0
        private void PersistDataContainers(IEnumerable <DataContainer> dataContainers, IUnlockedParentTransactionContext unlockedParentTransactionContext)
        {
            foreach (var dataContainer in dataContainers)
            {
                Assertion.IsFalse(
                    dataContainer.IsDiscarded,
                    "dataContainers cannot contain discarded DataContainers, because its items come"
                    + "from DataManager.DataContainerMap, which does not contain discarded containers");
                Assertion.IsTrue(dataContainer.State != StateType.Unchanged, "dataContainers cannot contain an unchanged container");
                Assertion.IsTrue(dataContainer.State != StateType.NotLoadedYet, "dataContainers cannot contain an unloaded container");
                Assertion.IsTrue(
                    dataContainer.State == StateType.New || dataContainer.State == StateType.Changed ||
                    dataContainer.State == StateType.Deleted,
                    "Invalid dataContainer.State: " + dataContainer.State);

                switch (dataContainer.State)
                {
                case StateType.New:
                    PersistNewDataContainer(dataContainer, unlockedParentTransactionContext);
                    break;

                case StateType.Changed:
                    PersistChangedDataContainer(dataContainer);
                    break;

                case StateType.Deleted:
                    PersistDeletedDataContainer(dataContainer, unlockedParentTransactionContext);
                    break;
                }
            }
        }