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 ObjectValuesCanBeChangedInParentAndChildSubTransactions() { SetDatabaseModifyable(); ClassWithAllDataTypes cwadt = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); Assert.That(cwadt.Int32Property, Is.Not.EqualTo(7)); Assert.That(cwadt.Int16Property, Is.Not.EqualTo(8)); using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { cwadt.Int32Property = 7; using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { Assert.That(cwadt.Int32Property, Is.EqualTo(7)); cwadt.Int16Property = 8; ClientTransaction.Current.Commit(); } Assert.That(cwadt.Int32Property, Is.EqualTo(7)); Assert.That(cwadt.Int16Property, Is.EqualTo(8)); ClientTransaction.Current.Commit(); } Assert.That(cwadt.Int32Property, Is.EqualTo(7)); Assert.That(cwadt.Int16Property, Is.EqualTo(8)); TestableClientTransaction.Commit(); using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var objectInThisTransaction = cwadt.GetHandle().GetObject(); Assert.That(objectInThisTransaction.Int32Property, Is.EqualTo(7)); Assert.That(objectInThisTransaction.Int16Property, Is.EqualTo(8)); } }
public void InvalidStateType() { ClassWithAllDataTypes newObject = ClassWithAllDataTypes.NewObject(); DataContainer newObjectDataContainer = newObject.InternalDataContainer; ClassWithAllDataTypes loadedObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); DataContainer loadedObjectDataContainer = newObject.InternalDataContainer; Assert.That(newObject.IsInvalid, Is.False); Assert.That(newObject.State, Is.EqualTo(StateType.New)); Assert.That(loadedObject.IsInvalid, Is.False); Assert.That(loadedObject.State, Is.EqualTo(StateType.Unchanged)); newObject.Delete(); Assert.That(newObject.IsInvalid, Is.True); Assert.That(newObject.State, Is.EqualTo(StateType.Invalid)); Assert.That(newObjectDataContainer.IsDiscarded, Is.True); Assert.That(newObjectDataContainer.State, Is.EqualTo(StateType.Invalid)); loadedObject.Delete(); TestableClientTransaction.Commit(); Assert.That(loadedObject.IsInvalid, Is.True); Assert.That(loadedObject.State, Is.EqualTo(StateType.Invalid)); Assert.That(loadedObjectDataContainer.IsDiscarded, Is.True); Assert.That(loadedObjectDataContainer.State, Is.EqualTo(StateType.Invalid)); }
public void GetObjects_Discarded() { SetDatabaseModifyable(); DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ().Delete(); TestableClientTransaction.Commit(); LifetimeService.GetObjects <ClassWithAllDataTypes> (TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1); }
public void UnloadCollectionEndPoint_WithoutReferences_AfterSettingDifferentCollection_AndCommit_CausesEndPointToBeRemoved_ButKeepsDomainObjectCollectionInMemory() { SetDatabaseModifyable(); var customer = DomainObjectIDs.Customer2.GetObject <Customer> (); var newCustomerOrders = new OrderCollection(); customer.Orders = newCustomerOrders; Assert.That(customer.Orders, Is.Empty); TestableClientTransaction.Commit(); 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 new collection Assert.That(newCustomerOrders, Is.SameAs(customer.Orders)); }
public void ModifyOtherObjectInDomainObjectCommitting() { var ceo = _customer.Ceo; _customer.Name = "New name"; _customer.Committing += (sender, e) => ceo.Name = "New CEO name"; var ceoEventReceiver = new DomainObjectEventReceiver(ceo); var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); TestableClientTransaction.Commit(); Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2)); Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1)); var committingDomainObjects1 = clientTransactionEventReceiver.CommittingDomainObjectLists[0]; var committingDomainObjects2 = clientTransactionEventReceiver.CommittingDomainObjectLists[1]; var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0]; Assert.That(committingDomainObjects1, Is.EqualTo(new[] { _customer })); Assert.That(committingDomainObjects2, Is.EqualTo(new[] { ceo })); Assert.That(committedDomainObjects, Is.EquivalentTo(new DomainObject[] { _customer, ceo })); }
public void ConcurrencyViolationException_WhenSomebodyElseRegistersForCommit() { SetDatabaseModifyable(); var computer = DomainObjectIDs.Computer1.GetObject <Computer> (); computer.RegisterForCommit(); using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var computerInOtherTransaction = DomainObjectIDs.Computer1.GetObject <Computer> (); computerInOtherTransaction.RegisterForCommit(); ClientTransaction.Current.Commit(); } try { TestableClientTransaction.Commit(); Assert.Fail("Expected ConcurrencyViolationException"); } catch (ConcurrencyViolationException) { // succeed } }
public void ModifyOtherObjectInClientTransactionCommitting() { _customer.Name = "New name"; TestableClientTransaction.Committing += ClientTransaction_CommittingForModifyOtherObjectInClientTransactionCommitting; Ceo ceo = _customer.Ceo; var ceoEventReceiver = new DomainObjectEventReceiver(ceo); var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); TestableClientTransaction.Commit(); Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2)); Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1)); var committingDomainObjectsForFirstCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[0]; var committingDomainObjectsForSecondCommit = clientTransactionEventReceiver.CommittingDomainObjectLists[1]; var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0]; Assert.That(committingDomainObjectsForFirstCommitEvent.Count, Is.EqualTo(1)); Assert.That(committingDomainObjectsForSecondCommit.Count, Is.EqualTo(1)); Assert.That(committedDomainObjects.Count, Is.EqualTo(2)); Assert.That(committingDomainObjectsForFirstCommitEvent.Contains(_customer), Is.True); Assert.That(committingDomainObjectsForFirstCommitEvent.Contains(ceo), Is.False); Assert.That(committingDomainObjectsForSecondCommit.Contains(_customer), Is.False); Assert.That(committingDomainObjectsForSecondCommit.Contains(ceo), Is.True); Assert.That(committedDomainObjects.Contains(_customer), Is.True); Assert.That(committedDomainObjects.Contains(ceo), Is.True); }
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 CommitTwice() { Order order = DomainObjectIDs.Order1.GetObject <Order> (); OrderTicket oldOrderTicket = DomainObjectIDs.OrderTicket1.GetObject <OrderTicket> (); OrderTicket newOrderTicket = DomainObjectIDs.OrderTicket2.GetObject <OrderTicket> (); oldOrderTicket.Order = newOrderTicket.Order; order.OrderTicket = newOrderTicket; TestableClientTransaction.Commit(); Assert.That(TestableClientTransaction.IsDiscarded, Is.False); object orderTimestamp = order.InternalDataContainer.Timestamp; object oldOrderTicketTimestamp = oldOrderTicket.InternalDataContainer.Timestamp; object newOrderTicketTimestamp = newOrderTicket.InternalDataContainer.Timestamp; TestableClientTransaction.Commit(); Assert.That(TestableClientTransaction.IsDiscarded, Is.False); Assert.That(order.InternalDataContainer.Timestamp, Is.EqualTo(orderTimestamp)); Assert.That(oldOrderTicket.InternalDataContainer.Timestamp, Is.EqualTo(oldOrderTicketTimestamp)); Assert.That(newOrderTicket.InternalDataContainer.Timestamp, Is.EqualTo(newOrderTicketTimestamp)); }
public void ClientTransactionEventsTriggeredInRightTransaction() { var mock = new TestableClientTransaction(); int events = 0; // ReSharper disable AccessToModifiedClosure mock.Committed += delegate { ++events; Assert.That(ClientTransactionScope.CurrentTransaction, Is.SameAs(mock)); }; mock.Committing += delegate { ++events; Assert.That(ClientTransactionScope.CurrentTransaction, Is.SameAs(mock)); }; mock.Loaded += delegate { ++events; Assert.That(ClientTransactionScope.CurrentTransaction, Is.SameAs(mock)); }; mock.RolledBack += delegate { ++events; Assert.That(ClientTransactionScope.CurrentTransaction, Is.SameAs(mock)); }; mock.RollingBack += delegate { ++events; Assert.That(ClientTransactionScope.CurrentTransaction, Is.SameAs(mock)); }; // ReSharper restore AccessToModifiedClosure Assert.That(events, Is.EqualTo(0)); mock.GetObject(DomainObjectIDs.Order1, false); Assert.That(events, Is.EqualTo(1)); // loaded events = 0; mock.Commit(); Assert.That(events, Is.EqualTo(2)); // committing, committed events = 0; mock.Rollback(); Assert.That(events, Is.EqualTo(2)); // rollingback, rolledback }
public void DataContainerStateAfterCommit() { Computer computer = Computer.NewObject(); TestableClientTransaction.Commit(); Assert.That(computer.State, Is.EqualTo(StateType.Unchanged)); }
private void CheckValueAfterCommitAndRollback(Computer computer, DateTime referenceDateTime, Employee referenceEmployee) { TestableClientTransaction.Commit(); CheckPropertiesAfterSet(computer, referenceDateTime, referenceEmployee); TestableClientTransaction.Rollback(); CheckPropertiesAfterSet(computer, referenceDateTime, referenceEmployee); }
private void CommitTransactionAndCheckTimestamps(params DomainObject[] domainObjects) { var timestampsBefore = domainObjects.Select(obj => obj.Timestamp).ToArray(); TestableClientTransaction.Commit(); var timestampsAfter = domainObjects.Select(obj => obj.Timestamp).ToArray(); Assert.That(timestampsBefore, Is.Not.EqualTo(timestampsAfter)); }
public void CommitDeletedObject() { Computer computer = DomainObjectIDs.Computer1.GetObject <Computer> (); computer.Delete(); TestableClientTransaction.Commit(); Assert.That(() => DomainObjectIDs.Computer1.GetObject <Computer> (), Throws.TypeOf <ObjectInvalidException>()); }
public void CommitWithOptionalOneToOneRelationNotSet() { SetDatabaseModifyable(); Employee employee = DomainObjectIDs.Employee3.GetObject<Employee> (); employee.Computer = null; Assert.That (() => TestableClientTransaction.Commit(), Throws.Nothing); }
public void AccessDeletedObjectAfterCommit() { Computer computer = DomainObjectIDs.Computer1.GetObject <Computer> (); computer.Delete(); TestableClientTransaction.Commit(); Assert.That(() => Dev.Null = computer.SerialNumber, Throws.TypeOf <ObjectInvalidException> ()); }
public void CommitWithValidProperties() { SetDatabaseModifyable(); var newObject = CreateClassWithAllDataTypes(); newObject.StringWithNullValueProperty = null; newObject.NullableBinaryProperty = null; Assert.That (() => TestableClientTransaction.Commit(), Throws.Nothing); }
public void CommitWithMandatoryOneToManyRelationNotSet() { IndustrialSector industrialSector = DomainObjectIDs.IndustrialSector2.GetObject<IndustrialSector> (); industrialSector.Companies.Clear(); Assert.That ( () => TestableClientTransaction.Commit(), Throws.TypeOf<MandatoryRelationNotSetException>().With.Message.EqualTo ( "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.IndustrialSector.Companies' of domain object" + " 'IndustrialSector|8565a077-ea01-4b5d-beaa-293dc484bddc|System.Guid' contains no items.")); }
public void CommitRoot_RegisterForUnchanged_LeadsToConcurrencyCheck() { var unchangedObject = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> (); unchangedObject.RegisterForCommit(); SetDatabaseModifyable(); ModifyAndCommitInOtherTransaction(unchangedObject.ID); Assert.That(() => TestableClientTransaction.Commit(), Throws.TypeOf <ConcurrencyViolationException>()); }
public void DeleteNewObjectsInClientTransactionsCommittingEvent() { _newOrder.Committing += (sender, args) => Assert.Fail("Should not be called."); _newOrderTicket.Committing += (sender1, args1) => Assert.Fail("Should not be called."); TestableClientTransaction.Committing += (sender2, args2) => { _newOrder.Delete(); _newOrderTicket.Delete(); }; TestableClientTransaction.Commit(); }
public void CommitPropertyChange() { Customer customer = DomainObjectIDs.Customer1.GetObject <Customer> (); customer.Name = "Arthur Dent"; TestableClientTransaction.Commit(); ReInitializeTransaction(); customer = DomainObjectIDs.Customer1.GetObject <Customer> (); Assert.That(customer.Name, Is.EqualTo("Arthur Dent")); }
public void HasBeenTouchedWithNullTwice_VirtualSide() { Employee employee = DomainObjectIDs.Employee3.GetObject <Employee> (); employee.Computer = null; SetDatabaseModifyable(); TestableClientTransaction.Commit(); CheckTouching(delegate { employee.Computer = null; }, null, null, RelationEndPointID.Create(employee.ID, typeof(Employee).FullName + ".Computer")); }
public void PropertyValueHasBeenTouchedAfterCommit() { Employee employee = Employee.NewObject(); employee.Name = "Mr. Prosser"; Assert.That(employee.InternalDataContainer.HasValueBeenTouched(GetPropertyDefinition(typeof(Employee), "Name")), Is.True); TestableClientTransaction.Commit(); Assert.That(employee.InternalDataContainer.HasValueBeenTouched(GetPropertyDefinition(typeof(Employee), "Name")), Is.False); }
public void DeleteNewObjectsInDomainObjectsCommittingEvent() { _newOrder.Committing += (o, args) => { _newOrder.Delete(); _newOrderTicket.Delete(); }; _newOrderTicket.Committing += (o, args) => Assert.Fail("NewOrderTicket_Committing event should not be raised."); TestableClientTransaction.Committing += (sender, args1) => Assert.That(args1.DomainObjects.Count, Is.EqualTo(2)); TestableClientTransaction.Commit(); }
public void ModifyOtherObjects() { _customer.Name = "New name"; Ceo ceo = _customer.Ceo; ceo.Name = "New CEO name"; Order order = _customer.Orders[DomainObjectIDs.Order1]; IndustrialSector industrialSector = _customer.IndustrialSector; var ceoEventReceiver = new DomainObjectEventReceiver(ceo); var customerEventReceiver = new DomainObjectEventReceiver(_customer); var orderEventReceiver = new DomainObjectEventReceiver(order); var industrialSectorEventReceiver = new DomainObjectEventReceiver(industrialSector); var clientTransactionEventReceiver = new ClientTransactionEventReceiver(TestableClientTransaction); _customer.Committing += (sender, e) => order.OrderNumber = 1000; TestableClientTransaction.Committing += (sender1, args) => { var customer = (Customer)args.DomainObjects.SingleOrDefault(obj => obj.ID == DomainObjectIDs.Customer1); if (customer != null) { customer.IndustrialSector.Name = "New industrial sector name"; } }; TestableClientTransaction.Commit(); Assert.That(ceoEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(ceoEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(customerEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(customerEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(orderEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(orderEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(industrialSectorEventReceiver.HasCommittingEventBeenCalled, Is.True); Assert.That(industrialSectorEventReceiver.HasCommittedEventBeenCalled, Is.True); Assert.That(clientTransactionEventReceiver.CommittingDomainObjectLists.Count, Is.EqualTo(2)); Assert.That(clientTransactionEventReceiver.CommittedDomainObjectLists.Count, Is.EqualTo(1)); var committingDomainObjectsForFirstCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[0]; var committingDomainObjectsForSecondCommitEvent = clientTransactionEventReceiver.CommittingDomainObjectLists[1]; var committedDomainObjects = clientTransactionEventReceiver.CommittedDomainObjectLists[0]; Assert.That(committingDomainObjectsForFirstCommitEvent, Is.EquivalentTo(new DomainObject[] { _customer, ceo })); Assert.That(committingDomainObjectsForSecondCommitEvent, Is.EquivalentTo(new DomainObject[] { order, industrialSector })); Assert.That(committedDomainObjects, Is.EquivalentTo(new DomainObject[] { _customer, ceo, order, industrialSector })); }
public void OriginalDomainObjectCollection_IsNotSameAfterCommit() { Order order = DomainObjectIDs.Order1.GetObject <Order> (); DomainObjectCollection originalOrderItems = order.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems"); OrderItem.NewObject(order); TestableClientTransaction.Commit(); Assert.That(order.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems"), Is.Not.SameAs(originalOrderItems)); Assert.That(order.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems"), Is.EqualTo(order.OrderItems)); Assert.That(order.GetOriginalRelatedObjects("Remotion.Data.DomainObjects.UnitTests.TestDomain.Order.OrderItems").IsReadOnly, Is.True); }
public void CommitWithMandatoryOneToOneRelationNotSet() { Order order = DomainObjectIDs.Order1.GetObject<Order> (); OrderTicket newOrderTicket = DomainObjectIDs.OrderTicket2.GetObject<OrderTicket> (); order.OrderTicket = newOrderTicket; Assert.That ( () => TestableClientTransaction.Commit(), Throws.TypeOf<MandatoryRelationNotSetException>().With.Message.EqualTo ( "Mandatory relation property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.OrderTicket.Order' of domain object" + " 'OrderTicket|058ef259-f9cd-4cb1-85e5-5c05119ab596|System.Guid' cannot be null.")); }
public void HasBeenTouchedWithNullTwice_RealSide() { Employee employee = DomainObjectIDs.Employee3.GetObject <Employee> (); Computer computer = employee.Computer; computer.Employee = null; SetDatabaseModifyable(); TestableClientTransaction.Commit(); CheckTouching(delegate { computer.Employee = null; }, computer, "Employee", RelationEndPointID.Create(computer.ID, typeof(Computer).FullName + ".Employee")); }
public void CommitWithOptionalOneToManyRelationNotSet() { SetDatabaseModifyable(); var customer = DomainObjectIDs.Customer1.GetObject<Customer> (); foreach (var order in customer.Orders.ToArray()) { order.Customer = DomainObjectIDs.Customer2.GetObject<Customer> (); } Assert.That (customer.Orders, Is.Empty); Assert.That (() => TestableClientTransaction.Commit(), Throws.Nothing); }