public void ObjectsNotFound() { var objectID1 = DomainObjectIDs.Order1; var objectID2 = DomainObjectIDs.Order3; var objectIDs = new[] { objectID1, objectID2 }; var parentTransaction = ClientTransaction.CreateRootTransaction(); var subTransaction1 = parentTransaction.CreateSubTransaction(); var subTransaction2 = subTransaction1.CreateSubTransaction(); Assert.That(parentTransaction.IsInvalid(objectID1), Is.False); Assert.That(parentTransaction.IsInvalid(objectID2), Is.False); Assert.That(subTransaction1.IsInvalid(objectID1), Is.False); Assert.That(subTransaction1.IsInvalid(objectID2), Is.False); Assert.That(subTransaction2.IsInvalid(objectID1), Is.False); Assert.That(subTransaction2.IsInvalid(objectID2), Is.False); _listener.ObjectsNotFound(parentTransaction, Array.AsReadOnly(objectIDs)); Assert.That(parentTransaction.IsInvalid(objectID1), Is.True); Assert.That(parentTransaction.IsInvalid(objectID2), Is.True); Assert.That(subTransaction1.IsInvalid(objectID1), Is.True); Assert.That(subTransaction1.IsInvalid(objectID2), Is.True); Assert.That(subTransaction2.IsInvalid(objectID1), Is.True); Assert.That(subTransaction1.IsInvalid(objectID2), Is.True); Assert.That( LifetimeService.GetObjectReference(parentTransaction, objectID1), Is.SameAs(LifetimeService.GetObjectReference(subTransaction1, objectID1))); Assert.That( LifetimeService.GetObjectReference(parentTransaction, objectID1), Is.SameAs(LifetimeService.GetObjectReference(subTransaction2, objectID1))); }
public void GetDomainObjectReference() { var domainObject = _endPoint.GetDomainObjectReference(); Assert.That(domainObject.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(domainObject, Is.SameAs(LifetimeService.GetObjectReference(TestableClientTransaction, DomainObjectIDs.Order1))); }
public void Invalidity_IsPropagated_ToSubtransaction_EvenIfLoadedOnlyIntoParentTransaction() { // When a subtransaction is active and a non-existing object is tried to be loaded into the parent transaction, the non-existing object should // be marked invalid in both transactions. // The only way to test this ATM is to trigger the loading of the non-existing object from a load event handler (which is triggered while the // parent transaction is temporarily writeable). var triggeringObjectReference = (TestDomainBase)LifetimeService.GetObjectReference(TestableClientTransaction, DomainObjectIDs.Order1); triggeringObjectReference.ProtectedLoaded += (sender, args) => { if (ClientTransaction.Current == TestableClientTransaction) { _nonExistingObjectID.TryGetObject <TestDomainBase> (); } }; using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { // Trigger the load event triggeringObjectReference.EnsureDataAvailable(); CheckObjectIsMarkedInvalid(_nonExistingObjectID); } CheckObjectIsMarkedInvalid(_nonExistingObjectID); }
public override void SetUp() { base.SetUp(); _clientTransaction = ClientTransaction.CreateRootTransaction(); _newDomainObject = _clientTransaction.ExecuteInScope(() => Order.NewObject()); _changedObject = _clientTransaction.ExecuteInScope(() => { var instance = DomainObjectIDs.Order1.GetObject <Order> (); instance.RegisterForCommit(); return(instance); }); _deletedObject = _clientTransaction.ExecuteInScope(() => { var instance = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); instance.Delete(); return(instance); }); _invalidObject = _clientTransaction.ExecuteInScope(() => { var instance = Order.NewObject(); instance.Delete(); return(instance); }); _unchangedObject = _clientTransaction.ExecuteInScope(() => DomainObjectIDs.Order4.GetObject <Order> ()); _notLoadedYetObject = LifetimeService.GetObjectReference(_clientTransaction, DomainObjectIDs.Order5); _registrar = new CommittingEventRegistrar(_clientTransaction); }
public static DomainObject GetDeletedObject(ClientTransaction transaction, ObjectID objectID) { var deletedInstance = LifetimeService.GetObjectReference(transaction, objectID); LifetimeService.DeleteObject(transaction, deletedInstance); Assert.That(deletedInstance.TransactionContext[transaction].State, Is.EqualTo(StateType.Deleted)); return(deletedInstance); }
public override void SetUp() { base.SetUp(); _order = (Order)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Order1); InstallExtensionMock(); }
public override void SetUp() { base.SetUp(); _order1 = (Order)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Order1); _relationEndPointID = RelationEndPointID.Resolve(_order1, o => o.Customer); _oppositeRelationEndPointID = RelationEndPointID.Create(DomainObjectIDs.Customer1, _relationEndPointID.Definition.GetOppositeEndPointDefinition()); }
public void GetObjectReference() { var result = LifetimeService.GetObjectReference(TestableClientTransaction, DomainObjectIDs.Order1); Assert.That(result, Is.InstanceOf(typeof(Order))); Assert.That(result.ID, Is.EqualTo(DomainObjectIDs.Order1)); Assert.That(result.State, Is.EqualTo(StateType.NotLoadedYet)); }
public void NeedsLoadModeDataContainerOnly_Serialization_ISerializable_False() { var classWithAllDataTypes = (ClassWithAllDataTypes)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.ClassWithAllDataTypes1); Assert.That(classWithAllDataTypes.NeedsLoadModeDataContainerOnly, Is.False); var deserializedClassWithAllDataTypes = Serializer.SerializeAndDeserialize(classWithAllDataTypes); Assert.That(deserializedClassWithAllDataTypes.NeedsLoadModeDataContainerOnly, Is.False); }
public void ObjectReference() { var classDefinition = MappingConfiguration.Current.GetTypeDefinition(typeof(SampleBindableDomainObject)); var instance = LifetimeService.GetObjectReference(TestableClientTransaction, new ObjectID(classDefinition, Guid.NewGuid())); var implementation = (BindableDomainObjectImplementation)PrivateInvoke.GetNonPublicField(instance, "_implementation"); Assert.That(implementation, Is.Not.Null); Assert.That(implementation.BusinessObjectClass, Is.Not.Null); }
public void NeedsLoadModeDataContainerOnly_Serialization_False() { var order = (Order)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order1); Assert.That(order.NeedsLoadModeDataContainerOnly, Is.False); var deserializedOrder = Serializer.SerializeAndDeserialize(order); Assert.That(deserializedOrder.NeedsLoadModeDataContainerOnly, Is.False); }
public void NeedsLoadModeDataContainerOnly_True_AfterOnLoaded() { var order = (Order)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order1); Assert.That(order.NeedsLoadModeDataContainerOnly, Is.False); PrivateInvoke.InvokeNonPublicMethod(order, typeof(DomainObject), "OnLoaded"); Assert.That(order.NeedsLoadModeDataContainerOnly, Is.True); }
public override void SetUp() { base.SetUp(); _transaction = ClientTransaction.CreateRootTransaction(); _cachingListener = new DomainObjectStateCache(_transaction); _existingOrder = (Order)LifetimeService.GetObject(_transaction, DomainObjectIDs.Order1, false); _newOrder = (Order)LifetimeService.NewObject(_transaction, typeof(Order), ParamList.Empty); _notYetLoadedOrder = (Order)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order3); }
public void DataContainerMapRegistering_NewObjects_NoParentTransaction() { var dataContainer = DataContainer.CreateNew(DomainObjectIDs.Order1); var domainObject = LifetimeService.GetObjectReference(_rootTransaction, dataContainer.ID); dataContainer.SetDomainObject(domainObject); _listener.DataContainerMapRegistering(_rootTransaction, dataContainer); Assert.That(_rootTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False); }
public void PropertyAccess_ShouldThrow_CollectionRelationProperty() { var instance = (Order)LifetimeService.GetObjectReference(TestableClientTransaction, _nonExistingObjectID); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(() => instance.OrderItems, ThrowsObjectNotFoundException(_nonExistingObjectID)); CheckObjectIsMarkedInvalid(instance.ID); // After the object has been marked invalid Assert.That(() => instance.OrderItems, ThrowsObjectInvalidException(_nonExistingObjectID)); }
public void GetObjectReference_WithInvalidObject() { var instance = Order.NewObject(); instance.Delete(); Assert.That(instance.State, Is.EqualTo(StateType.Invalid)); var result = LifetimeService.GetObjectReference(TestableClientTransaction, instance.ID); Assert.That(result, Is.SameAs(instance)); }
public ILoadedObjectData CreateFakeResultData(ClientTransaction clientTransaction) { var existingDataContainer = DataContainer.CreateForExisting( new ObjectID(typeof(OppositeBidirectionalBindableDomainObject), Guid.NewGuid()), null, pd => pd.DefaultValue); existingDataContainer.SetDomainObject(LifetimeService.GetObjectReference(clientTransaction, existingDataContainer.ID)); ClientTransactionTestHelper.GetDataManager(clientTransaction).RegisterDataContainer(existingDataContainer); return(new AlreadyExistingLoadedObjectData(existingDataContainer)); }
public override void SetUp() { base.SetUp(); _listener = new ReadOnlyClientTransactionListenerWithLoadRules(); _transaction = ClientTransactionObjectMother.Create(); _client1 = LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Client1); _order1 = LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order1); _orderNumberPropertyDefinition = GetPropertyDefinition(typeof(Order), "OrderNumber"); _orderTicketEndPointDefinition = GetEndPointDefinition(typeof(Order), "OrderTicket"); }
public static void RegisterDataContainer(ClientTransaction clientTransaction, DataContainer dataContainer) { if (!dataContainer.HasDomainObject) { var objectReference = LifetimeService.GetObjectReference(clientTransaction, dataContainer.ID); dataContainer.SetDomainObject(objectReference); } var dataManager = GetDataManager(clientTransaction); dataManager.RegisterDataContainer(dataContainer); }
private OrderItem RegisterFakeOrderItem(ObjectID objectID, ObjectID fakeOrderID) { var orderItem = (OrderItem)LifetimeService.GetObjectReference(TestableClientTransaction, objectID); var fakeDataContainer = DataContainer.CreateForExisting( orderItem.ID, null, pd => pd.PropertyName.EndsWith("Order") ? fakeOrderID : pd.DefaultValue); fakeDataContainer.SetDomainObject(orderItem); ClientTransactionTestHelper.RegisterDataContainer(TestableClientTransaction, fakeDataContainer); return(orderItem); }
public void EnsureDataAvailable_ShouldThrow_AndMarkObjectNotFound() { var instance = LifetimeService.GetObjectReference(TestableClientTransaction, _nonExistingObjectID); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(() => instance.EnsureDataAvailable(), ThrowsObjectNotFoundException(_nonExistingObjectID)); CheckObjectIsMarkedInvalid(instance.ID); // After the object has been marked invalid Assert.That(() => instance.EnsureDataAvailable(), ThrowsObjectInvalidException(_nonExistingObjectID)); }
public void NotLoadedYetObject_LoadedToUnchanged() { var domainObject = (ClassWithAllDataTypes)LifetimeService.GetObjectReference(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1); Assert.That(TestableClientTransaction.DataManager.DataContainers[domainObject.ID], Is.Null); Assert.That(domainObject.State, Is.EqualTo(StateType.NotLoadedYet)); domainObject.RegisterForCommit(); Assert.That(domainObject.State, Is.EqualTo(StateType.Changed)); Assert.That(TestableClientTransaction.DataManager.DataContainers[domainObject.ID], Is.Not.Null); CheckMarkedAsChanged(domainObject); }
public void NotFoundObject() { var notFoundID = new ObjectID(typeof(Order), Guid.NewGuid()); var notFoundObject = LifetimeService.GetObjectReference(TestableClientTransaction, notFoundID); notFoundObject.TryEnsureDataAvailable(); CheckStateIsInvalid(notFoundObject, TestableClientTransaction); ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, notFoundID); CheckStateIsNotInvalid(notFoundObject, TestableClientTransaction, StateType.NotLoadedYet); }
public void GetOppositeObject() { RealObjectEndPointTestHelper.SetOppositeObjectID(_endPoint, DomainObjectIDs.Order1); DomainObject oppositeObject; using (ClientTransactionScope.EnterNullScope()) { oppositeObject = _endPoint.GetOppositeObject(); } Assert.That(oppositeObject, Is.SameAs(LifetimeService.GetObjectReference(TestableClientTransaction, DomainObjectIDs.Order1))); Assert.That(oppositeObject.State, Is.EqualTo(StateType.NotLoadedYet), "Data has not been loaded"); }
public void GetObjectReferenceInReadOnlyMiddleTransaction_IsAllowed() { CheckDataNotLoaded(ReadOnlyRootTransaction, DomainObjectIDs.Order1); CheckDataNotLoaded(ReadOnlyMiddleTransaction, DomainObjectIDs.Order1); CheckDataNotLoaded(WriteableSubTransaction, DomainObjectIDs.Order1); var order1 = LifetimeService.GetObjectReference(ReadOnlyMiddleTransaction, DomainObjectIDs.Order1); Assert.That(order1.ID, Is.EqualTo(DomainObjectIDs.Order1)); CheckDataNotLoaded(ReadOnlyRootTransaction, order1); CheckDataNotLoaded(ReadOnlyMiddleTransaction, order1); CheckDataNotLoaded(WriteableSubTransaction, order1); }
public void GetObjectReference_DeletedInParentTransaction() { var order1 = DomainObjectIDs.Order1.GetObject <Order> (); order1.Delete(); ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var objectReference = LifetimeService.GetObjectReference(subTransaction, order1.ID); Assert.That(objectReference, Is.SameAs(order1)); Assert.That(objectReference.State, Is.EqualTo(StateType.Invalid)); } }
public override void SetUp() { base.SetUp(); _order = (Order)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Order1); _location = (Location)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Location1); _client1 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client1, false); _client2 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client2, false); _client3 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client3, false); _client4 = (Client)LifetimeService.NewObject(WriteableSubTransaction, typeof(Client), ParamList.Empty); _loadEventReceiverMock = MockRepository.GenerateStrictMock <ILoadEventReceiver>(); _order.SetLoadEventReceiver(_loadEventReceiverMock); _location.SetLoadEventReceiver(_loadEventReceiverMock); }
private Group GetParentObjectReference() { var parentID = Properties[typeof(Group), "Parent"].GetRelatedObjectID(); if (parentID == null) { return(null); } var parent = (Group)LifetimeService.GetObjectReference(DefaultTransactionContext.ClientTransaction, parentID); UnloadService.TryUnloadData(DefaultTransactionContext.ClientTransaction, parent.ID); return(parent); }
public void CanRead_NotLoadedObject_LoadsNonExistentObject_ReturnsFalse() { var instance = (SampleBindableDomainObject)LifetimeService.GetObjectReference( ClientTransaction.Current, new ObjectID(typeof(SampleBindableDomainObject), Guid.NewGuid())); var property = GetProperty(instance); var strategy = (IBindablePropertyReadAccessStrategy) new BindableDomainObjectPropertyReadAccessStrategy(); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); var result = strategy.CanRead(instance, property); Assert.That(result, Is.False); Assert.That(instance.State, Is.EqualTo(StateType.Invalid)); }
public void DataContainerMapRegistering_IgnoresNonNewObjects() { var middleTransaction = CreateSubTransactionAndClearListeners(_rootTransaction); var subTransaction = CreateSubTransactionAndClearListeners(middleTransaction); var dataContainer = DataContainer.CreateForExisting(DomainObjectIDs.Order1, null, pd => pd.DefaultValue); var domainObject = LifetimeService.GetObjectReference(subTransaction, dataContainer.ID); dataContainer.SetDomainObject(domainObject); _listener.DataContainerMapRegistering(subTransaction, dataContainer); Assert.That(_rootTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False); Assert.That(middleTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False); Assert.That(subTransaction.IsInvalid(DomainObjectIDs.Order1), Is.False); }