public void VirtualEndPointQuery_OneMany_ObjectIncludedInTwoCollections() { SetDatabaseModifyable(); var companyID = CreateCompanyAndSetIndustrialSectorInOtherTransaction(DomainObjectIDs.IndustrialSector1); var company = companyID.GetObject <Company> (); var industrialSector1 = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> (); industrialSector1.Companies.EnsureDataComplete(); SetIndustrialSectorInOtherTransaction(company.ID, DomainObjectIDs.IndustrialSector2); var industrialSector2 = DomainObjectIDs.IndustrialSector2.GetObject <IndustrialSector> (); industrialSector2.Companies.EnsureDataComplete(); Assert.That(company.IndustrialSector, Is.SameAs(industrialSector1)); Assert.That(industrialSector1.Companies, Has.Member(company)); Assert.That(industrialSector2.Companies, Has.Member(company)); CheckSyncState(company, c => c.IndustrialSector, true); CheckSyncState(industrialSector1, s => s.Companies, true); CheckSyncState(industrialSector2, s => s.Companies, false); BidirectionalRelationSyncService.Synchronize(TestableClientTransaction, RelationEndPointID.Resolve(industrialSector2, s => s.Companies)); Assert.That(company.IndustrialSector, Is.SameAs(industrialSector1)); Assert.That(industrialSector1.Companies, Has.Member(company)); Assert.That(industrialSector2.Companies, Has.No.Member(company)); CheckSyncState(company, c => c.IndustrialSector, true); CheckSyncState(industrialSector1, s => s.Companies, true); CheckSyncState(industrialSector2, s => s.Companies, true); }
public void Synchronize_WithSubtransactions_LoadedInRootAndSub_SyncedInSub() { Company company; IndustrialSector industrialSector; PrepareInconsistentState_OneMany_ObjectIncluded(out company, out industrialSector); CheckSyncState(company, c => c.IndustrialSector, true); CheckSyncState(industrialSector, s => s.Companies, false); using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { var relationEndPointID = RelationEndPointID.Resolve(industrialSector, s => s.Companies); var dataManager = ClientTransactionTestHelper.GetDataManager(ClientTransaction.Current); var endPoint = dataManager.GetRelationEndPointWithLazyLoad(relationEndPointID); Assert.That(endPoint.IsSynchronized, Is.Null); endPoint.EnsureDataComplete(); Assert.That(endPoint.IsSynchronized, Is.False); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, relationEndPointID); CheckSyncState(industrialSector, s => s.Companies, true); Assert.That(endPoint.IsSynchronized, Is.True); } CheckSyncState(industrialSector, s => s.Companies, true); }
public void UnloadLastFK_CausesCollectionEndPointToBeRemoved_ButKeepsDomainObjectCollectionInMemory() { SetDatabaseModifyable(); var industrialSector = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> (); var companies = industrialSector.Companies; industrialSector.Companies.EnsureDataComplete(); var unsynchronizedCompanyID = CreateCompanyAndSetIndustrialSectorInOtherTransaction(industrialSector.ID); var unsynchronizedCompany = unsynchronizedCompanyID.GetObject <Company> (); var virtualEndPointID = RelationEndPointID.Resolve(industrialSector, s => s.Companies); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True); UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, virtualEndPointID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.False); UnloadService.UnloadData(TestableClientTransaction, unsynchronizedCompany.ID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Null); // But DomainObjectCollection stays valid Assert.That(industrialSector.Companies, Is.SameAs(companies)); }
public void UnloadCollectionEndPoint_WithoutReferences_AfterSettingDifferentCollection_AndRollback_CausesEndPointToBeRemoved_ButKeepsDomainObjectCollectionInMemory() { SetDatabaseModifyable(); var customer = DomainObjectIDs.Customer2.GetObject <Customer> (); var oldCustomerOrders = customer.Orders; Assert.That(customer.Orders, Is.Empty); var newCustomerOrders = new OrderCollection(); customer.Orders = newCustomerOrders; Assert.That(customer.Orders, Is.Empty); TestableClientTransaction.Rollback(); var virtualEndPointID = RelationEndPointID.Resolve(customer, c => c.Orders); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, virtualEndPointID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Null); // But DomainObjectCollection stays valid - and uses original collection Assert.That(oldCustomerOrders, Is.SameAs(customer.Orders)); }
public void Synchronize_WithSubtransactions_LoadedInRootAndSub_SyncedInRoot() { Computer computer; Employee employee; Employee employee2; PrepareInconsistentState_OneOne_ObjectReturned_ThatLocallyPointsSomewhereElse(out computer, out employee, out employee2); Assert.That(computer.Employee, Is.SameAs(employee2)); Assert.That(employee.Computer, Is.SameAs(computer)); Assert.That(employee2.Computer, Is.SameAs(computer)); CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, false); CheckSyncState(employee2, e => e.Computer, true); using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { TestableClientTransaction.EnsureDataComplete(RelationEndPointID.Resolve(computer, c => c.Employee)); TestableClientTransaction.EnsureDataComplete(RelationEndPointID.Resolve(employee, e => e.Computer)); TestableClientTransaction.EnsureDataComplete(RelationEndPointID.Resolve(employee2, e => e.Computer)); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current.ParentTransaction, RelationEndPointID.Resolve(employee, e => e.Computer)); CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); CheckSyncState(employee2, e => e.Computer, true); } CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); CheckSyncState(employee2, e => e.Computer, true); }
protected void SecurableClassDefinitionTree_Click(object sender, BocTreeNodeClickEventArgs e) { if (!IsReturningPostBack) { var classDefinition = (SecurableClassDefinition)e.BusinessObjectTreeNode.BusinessObject; var function = new EditPermissionsFormFunction(WxeTransactionMode.CreateRootWithAutoCommit, classDefinition.GetHandle()); var options = new WxeCallOptionsExternal( "_blank", "width=1000, height=700, resizable=yes, menubar=no, toolbar=no, location=no, status=no", true); try { ExecuteFunction(function, new WxeCallArguments((Control)sender, options)); } catch (WxeCallExternalException) { } } else { var classDefinition = ((EditPermissionsFormFunction)ReturningFunction).CurrentObjectHandle.GetObject(); UnloadService.UnloadVirtualEndPoint( ClientTransaction.Current, RelationEndPointID.Resolve(classDefinition, c => c.StatelessAccessControlList)); UnloadService.UnloadVirtualEndPoint( ClientTransaction.Current, RelationEndPointID.Resolve(classDefinition, c => c.StatefulAccessControlLists)); LoadTree(false, true); } }
public void UnloadVirtualEndPoint_ObjectEndPoint_ChangedInParent_ButNotInSubTx() { var order = DomainObjectIDs.Order1.GetObject <Order> (); var oldOrderTicket = order.OrderTicket; oldOrderTicket.Delete(); var newOrderTicket = OrderTicket.NewObject(); order.OrderTicket = newOrderTicket; _subTransaction.Commit(); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); Assert.That(order.TransactionContext[_subTransaction.ParentTransaction].State, Is.EqualTo(StateType.Changed)); try { UnloadService.UnloadVirtualEndPoint(_subTransaction, RelationEndPointID.Resolve(order, o => o.OrderTicket)); Assert.Fail("Expected InvalidOperationException"); } catch (InvalidOperationException ex) { Assert.That(ex.Message, Is.EqualTo( "The end point with ID " + "'Order|5682f032-2f0b-494b-a31c-c97f02b89c36|System.Guid/Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderTicket' " + "has been changed. Changed end points cannot be unloaded.")); } CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", true); CheckVirtualEndPoint(_subTransaction.ParentTransaction, order, "OrderTicket", true); Assert.That(order.OrderTicket, Is.SameAs(newOrderTicket)); }
public void ObjectLoaded_WithInconsistentForeignKey_OneOne_NonNull_UnloadCorrectsIssue() { Employee employee; Computer computer; Computer computer2; PrepareInconsistentState_InconsistentForeignKeyLoaded_VirtualSideAlreadyNonNull(out employee, out computer, out computer2); // computer.Employee and employee.Computer match, but computer2.Employee doesn't Assert.That(computer.Employee, Is.SameAs(employee)); Assert.That(computer2.Employee, Is.SameAs(employee)); Assert.That(employee.Computer, Is.SameAs(computer)); CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); CheckSyncState(computer2, c => c.Employee, false); // Reload virtual relation from database => computer2 and employee now match, computer is unsynchronized UnloadService.UnloadVirtualEndPoint(ClientTransaction.Current, RelationEndPointID.Resolve(employee, e => e.Computer)); Dev.Null = employee.Computer; CheckSyncState(computer, c => c.Employee, false); CheckSyncState(computer2, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); Assert.That(employee.Computer, Is.SameAs(computer2)); Assert.That(computer2.Employee, Is.SameAs(employee)); Assert.That(computer.Employee, Is.SameAs(employee)); }
public void CollectionItems_Unsynchronized_WithUnload() { SetDatabaseModifyable(); var order = DomainObjectIDs.Order1.GetObject <Order> (); order.OrderItems.EnsureDataComplete(); var orderItemID = RelationInconcsistenciesTestHelper.CreateObjectAndSetRelationInOtherTransaction <OrderItem, Order> (order.ID, (oi, o) => oi.Order = o); var orderItem = orderItemID.GetObject <OrderItem>(); var endPointID = RelationEndPointID.Resolve(orderItem, oi => oi.Order); var endPoint = (RealObjectEndPoint)TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID); Assert.That(endPoint, Is.Not.Null); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(UnsynchronizedRealObjectEndPointSyncState))); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, orderItem.Order.OrderItems.AssociatedEndPointID); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(UnknownRealObjectEndPointSyncState))); order.OrderItems.EnsureDataComplete(); Assert.That(RealObjectEndPointTestHelper.GetSyncState(endPoint), Is.TypeOf(typeof(SynchronizedRealObjectEndPointSyncState))); }
public void UnloadVirtualEndPoint_VirtualEndPoint() { var order = DomainObjectIDs.Order1.GetObject <Order> (); var orderTicket = order.OrderTicket; CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", true); UnloadService.UnloadVirtualEndPoint(_subTransaction, RelationEndPointID.Resolve(order, o => o.OrderTicket)); CheckDataContainerExists(_subTransaction, order, true); CheckDataContainerExists(_subTransaction, orderTicket, true); CheckEndPointExists(_subTransaction, orderTicket, "Order", true); CheckVirtualEndPoint(_subTransaction, order, "OrderTicket", false); CheckDataContainerExists(_subTransaction.ParentTransaction, order, true); CheckDataContainerExists(_subTransaction.ParentTransaction, orderTicket, true); CheckEndPointExists(_subTransaction.ParentTransaction, orderTicket, "Order", true); CheckVirtualEndPoint(_subTransaction.ParentTransaction, order, "OrderTicket", false); Assert.That(order.State, Is.EqualTo(StateType.Unchanged)); Assert.That(orderTicket.State, Is.EqualTo(StateType.Unchanged)); Assert.That(order.TransactionContext[_subTransaction.ParentTransaction].State, Is.EqualTo(StateType.Unchanged)); Assert.That(orderTicket.TransactionContext[_subTransaction.ParentTransaction].State, Is.EqualTo(StateType.Unchanged)); }
public void UnloadVirtualEndPoint_EndPointsOfDeletedObject_CannotBeUnloaded() { var customerWithoutOrders = DomainObjectIDs.Customer2.GetObject <Customer> (); var employeeWithoutComputer = DomainObjectIDs.Employee1.GetObject <Employee> (); var endPointID1 = RelationEndPointID.Resolve(customerWithoutOrders, o => o.Orders); var endPointID2 = RelationEndPointID.Resolve(employeeWithoutComputer, o => o.Computer); customerWithoutOrders.Delete(); employeeWithoutComputer.Delete(); CheckEndPointExists(endPointID1, true); CheckEndPointExists(endPointID2, true); Assert.That( () => UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPointID1), Throws.InvalidOperationException.With.Message.EqualTo( "Cannot unload the following relation end-points because they belong to new or deleted objects: " + endPointID1 + ".")); Assert.That( () => UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, endPointID2), Throws.InvalidOperationException.With.Message.EqualTo( "Cannot unload the following relation end-points because they belong to new or deleted objects: " + endPointID2 + ".")); Assert.That(UnloadService.TryUnloadVirtualEndPoint(TestableClientTransaction, endPointID1), Is.False); Assert.That(UnloadService.TryUnloadVirtualEndPoint(TestableClientTransaction, endPointID2), Is.False); CheckEndPointExists(endPointID1, true); CheckEndPointExists(endPointID2, true); }
public void UnloadVirtualEndPoint_Object_Null_Reload() { SetDatabaseModifyable(); var employee = DomainObjectIDs.Employee1.GetObject <Employee> (); Dev.Null = employee.Computer; ObjectID newComputerID; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var employeeInOtherTx = employee.ID.GetObject <Employee> (); employeeInOtherTx.Computer = Computer.NewObject(); newComputerID = employeeInOtherTx.Computer.ID; ClientTransaction.Current.Commit(); } Assert.That(employee.Computer, Is.Null); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, RelationEndPointID.Resolve(employee, e => e.Computer)); Assert.That(employee.Computer.ID, Is.EqualTo(newComputerID)); Assert.That(employee.Computer, Is.SameAs(newComputerID.GetObject <Computer> ())); }
public void UnloadVirtualEndPoint_Object_Reload() { SetDatabaseModifyable(); var order = DomainObjectIDs.Order1.GetObject <Order> (); var oldOrderTicket = order.OrderTicket; ObjectID newOrderTicketID; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var orderInOtherTx = DomainObjectIDs.Order1.GetObject <Order> (); orderInOtherTx.OrderTicket.Delete(); orderInOtherTx.OrderTicket = OrderTicket.NewObject(); newOrderTicketID = orderInOtherTx.OrderTicket.ID; ClientTransaction.Current.Commit(); } Assert.That(order.OrderTicket, Is.SameAs(oldOrderTicket)); UnloadService.UnloadVirtualEndPoint(TestableClientTransaction, RelationEndPointID.Resolve(order, o => o.OrderTicket)); Assert.That(order.OrderTicket, Is.SameAs(newOrderTicketID.GetObject <OrderTicket> ())); }
public void Sort_TriggersOnReplaceDataEvent_ButNoRelationChangeEvents() { var eventReceiverMock = MockRepository.GenerateStrictMock <OrderCollection.ICollectionEventReceiver>(); eventReceiverMock.Expect(mock => mock.OnReplaceData()); eventReceiverMock.Replay(); var orderCollection = _owningCustomer.Orders; orderCollection.SetEventReceiver(eventReceiverMock); var eventListenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction); try { eventListenerMock .Expect( mock => mock.VirtualRelationEndPointStateUpdated( TestableClientTransaction, RelationEndPointID.Resolve(_owningCustomer, c => c.Orders), null)); eventListenerMock.Replay(); orderCollection.Sort(_reversingComparison); eventReceiverMock.VerifyAllExpectations(); eventListenerMock.VerifyAllExpectations(); } finally { TestableClientTransaction.RemoveListener(eventListenerMock); } }
public void UnloadLastFK_CausesVirtualObjectEndPointToBeRemoved() { SetDatabaseModifyable(); var employee = DomainObjectIDs.Employee3.GetObject <Employee> (); var virtualEndPointID = RelationEndPointID.Resolve(employee, e => e.Computer); TestableClientTransaction.EnsureDataComplete(virtualEndPointID); var unsynchronizedComputerID = RelationInconcsistenciesTestHelper.CreateObjectAndSetRelationInOtherTransaction <Computer, Employee> ( employee.ID, (c, e) => c.Employee = e); var unsynchronizedComputer = unsynchronizedComputerID.GetObject <Computer> (); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.True); UnloadService.UnloadData(TestableClientTransaction, employee.Computer.ID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Not.Null); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID).IsDataComplete, Is.False); UnloadService.UnloadData(TestableClientTransaction, unsynchronizedComputer.ID); Assert.That(_dataManager.GetRelationEndPointWithoutLoading(virtualEndPointID), Is.Null); }
public void ObjectLoaded_WithInconsistentForeignKey_OneOne_Null() { Employee employee; Computer computer; PrepareInconsistentState_InconsistentForeignKeyLoaded_VirtualSideAlreadyNull(out employee, out computer); Assert.That(computer.Employee, Is.SameAs(employee)); Assert.That(employee.Computer, Is.Null); CheckSyncState(computer, c => c.Employee, false); CheckSyncState(employee, e => e.Computer, true); // sync states not changed by Rollback CheckSyncState(computer, c => c.Employee, false); CheckSyncState(employee, e => e.Computer, true); CheckActionThrows <InvalidOperationException> (employee.Delete, "out of sync with the virtual property"); CheckActionThrows <InvalidOperationException> (computer.Delete, "out of sync with the opposite property"); CheckActionThrows <InvalidOperationException> (() => computer.Employee = null, "out of sync with the opposite property"); CheckActionThrows <InvalidOperationException> (() => employee.Computer = computer, "out of sync with the virtual property"); CheckActionWorks(() => employee.Computer = Computer.NewObject()); ClientTransaction.Current.Rollback(); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(computer, c => c.Employee)); CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); Assert.That(employee.Computer, Is.SameAs(computer)); Assert.That(computer.Employee, Is.SameAs(employee)); }
public void UnloadVirtualEndPointAndItemData_IsAtomicWithinTransaction_WhenSingleCollectionItemIsChanged() { var order1 = DomainObjectIDs.Order1.GetObject <Order> (); var endPointID = RelationEndPointID.Resolve(order1, o => o.OrderItems); var orderItemA = order1.OrderItems[0]; var orderItemB = order1.OrderItems[1]; // Change a single OrderItem - this must cause nothing to be unloaded orderItemB.Product = "Changed"; Assert.That(orderItemA.State, Is.EqualTo(StateType.Unchanged)); Assert.That(orderItemB.State, Is.EqualTo(StateType.Changed)); Assert.That(TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(endPointID).HasChanged, Is.False); Assert.That(order1.OrderItems.IsDataComplete, Is.True); CheckDataContainerExists(orderItemA, true); CheckDataContainerExists(orderItemB, true); CheckVirtualEndPointExistsAndComplete(endPointID, true, true); Assert.That(() => UnloadService.UnloadVirtualEndPointAndItemData(TestableClientTransaction, endPointID), Throws.InvalidOperationException); CheckDataContainerExists(orderItemA, true); CheckDataContainerExists(orderItemB, true); CheckVirtualEndPointExistsAndComplete(endPointID, true, true); Assert.That(UnloadService.TryUnloadVirtualEndPointAndItemData(TestableClientTransaction, endPointID), Is.False); CheckDataContainerExists(orderItemA, true); CheckDataContainerExists(orderItemB, true); CheckVirtualEndPointExistsAndComplete(endPointID, true, true); Assert.That(orderItemA.State, Is.Not.EqualTo(StateType.NotLoadedYet)); Assert.That(orderItemB.State, Is.Not.EqualTo(StateType.NotLoadedYet)); Assert.That(order1.OrderItems.IsDataComplete, Is.True); }
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 EagerFetching_UsesForeignKeyDataFromDatabase_NotTransaction() { // This will retrieve Order1. var ordersQuery = CreateOrdersQuery("OrderNo = 1"); // This will fetch OrderItem1 and OrderItem2, both pointing to Order1. AddOrderItemsFetchQuery(ordersQuery, "o.OrderNo = 1"); // Fake OrderItem2 to point to Order3 in memory. var orderItem2 = RegisterFakeOrderItem(DomainObjectIDs.OrderItem2, DomainObjectIDs.Order3); var result = TestableClientTransaction.QueryManager.GetCollection(ordersQuery); var order1 = DomainObjectIDs.Order1.GetObject <Order> (); Assert.That(result.ToArray(), Is.EquivalentTo(new[] { order1 })); var orderItemsEndPointID = RelationEndPointID.Resolve(order1, o => o.OrderItems); var orderItemsEndPoint = TestableClientTransaction.DataManager.GetRelationEndPointWithoutLoading(orderItemsEndPointID); Assert.That(orderItemsEndPoint, Is.Not.Null); Assert.That(orderItemsEndPoint.IsDataComplete, Is.True); // The relation contains the fetched result, disregarding the in-memory data. This makes it an unsynchronized relation. Assert.That( order1.OrderItems, Is.EquivalentTo(new[] { DomainObjectIDs.OrderItem1.GetObject <OrderItem>(), orderItem2 })); Assert.That(orderItem2.Order, Is.Not.SameAs(order1)); Assert.That(BidirectionalRelationSyncService.IsSynchronized(TestableClientTransaction, orderItemsEndPointID), Is.False); }
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 Resolve_Expression_Interface() { var instance = DomainObjectMother.CreateFakeObject <Order> (_objectID); var endPointID = RelationEndPointID.Resolve(instance, o => ((IOrder)o).OrderTicket); Assert.That(endPointID.Definition, Is.EqualTo(_endPointDefinition)); Assert.That(endPointID.ObjectID, Is.EqualTo(_objectID)); }
public void GetState_FromDataContainer_DoesNotLoadRelations() { var dataManager = ClientTransactionTestHelper.GetIDataManager(_transaction); Assert.That(dataManager.GetRelationEndPointWithoutLoading(RelationEndPointID.Resolve(_existingOrder, o => o.OrderTicket)), Is.Null); _transaction.ExecuteInScope(() => _existingOrder.OrderItems.Clear()); Assert.That(dataManager.GetRelationEndPointWithoutLoading(RelationEndPointID.Resolve(_existingOrder, o => o.OrderTicket)), Is.Null); }
private Order LoadOrderWithRelations(ObjectID objectID) { var order = objectID.GetObject <Order> (); order.EnsureDataAvailable(); ClientTransaction.Current.EnsureDataComplete(RelationEndPointID.Resolve(order, o => o.OrderTicket)); ClientTransaction.Current.EnsureDataComplete(RelationEndPointID.Resolve(order, o => o.OrderItems)); ClientTransaction.Current.EnsureDataComplete(RelationEndPointID.Resolve(order, o => o.Customer)); return(order); }
public void VirtualEndPointQuery_OneMany_ObjectIncluded_ThatLocallyPointsToSomewhereElse() { SetDatabaseModifyable(); var company = CreateCompanyInDatabaseAndLoad(); Assert.That(company.IndustrialSector, Is.Null); var industrialSector = DomainObjectIDs.IndustrialSector1.GetObject <IndustrialSector> (); // virtual end point not yet resolved SetIndustrialSectorInOtherTransaction(company.ID, industrialSector.ID); // Resolve virtual end point - the database says that company points to industrialSector, but the transaction says it points to null! var companiesOfIndustrialSector = industrialSector.Companies; companiesOfIndustrialSector.EnsureDataComplete(); Assert.That(company.IndustrialSector, Is.Null); Assert.That(companiesOfIndustrialSector, Has.Member(company)); CheckSyncState(company, c => c.IndustrialSector, true); CheckSyncState(industrialSector, s => s.Companies, false); var otherCompany = companiesOfIndustrialSector.FirstOrDefault(c => c != company); CheckSyncState(otherCompany, c => c.IndustrialSector, true); CheckActionWorks(company.Delete); TestableClientTransaction.Rollback(); // required so that the remaining actions can be tried below // sync states not changed by Rollback CheckSyncState(company, c => c.IndustrialSector, true); CheckSyncState(industrialSector, s => s.Companies, false); CheckActionWorks(() => industrialSector.Companies.Remove(otherCompany)); CheckActionWorks(() => industrialSector.Companies.Add(Company.NewObject())); var companyIndex = industrialSector.Companies.IndexOf(company); CheckActionThrows <InvalidOperationException> (industrialSector.Delete, "out of sync with the opposite object property"); CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies.Remove(company), "out of sync with the opposite object property"); CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies[companyIndex] = Company.NewObject(), "out of sync with the opposite object property"); CheckActionThrows <InvalidOperationException> (() => industrialSector.Companies = new ObjectList <Company> (), "out of sync with the opposite object property"); CheckActionThrows <InvalidOperationException> (industrialSector.Delete, "out of sync with the opposite object property"); CheckActionWorks(() => company.IndustrialSector = IndustrialSector.NewObject()); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(industrialSector, s => s.Companies)); CheckSyncState(industrialSector, s => s.Companies, true); Assert.That(companiesOfIndustrialSector, Has.No.Member(company)); CheckActionWorks(() => industrialSector.Companies.Add(company)); }
public void ObjectLoaded_WithInconsistentForeignKey_OneOne_NonNull() { Employee employee; Computer computer; Computer computer2; using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { PrepareInconsistentState_InconsistentForeignKeyLoaded_VirtualSideAlreadyNonNull(out employee, out computer, out computer2); // computer.Employee and employee.Computer match, but computer2.Employee doesn't Assert.That(computer.Employee, Is.SameAs(employee)); Assert.That(computer2.Employee, Is.SameAs(employee)); Assert.That(employee.Computer, Is.SameAs(computer)); CheckSyncState(computer, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); CheckSyncState(computer2, c => c.Employee, false); CheckActionThrows <InvalidOperationException> (() => BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(computer2, c => c.Employee)), "The object end-point '{0}/Remotion.Data.DomainObjects.UnitTests.TestDomain.Computer.Employee' " + "cannot be synchronized with the virtual object end-point " + "'{2}/Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Computer' because " + "the virtual relation property already refers to another object ('{1}'). To synchronize " + "'{0}/Remotion.Data.DomainObjects.UnitTests.TestDomain.Computer.Employee', use " + "UnloadService to unload either object '{1}' or the virtual object end-point " + "'{2}/Remotion.Data.DomainObjects.UnitTests.TestDomain.Employee.Computer'.", computer2.ID, computer.ID, employee.ID); // By unloading the employee.Computer -> computer relation, we can now synchronize computer2.Employee -> employee with employee.Computer UnloadService.UnloadVirtualEndPoint(ClientTransaction.Current, RelationEndPointID.Resolve(employee, e => e.Computer)); BidirectionalRelationSyncService.Synchronize(ClientTransaction.Current, RelationEndPointID.Resolve(computer2, c => c.Employee)); CheckSyncState(computer, c => c.Employee, false); CheckSyncState(computer2, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); Assert.That(employee.Computer, Is.SameAs(computer2)); Assert.That(computer2.Employee, Is.SameAs(employee)); Assert.That(computer.Employee, Is.SameAs(employee)); } CheckSyncState(computer, c => c.Employee, false); CheckSyncState(computer2, c => c.Employee, true); CheckSyncState(employee, e => e.Computer, true); Assert.That(employee.Computer, Is.SameAs(computer2)); Assert.That(computer2.Employee, Is.SameAs(employee)); Assert.That(computer.Employee, Is.SameAs(employee)); }
public void ExpandToAllRelatedObjects_SetDifferent_BidirectionalOneOne() { // order.OrderTicket = newOrderTicket; var bidirectionalModification = _command.ExpandToAllRelatedObjects(); var steps = bidirectionalModification.GetNestedCommands(); Assert.That(steps.Count, Is.EqualTo(4)); // order.OrderTicket = newOrderTicket; Assert.That(steps[0], Is.SameAs(_command)); // oldOrderTicket.Order = null; var orderOfOldOrderTicketEndPointID = RelationEndPointID.Resolve(_oldRelatedObject, ot => ot.Order); var orderOfOldOrderTicketEndPoint = TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(orderOfOldOrderTicketEndPointID); Assert.That(steps[1], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrderOfOldOrderTicketCommand = (ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[1]).DecoratedCommand; Assert.That(setOrderOfOldOrderTicketCommand.ModifiedEndPoint, Is.SameAs(orderOfOldOrderTicketEndPoint)); Assert.That(setOrderOfOldOrderTicketCommand.OldRelatedObject, Is.SameAs(_domainObject)); Assert.That(setOrderOfOldOrderTicketCommand.NewRelatedObject, Is.Null); // newOrderTicket.Order = order; var orderOfNewOrderTicketEndPointID = RelationEndPointID.Resolve(_newRelatedObject, ot => ot.Order); var orderOfNewOrderTicketEndPoint = TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(orderOfNewOrderTicketEndPointID); Assert.That(steps[2], Is.InstanceOf(typeof(RealObjectEndPointRegistrationCommandDecorator))); var setOrderOfNewOrderTicketCommand = (ObjectEndPointSetCommand)((RealObjectEndPointRegistrationCommandDecorator)steps[2]).DecoratedCommand; Assert.That(setOrderOfNewOrderTicketCommand.ModifiedEndPoint, Is.SameAs(orderOfNewOrderTicketEndPoint)); Assert.That(setOrderOfNewOrderTicketCommand.OldRelatedObject, Is.SameAs(_newRelatedObject.Order)); Assert.That(setOrderOfNewOrderTicketCommand.NewRelatedObject, Is.SameAs(_domainObject)); // oldOrderOfNewOrderTicket.OrderTicket = null var orderTicketOfOldOrderOfNewOrderTicketEndPointID = RelationEndPointID.Create(_newRelatedObject.Order.ID, _endPoint.Definition); var orderTicketOfOldOrderOfNewOrderTicketEndPoint = TestableClientTransaction.DataManager.GetRelationEndPointWithLazyLoad(orderTicketOfOldOrderOfNewOrderTicketEndPointID); Assert.That(steps[3], Is.InstanceOf(typeof(VirtualEndPointStateUpdatedRaisingCommandDecorator))); var setOrderTicketOfOldOrderOfNewOrderTicketCommand = ((ObjectEndPointSetCommand)((VirtualEndPointStateUpdatedRaisingCommandDecorator)steps[3]).DecoratedCommand); Assert.That(setOrderTicketOfOldOrderOfNewOrderTicketCommand.ModifiedEndPoint, Is.SameAs(((StateUpdateRaisingVirtualObjectEndPointDecorator)orderTicketOfOldOrderOfNewOrderTicketEndPoint).InnerEndPoint)); Assert.That(setOrderTicketOfOldOrderOfNewOrderTicketCommand.OldRelatedObject, Is.SameAs(_newRelatedObject)); Assert.That(setOrderTicketOfOldOrderOfNewOrderTicketCommand.NewRelatedObject, Is.SameAs(null)); }
public override void SetUp() { base.SetUp(); _domainObject = DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); _oldRelatedObject = _domainObject.Order; _newRelatedObject = DomainObjectIDs.Order3.GetObject <Order> (); _endPointID = RelationEndPointID.Resolve(_domainObject, oi => oi.Order); _endPoint = (RealObjectEndPoint)RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID); _command = new ObjectEndPointSetOneManyCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, EndPointProviderStub, TransactionEventSinkWithMock); }
public override void SetUp() { base.SetUp(); _domainObject = DomainObjectIDs.Client3.GetObject <Client> (); _oldRelatedObject = DomainObjectIDs.Client1.GetObject <Client> (); _newRelatedObject = DomainObjectIDs.Client2.GetObject <Client> (); _endPointID = RelationEndPointID.Resolve(_domainObject, c => c.ParentClient); _endPoint = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID); _command = new ObjectEndPointSetUnidirectionalCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, TransactionEventSinkWithMock); }
public override void SetUp() { base.SetUp(); _domainObject = DomainObjectIDs.Order1.GetObject <Order> (); _oldRelatedObject = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> (); _newRelatedObject = DomainObjectIDs.OrderTicket2.GetObject <OrderTicket> (); _endPointID = RelationEndPointID.Resolve(_domainObject, o => o.OrderTicket); _endPoint = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _oldRelatedObject.ID); _command = new ObjectEndPointSetOneOneCommand(_endPoint, _newRelatedObject, OppositeObjectSetter, TransactionEventSinkWithMock); }
public override void SetUp() { base.SetUp(); _domainObject = DomainObjectIDs.Computer1.GetObject <Computer> (); _relatedObject = DomainObjectIDs.Employee3.GetObject <Employee> (); _endPointID = RelationEndPointID.Resolve(_domainObject, c => c.Employee); _endPoint = RelationEndPointObjectMother.CreateObjectEndPoint(_endPointID, _relatedObject.ID); _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>(); _command = new ObjectEndPointSetSameCommand(_endPoint, _transactionEventSinkWithMock); }