public void AccessInvalidForeignKeyRelation() { var id = new ObjectID(typeof(ClassWithInvalidRelation), new Guid("{AFA9CF46-8E77-4da8-9793-53CAA86A277C}")); var objectWithInvalidRelation = (ClassWithInvalidRelation)id.GetObject <TestDomainBase> (); Assert.That(objectWithInvalidRelation.ClassWithGuidKey.State, Is.Not.EqualTo(StateType.Invalid)); Assert.That(() => objectWithInvalidRelation.ClassWithGuidKey.EnsureDataAvailable(), Throws.TypeOf <ObjectsNotFoundException>()); Assert.That(objectWithInvalidRelation.ClassWithGuidKey.State, Is.EqualTo(StateType.Invalid)); // Overwriting the invalid ID is possible! var classWithGuidKey = ClassWithGuidKey.NewObject(); classWithGuidKey.ClassWithValidRelationsNonOptional = ClassWithValidRelations.NewObject(); objectWithInvalidRelation.ClassWithGuidKey = classWithGuidKey; SetDatabaseModifyable(); TestableClientTransaction.Commit(); using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var reloadedObject = (ClassWithInvalidRelation)id.GetObject <TestDomainBase> (); reloadedObject.ClassWithGuidKey.EnsureDataAvailable(); Assert.That(reloadedObject.ClassWithGuidKey.State, Is.Not.EqualTo(StateType.Invalid)); } // Note: See also NotFoundObjectsTest }
public void LoadObjectsOverRelationTest() { const int numberOfTests = 10; Console.WriteLine("Expected average duration of LoadObjectsOverRelationTest on reference system: ~230 ms (release build), ~313 ms (debug build)"); Stopwatch stopwatch = new Stopwatch(); for (int i = 0; i < numberOfTests; i++) { using (ClientTransaction.CreateRootTransaction().EnterScope(AutoRollbackBehavior.None)) { Client client = _clientID.GetObject <Client>(); stopwatch.Start(); DomainObjectCollection files = client.Files; stopwatch.Stop(); Assert.That(files.Count, Is.EqualTo(6000)); } } double averageMilliSeconds = stopwatch.ElapsedMilliseconds / numberOfTests; Console.WriteLine("LoadObjectsOverRelationTest (executed {0}x): Average duration: {1} ms", numberOfTests, averageMilliSeconds.ToString("n")); }
public void LoadObjectsWithSamePropertyNameInDifferentInheritanceBranches() { TIFolder rootFolder = _rootFolderID.GetObject <TIFolder> (); Assert.That(rootFolder.CreatedAt, Is.EqualTo(new DateTime(2006, 2, 1))); TIFile fileInRootFolder = _fileInRootFolderID.GetObject <TIFile> (); Assert.That(fileInRootFolder.CreatedAt, Is.EqualTo(new DateTime(2006, 2, 3))); }
public void CompositePatternNavigateOneToMany() { TIFolder rootFolder = _rootFolderID.GetObject <TIFolder> (); Assert.That(rootFolder.FileSystemItems.Count, Is.EqualTo(2)); Assert.That(rootFolder.FileSystemItems[0].ID, Is.EqualTo(_fileInRootFolderID)); Assert.That(rootFolder.FileSystemItems[1].ID, Is.EqualTo(_folder1ID)); TIFolder folder1 = _folder1ID.GetObject <TIFolder> (); Assert.That(folder1.FileSystemItems.Count, Is.EqualTo(1)); Assert.That(folder1.FileSystemItems[0].ID, Is.EqualTo(_fileInFolder1ID)); }
public void UnidirectionalRelationProperty_ShouldReturnInvalidObject() { SetDatabaseModifyable(); // Need to disable the foreign key constraints so that the property is allowed to point to an invalid ID in the database var clientTable = (TableDefinition)GetTypeDefinition(typeof(Client)).StorageEntityDefinition; DisableConstraints(clientTable); ObjectID clientID = null; try { clientID = CreateClientWithNonExistingParentClient(); var client = clientID.GetObject <Client> (); Client instance = null; Assert.That(() => instance = client.ParentClient, Throws.Nothing); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(() => instance.EnsureDataAvailable(), Throws.TypeOf <ObjectsNotFoundException>()); CheckObjectIsMarkedInvalid(instance.ID); } finally { if (clientID != null) { CleanupClientWithNonExistingParentClient(clientID); } EnableConstraints(clientTable); } }
public void ObjectHierarchyNavigateManyToOne() { DerivedClassWithEntityWithHierarchy derivedClassWithEntity2 = _derivedClassWithEntity2ID.GetObject <DerivedClassWithEntityWithHierarchy>(); Assert.That(derivedClassWithEntity2.ParentAbstractBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); Assert.That(derivedClassWithEntity2.ParentDerivedClassWithEntityWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); DerivedClassWithEntityWithHierarchy derivedClassWithEntity3 = _derivedClassWithEntity3ID.GetObject <DerivedClassWithEntityWithHierarchy>(); Assert.That(derivedClassWithEntity3.ParentAbstractBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); Assert.That(derivedClassWithEntity3.ParentDerivedClassWithEntityWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); DerivedClassWithEntityFromBaseClassWithHierarchy derivedClassWithEntityFromBaseClass1 = _derivedClassWithEntityFromBaseClass1ID.GetObject <DerivedClassWithEntityFromBaseClassWithHierarchy> (); Assert.That(derivedClassWithEntityFromBaseClass1.ParentAbstractBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); Assert.That(derivedClassWithEntityFromBaseClass1.ParentDerivedClassWithEntityWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity1ID)); DerivedClassWithEntityFromBaseClassWithHierarchy derivedClassWithEntityFromBaseClass2 = _derivedClassWithEntityFromBaseClass2ID.GetObject <DerivedClassWithEntityFromBaseClassWithHierarchy> (); Assert.That(derivedClassWithEntityFromBaseClass2.ParentAbstractBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity2ID)); Assert.That(derivedClassWithEntityFromBaseClass2.ParentDerivedClassWithEntityWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity2ID)); Assert.That(derivedClassWithEntityFromBaseClass2.ParentDerivedClassWithEntityFromBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass1ID)); DerivedClassWithEntityFromBaseClassWithHierarchy derivedClassWithEntityFromBaseClass3 = _derivedClassWithEntityFromBaseClass3ID.GetObject <DerivedClassWithEntityFromBaseClassWithHierarchy> (); Assert.That(derivedClassWithEntityFromBaseClass3.ParentAbstractBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity3ID)); Assert.That(derivedClassWithEntityFromBaseClass3.ParentDerivedClassWithEntityWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntity3ID)); Assert.That(derivedClassWithEntityFromBaseClass3.ParentDerivedClassWithEntityFromBaseClassWithHierarchy.ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass1ID)); }
public void SaveHierarchy() { Employee supervisor = Employee.NewObject(); Employee subordinate = Employee.NewObject(); ObjectID supervisorID = supervisor.ID; ObjectID subordinateID = subordinate.ID; supervisor.Name = "Slartibartfast"; subordinate.Name = "Zarniwoop"; supervisor.Subordinates.Add(subordinate); TestableClientTransaction.Commit(); ReInitializeTransaction(); supervisor = supervisorID.GetObject <Employee> (); subordinate = subordinateID.GetObject <Employee> (); Assert.That(supervisor, Is.Not.Null); Assert.That(subordinate, Is.Not.Null); Assert.That(supervisor.ID, Is.EqualTo(supervisorID)); Assert.That(subordinate.ID, Is.EqualTo(subordinateID)); Assert.That(supervisor.Name, Is.EqualTo("Slartibartfast")); Assert.That(subordinate.Name, Is.EqualTo("Zarniwoop")); }
public void OnLoadedInParentAndSubTransaction() { var id = new ObjectID("ClassWithAllDataTypes", new Guid("{3F647D79-0CAF-4a53-BAA7-A56831F8CE2D}")); ClassWithAllDataTypes classWithAllDataTypes = id.GetObject <ClassWithAllDataTypes> (); Assert.That(classWithAllDataTypes.OnLoadedCalled, Is.True); Assert.That(classWithAllDataTypes.OnLoadedCallCount, Is.EqualTo(1)); Assert.That(classWithAllDataTypes.OnLoadedLoadMode, Is.EqualTo(LoadMode.WholeDomainObjectInitialized)); using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { id.GetObject <ClassWithAllDataTypes> (); Assert.That(classWithAllDataTypes.OnLoadedCallCount, Is.EqualTo(2)); Assert.That(classWithAllDataTypes.OnLoadedLoadMode, Is.EqualTo(LoadMode.DataContainerLoadedOnly)); } }
private void ModifyAndCommitInOtherTransaction(ObjectID objectID) { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var domainObject = objectID.GetObject <ClassWithAllDataTypes> (); ++domainObject.Int32Property; ClientTransaction.Current.Commit(); } }
private void CleanupClientWithNonExistingParentClient(ObjectID clientID) { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var client = clientID.GetObject <Client> (); client.Delete(); ClientTransaction.Current.Commit(); } }
public void OnLoaded() { var id = new ObjectID("ClassWithAllDataTypes", new Guid("{3F647D79-0CAF-4a53-BAA7-A56831F8CE2D}")); ClassWithAllDataTypes classWithAllDataTypes = id.GetObject <ClassWithAllDataTypes> (); Assert.That(classWithAllDataTypes.OnLoadedCalled, Is.True); Assert.That(classWithAllDataTypes.OnLoadedCallCount, Is.EqualTo(1)); Assert.That(classWithAllDataTypes.OnLoadedLoadMode, Is.EqualTo(LoadMode.WholeDomainObjectInitialized)); }
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); }
protected void CheckIfObjectIsDeleted(ObjectID id) { try { DomainObject domainObject = id.GetObject <TestDomainBase> (includeDeleted: true); Assert.IsNull(domainObject, string.Format("Object '{0}' was not deleted.", id)); } catch (ObjectsNotFoundException) { } }
public void RootToSubDeletedThrowsWhenReloadingTheObject() { Order obj = GetDeleted(); ObjectID id = obj.ID; using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { Assert.That(obj.State, Is.EqualTo(StateType.Invalid)); id.GetObject <Order> (); } }
public bool MoveNext() { if (nextObjectId == null || nextObjectId.IsNull) { return(false); } Current = nextObjectId.GetObject(data); Current.ObjectID = nextObjectId; nextObjectId = new ObjectID(Current.NextObjectID); return(true); }
public void CompositePatternNavigateManyToOne() { TIFolder folder1 = _folder1ID.GetObject <TIFolder> (); Assert.That(folder1.ParentFolder.ID, Is.EqualTo(_rootFolderID)); TIFile fileInRootFolder = _fileInRootFolderID.GetObject <TIFile> (); Assert.That(fileInRootFolder.ParentFolder.ID, Is.EqualTo(_rootFolderID)); TIFile fileInFolder1 = _fileInFolder1ID.GetObject <TIFile> (); Assert.That(fileInFolder1.ParentFolder.ID, Is.EqualTo(_folder1ID)); }
public void GetObject_True_ShouldThrow_AndMarkObjectNotFound() { Assert.That(() => _nonExistingObjectID.GetObject <Order> (includeDeleted: true), ThrowsObjectNotFoundException(_nonExistingObjectID)); CheckObjectIsMarkedInvalid(_nonExistingObjectID); // After the object has been marked invalid Assert.That(() => _nonExistingObjectID.GetObject <Order> (includeDeleted: true), ThrowsObjectInvalidException(_nonExistingObjectID)); }
public void ObjectHierarchyNavigateOneToMany() { DerivedClassWithEntityWithHierarchy derivedClassWithEntity1 = _derivedClassWithEntity1ID.GetObject <DerivedClassWithEntityWithHierarchy>(); Assert.That(derivedClassWithEntity1.ChildAbstractBaseClassesWithHierarchy.Count, Is.EqualTo(3)); Assert.That(derivedClassWithEntity1.ChildAbstractBaseClassesWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntity3ID)); Assert.That(derivedClassWithEntity1.ChildAbstractBaseClassesWithHierarchy[1].ID, Is.EqualTo(_derivedClassWithEntity2ID)); Assert.That(derivedClassWithEntity1.ChildAbstractBaseClassesWithHierarchy[2].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass1ID)); Assert.That(derivedClassWithEntity1.ChildDerivedClassesWithEntityWithHierarchy.Count, Is.EqualTo(3)); Assert.That(derivedClassWithEntity1.ChildDerivedClassesWithEntityWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass1ID)); Assert.That(derivedClassWithEntity1.ChildDerivedClassesWithEntityWithHierarchy[1].ID, Is.EqualTo(_derivedClassWithEntity2ID)); Assert.That(derivedClassWithEntity1.ChildDerivedClassesWithEntityWithHierarchy[2].ID, Is.EqualTo(_derivedClassWithEntity3ID)); DerivedClassWithEntityWithHierarchy derivedClassWithEntity2 = _derivedClassWithEntity2ID.GetObject <DerivedClassWithEntityWithHierarchy>(); DerivedClassWithEntityWithHierarchy derivedClassWithEntity3 = _derivedClassWithEntity3ID.GetObject <DerivedClassWithEntityWithHierarchy>(); Assert.That(derivedClassWithEntity2.ChildAbstractBaseClassesWithHierarchy.Count, Is.EqualTo(1)); Assert.That(derivedClassWithEntity2.ChildAbstractBaseClassesWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass2ID)); Assert.That(derivedClassWithEntity2.ChildDerivedClassesWithEntityWithHierarchy.Count, Is.EqualTo(1)); Assert.That(derivedClassWithEntity2.ChildDerivedClassesWithEntityWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass2ID)); Assert.That(derivedClassWithEntity3.ChildAbstractBaseClassesWithHierarchy.Count, Is.EqualTo(1)); Assert.That(derivedClassWithEntity3.ChildAbstractBaseClassesWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass3ID)); Assert.That(derivedClassWithEntity3.ChildDerivedClassesWithEntityWithHierarchy.Count, Is.EqualTo(1)); Assert.That(derivedClassWithEntity3.ChildDerivedClassesWithEntityWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass3ID)); DerivedClassWithEntityFromBaseClassWithHierarchy derivedClassWithEntityFromBaseClass1 = _derivedClassWithEntityFromBaseClass1ID.GetObject <DerivedClassWithEntityFromBaseClassWithHierarchy> (); Assert.That(derivedClassWithEntityFromBaseClass1.ChildAbstractBaseClassesWithHierarchy, Is.Empty); Assert.That(derivedClassWithEntityFromBaseClass1.ChildDerivedClassesWithEntityWithHierarchy, Is.Empty); Assert.That(derivedClassWithEntityFromBaseClass1.ChildDerivedClassesWithEntityFromBaseClassWithHierarchy.Count, Is.EqualTo(2)); Assert.That(derivedClassWithEntityFromBaseClass1.ChildDerivedClassesWithEntityFromBaseClassWithHierarchy[0].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass2ID)); Assert.That(derivedClassWithEntityFromBaseClass1.ChildDerivedClassesWithEntityFromBaseClassWithHierarchy[1].ID, Is.EqualTo(_derivedClassWithEntityFromBaseClass3ID)); }
public void BidirectionalForeignKeyRelationProperty_ShouldReturnNotLoadedObject() { var id = new ObjectID(typeof(ClassWithInvalidRelation), new Guid("{AFA9CF46-8E77-4da8-9793-53CAA86A277C}")); var objectWithInvalidRelation = (ClassWithInvalidRelation)id.GetObject <TestDomainBase> (); DomainObject instance = null; Assert.That(() => instance = objectWithInvalidRelation.ClassWithGuidKey, Throws.Nothing); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(() => instance.EnsureDataAvailable(), Throws.TypeOf <ObjectsNotFoundException>()); CheckObjectIsMarkedInvalid(instance.ID); // Note: See also ObjectWithInvalidForeignKeyTest }
public void BidirectionalForeignKeyRelationProperty_Subtransaction() { DomainObject instance = null; using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { var id = new ObjectID(typeof(ClassWithInvalidRelation), new Guid("{AFA9CF46-8E77-4da8-9793-53CAA86A277C}")); var objectWithInvalidRelation = (ClassWithInvalidRelation)id.GetObject <TestDomainBase> (); Assert.That(() => instance = objectWithInvalidRelation.ClassWithGuidKey, Throws.Nothing); Assert.That(instance.State, Is.EqualTo(StateType.NotLoadedYet)); Assert.That(() => instance.EnsureDataAvailable(), Throws.TypeOf <ObjectsNotFoundException> ()); CheckObjectIsMarkedInvalid(instance.ID); } CheckObjectIsMarkedInvalid(instance.ID); }
public void Loading() { var newInstanceID = new ObjectID(typeof(SampleBindableDomainObject), Guid.NewGuid()); try { StubStorageProvider.LoadDataContainerResult = DataContainer.CreateNew(newInstanceID); { var instance = newInstanceID.GetObject <SampleBindableDomainObject>(); var implementation = (BindableDomainObjectImplementation)PrivateInvoke.GetNonPublicField(instance, "_implementation"); Assert.That(implementation, Is.Not.Null); Assert.That(implementation.BusinessObjectClass, Is.Not.Null); } } finally { StubStorageProvider.LoadDataContainerResult = null; } }
public void SaveExistingObjectWithRelatedNew() { Computer computer = DomainObjectIDs.Computer4.GetObject <Computer> (); Employee newEmployee = Employee.NewObject(); ObjectID newEmployeeID = newEmployee.ID; newEmployee.Computer = computer; newEmployee.Name = "Arthur Dent"; TestableClientTransaction.Commit(); ReInitializeTransaction(); computer = DomainObjectIDs.Computer4.GetObject <Computer> (); newEmployee = newEmployeeID.GetObject <Employee> (); Assert.That(newEmployee, Is.Not.Null); Assert.That(newEmployee.Name, Is.EqualTo("Arthur Dent")); Assert.That(newEmployee.Computer, Is.SameAs(computer)); }
public void CreateObjectsAndCommit() { SetDatabaseModifyable(); Client client1 = Client.NewObject(); Client client2 = Client.NewObject(); Location location = Location.NewObject(); SequenceEventReceiver eventReceiver = new SequenceEventReceiver(new DomainObject[] { location, client1, client2 }, new DomainObjectCollection[0]); location.Client = client1; Assert.That(client1.State, Is.EqualTo(StateType.New)); Assert.That(client2.State, Is.EqualTo(StateType.New)); Assert.That(location.State, Is.EqualTo(StateType.New)); ObjectID clientID1 = client1.ID; ObjectID clientID2 = client2.ID; ObjectID locationID = location.ID; ChangeState[] expectedStates = new ChangeState[] { new RelationChangeState(location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", null, client1, "1. Changing event of location"), new RelationChangeState(location, "Remotion.Data.DomainObjects.UnitTests.TestDomain.Location.Client", null, null, "2. Changed event of location") }; eventReceiver.Check(expectedStates); TestableClientTransaction.Commit(); using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { client1 = clientID1.GetObject <Client> (); client2 = clientID2.GetObject <Client> (); location = locationID.GetObject <Location>(); Assert.That(client1, Is.Not.Null); Assert.That(client2, Is.Not.Null); Assert.That(location, Is.Not.Null); Assert.That(location.Client, Is.SameAs(client1)); } }
public void GetObject_Subtransaction() { using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { Assert.That( () => _nonExistingObjectIDForSubtransaction.GetObject <TestDomainBase> (includeDeleted: true), ThrowsObjectInvalidException(_nonExistingObjectIDForSubtransaction)); CheckObjectIsMarkedInvalid(_nonExistingObjectIDForSubtransaction); Assert.That( () => _nonExistingObjectID.GetObject <TestDomainBase> (includeDeleted: true), ThrowsObjectNotFoundException(_nonExistingObjectID)); CheckObjectIsMarkedInvalid(_nonExistingObjectID); } CheckObjectIsMarkedInvalid(_nonExistingObjectID); CheckObjectIsNotMarkedInvalid(_nonExistingObjectIDForSubtransaction); }
public void CreateHierarchy() { SetDatabaseModifyable(); Client newClient1 = Client.NewObject(); Client newClient2 = Client.NewObject(); newClient2.ParentClient = newClient1; ObjectID newClientID1 = newClient1.ID; ObjectID newClientID2 = newClient2.ID; TestableClientTransaction.Commit(); using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { newClient1 = newClientID1.GetObject <Client> (); newClient2 = newClientID2.GetObject <Client> (); Assert.That(newClient1, Is.Not.Null); Assert.That(newClient2, Is.Not.Null); Assert.That(newClient2.ParentClient, Is.SameAs(newClient1)); } }
public void TestAllOperationsWithHierarchy() { Employee newSupervisor1 = Employee.NewObject(); ObjectID newSupervisor1ID = newSupervisor1.ID; Employee newSubordinate1 = Employee.NewObject(); ObjectID newSubordinate1ID = newSubordinate1.ID; newSubordinate1.Supervisor = newSupervisor1; Employee supervisor1 = DomainObjectIDs.Employee1.GetObject <Employee> (); Employee subordinate4 = DomainObjectIDs.Employee4.GetObject <Employee> (); Employee supervisor2 = DomainObjectIDs.Employee2.GetObject <Employee> (); Employee subordinate3 = DomainObjectIDs.Employee3.GetObject <Employee> (); supervisor2.Supervisor = supervisor1; supervisor2.Name = "New name of supervisor"; subordinate3.Name = "New name of subordinate"; Employee supervisor6 = DomainObjectIDs.Employee6.GetObject <Employee> (); Dev.Null = DomainObjectIDs.Employee7.GetObject <Employee> (); Employee newSubordinate2 = Employee.NewObject(); ObjectID newSubordinate2ID = newSubordinate2.ID; Employee newSubordinate3 = Employee.NewObject(); ObjectID newSubordinate3ID = newSubordinate3.ID; newSupervisor1.Supervisor = supervisor2; newSubordinate2.Supervisor = supervisor1; newSubordinate3.Supervisor = supervisor6; supervisor1.Delete(); subordinate4.Delete(); TestableClientTransaction.Commit(); ReInitializeTransaction(); newSupervisor1 = newSupervisor1ID.GetObject <Employee> (); newSubordinate1 = newSubordinate1ID.GetObject <Employee> (); Assert.That(newSubordinate1.Supervisor, Is.SameAs(newSupervisor1)); Assert.That(newSupervisor1.Subordinates.Contains(newSubordinate1ID), Is.True); supervisor2 = DomainObjectIDs.Employee2.GetObject <Employee> (); Assert.That(supervisor2.Supervisor, Is.Null); Assert.That(supervisor2.Name, Is.EqualTo("New name of supervisor")); subordinate3 = DomainObjectIDs.Employee3.GetObject <Employee> (); Assert.That(subordinate3.Supervisor, Is.SameAs(supervisor2)); Assert.That(supervisor2.Subordinates.Contains(DomainObjectIDs.Employee3), Is.True); Assert.That(subordinate3.Name, Is.EqualTo("New name of subordinate")); Assert.That(newSupervisor1.Supervisor, Is.SameAs(supervisor2)); Assert.That(supervisor2.Subordinates.Contains(newSupervisor1ID), Is.True); newSubordinate2 = newSubordinate2ID.GetObject <Employee> (); Assert.That(newSubordinate2.Supervisor, Is.Null); supervisor6 = DomainObjectIDs.Employee6.GetObject <Employee> (); newSubordinate3 = newSubordinate3ID.GetObject <Employee> (); Assert.That(newSubordinate3.Supervisor, Is.SameAs(supervisor6)); Assert.That(supervisor6.Subordinates.Contains(newSubordinate3ID), Is.True); CheckIfObjectIsDeleted(DomainObjectIDs.Employee1); CheckIfObjectIsDeleted(DomainObjectIDs.Employee4); }
public void TestAllOperations() { Order order1 = DomainObjectIDs.Order1.GetObject <Order> (); Order order3 = DomainObjectIDs.Order3.GetObject <Order> (); Customer customer1 = order1.Customer; Customer customer4 = DomainObjectIDs.Customer4.GetObject <Customer> (); Order order4 = customer4.Orders[DomainObjectIDs.Order4]; Dev.Null = customer4.Orders[DomainObjectIDs.Order5]; OrderTicket orderTicket1 = order1.OrderTicket; OrderTicket orderTicket3 = order3.OrderTicket; Official official1 = order1.Official; var orderItem1 = order1.OrderItems[DomainObjectIDs.OrderItem1]; var orderItem2 = order1.OrderItems[DomainObjectIDs.OrderItem2]; Dev.Null = order4.OrderItems[DomainObjectIDs.OrderItem4]; order1.Delete(); orderItem1.Delete(); orderItem2.Delete(); order4.OrderNumber = 7; Order newOrder = Order.NewObject(); ObjectID newOrderID = newOrder.ID; newOrder.DeliveryDate = DateTime.Now; newOrder.Official = official1; customer1.Orders.Add(newOrder); newOrder.OrderTicket = orderTicket1; orderTicket1.FileName = @"C:\NewFile.tif"; OrderItem newOrderItem1 = OrderItem.NewObject(); ObjectID newOrderItem1ID = newOrderItem1.ID; newOrderItem1.Position = 1; newOrder.OrderItems.Add(newOrderItem1); OrderItem newOrderItem2 = OrderItem.NewObject(); ObjectID newOrderItem2ID = newOrderItem2.ID; newOrderItem2.Position = 2; order4.OrderItems.Add(newOrderItem2); Customer newCustomer = Customer.NewObject(); ObjectID newCustomerID = newCustomer.ID; Ceo newCeo = Ceo.NewObject(); ObjectID newCeoID = newCeo.ID; newCustomer.Ceo = newCeo; order3.Customer = newCustomer; orderTicket3.FileName = @"C:\NewFile.gif"; Order deletedNewOrder = Order.NewObject(); deletedNewOrder.Delete(); TestableClientTransaction.Commit(); ReInitializeTransaction(); CheckIfObjectIsDeleted(DomainObjectIDs.Order1); CheckIfObjectIsDeleted(DomainObjectIDs.OrderItem1); CheckIfObjectIsDeleted(DomainObjectIDs.OrderItem2); order4 = DomainObjectIDs.Order4.GetObject <Order> (); Assert.That(order4.OrderNumber, Is.EqualTo(7)); newOrder = newOrderID.GetObject <Order> (); Assert.That(newOrder, Is.Not.Null); official1 = DomainObjectIDs.Official1.GetObject <Official>(); Assert.That(official1.Orders[newOrderID], Is.Not.Null); Assert.That(newOrder.Official, Is.SameAs(official1)); Assert.That(official1.Orders[DomainObjectIDs.Order1], Is.Null); orderTicket1 = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> (); Assert.That(orderTicket1.FileName, Is.EqualTo(@"C:\NewFile.tif")); Assert.That(orderTicket1.Order, Is.SameAs(newOrder)); Assert.That(newOrder.OrderTicket, Is.SameAs(orderTicket1)); newOrderItem1 = newOrderItem1ID.GetObject <OrderItem>(); Assert.That(newOrderItem1, Is.Not.Null); Assert.That(newOrderItem1.Position, Is.EqualTo(1)); Assert.That(newOrderItem1.Order, Is.SameAs(newOrder)); Assert.That(newOrder.OrderItems[newOrderItem1ID], Is.Not.Null); newOrderItem2 = newOrderItem2ID.GetObject <OrderItem>(); Assert.That(newOrderItem2, Is.Not.Null); Assert.That(newOrderItem2.Position, Is.EqualTo(2)); Assert.That(newOrderItem2.Order, Is.SameAs(order4)); Assert.That(order4.OrderItems[newOrderItem2ID], Is.Not.Null); newCustomer = newCustomerID.GetObject <Customer> (); newCeo = newCeoID.GetObject <Ceo> (); Assert.That(newCeo.Company, Is.SameAs(newCustomer)); Assert.That(newCustomer.Ceo, Is.SameAs(newCeo)); Assert.That(newCustomer.Orders.Contains(DomainObjectIDs.Order3), Is.True); Assert.That(newCustomer.Orders[DomainObjectIDs.Order3].Customer, Is.SameAs(newCustomer)); orderTicket3 = DomainObjectIDs.OrderTicket3.GetObject <OrderTicket> (); Assert.That(orderTicket3.FileName, Is.EqualTo(@"C:\NewFile.gif")); }
public void SaveNewRelatedObjects() { Ceo ceo = Ceo.NewObject(); Customer customer = Customer.NewObject(); Order order = Order.NewObject(); OrderTicket orderTicket = OrderTicket.NewObject(order); OrderItem orderItem = OrderItem.NewObject(); ObjectID ceoID = ceo.ID; ObjectID customerID = customer.ID; ObjectID orderID = order.ID; ObjectID orderTicketID = orderTicket.ID; ObjectID orderItemID = orderItem.ID; ceo.Name = "Ford Prefect"; customer.CustomerSince = new DateTime(2000, 1, 1); customer.Name = "Arthur Dent"; customer.Ceo = ceo; orderItem.Position = 1; orderItem.Product = "Sternenkarte"; orderTicket.FileName = @"C:\home\arthur_dent\maporder.png"; order.OrderNumber = 42; order.DeliveryDate = new DateTime(2005, 2, 1); order.Official = DomainObjectIDs.Official1.GetObject <Official>(); order.Customer = customer; order.OrderItems.Add(orderItem); Assert.That(ceo.InternalDataContainer.Timestamp, Is.Null); Assert.That(customer.InternalDataContainer.Timestamp, Is.Null); Assert.That(order.InternalDataContainer.Timestamp, Is.Null); Assert.That(orderTicket.InternalDataContainer.Timestamp, Is.Null); Assert.That(orderItem.InternalDataContainer.Timestamp, Is.Null); TestableClientTransaction.Commit(); ReInitializeTransaction(); ceo = ceoID.GetObject <Ceo> (); customer = customerID.GetObject <Customer> (); order = orderID.GetObject <Order> (); orderTicket = orderTicketID.GetObject <OrderTicket> (); orderItem = orderItemID.GetObject <OrderItem>(); Official official = DomainObjectIDs.Official1.GetObject <Official>(); Assert.That(ceo, Is.Not.Null); Assert.That(customer, Is.Not.Null); Assert.That(order, Is.Not.Null); Assert.That(orderTicket, Is.Not.Null); Assert.That(orderItem, Is.Not.Null); Assert.That(ceo.Company, Is.SameAs(customer)); Assert.That(customer.Ceo, Is.SameAs(ceo)); Assert.That(order.Customer, Is.SameAs(customer)); Assert.That(customer.Orders.Count, Is.EqualTo(1)); Assert.That(customer.Orders[0], Is.SameAs(order)); Assert.That(orderTicket.Order, Is.SameAs(order)); Assert.That(order.OrderTicket, Is.SameAs(orderTicket)); Assert.That(orderItem.Order, Is.SameAs(order)); Assert.That(order.OrderItems.Count, Is.EqualTo(1)); Assert.That(order.OrderItems[0], Is.SameAs(orderItem)); Assert.That(order.Official, Is.SameAs(official)); Assert.That(official.Orders.Count, Is.EqualTo(6)); Assert.That(official.Orders[orderID], Is.Not.Null); Assert.That(ceo.Name, Is.EqualTo("Ford Prefect")); Assert.That(customer.CustomerSince, Is.EqualTo(new DateTime(2000, 1, 1))); Assert.That(customer.Name, Is.EqualTo("Arthur Dent")); Assert.That(orderItem.Position, Is.EqualTo(1)); Assert.That(orderItem.Product, Is.EqualTo("Sternenkarte")); Assert.That(orderTicket.FileName, Is.EqualTo(@"C:\home\arthur_dent\maporder.png")); Assert.That(order.OrderNumber, Is.EqualTo(42)); Assert.That(order.DeliveryDate, Is.EqualTo(new DateTime(2005, 2, 1))); Assert.That(ceo.InternalDataContainer.Timestamp, Is.Not.Null); Assert.That(customer.InternalDataContainer.Timestamp, Is.Not.Null); Assert.That(order.InternalDataContainer.Timestamp, Is.Not.Null); Assert.That(orderTicket.InternalDataContainer.Timestamp, Is.Not.Null); Assert.That(orderItem.InternalDataContainer.Timestamp, Is.Not.Null); }
public void GetObject_LoadsObjectIntoGivenTransaction() { var result = _orderID1.GetObject <Order> (_clientTransaction); CheckDomainObject(result, _clientTransaction, expectedID: _orderID1, expectedState: StateType.Unchanged); }