public void TryGetObject_Deleted() { var domainObject = LifetimeService.GetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false); LifetimeService.DeleteObject(TestableClientTransaction, domainObject); Assert.That(LifetimeService.TryGetObject(TestableClientTransaction, domainObject.ID), Is.SameAs(domainObject)); }
public void TryGetObject() { var order = (Order)LifetimeService.TryGetObject(TestableClientTransaction, DomainObjectIDs.Order1); Assert.That(order, Is.Not.Null); Assert.That(order.ID, Is.EqualTo(DomainObjectIDs.Order1)); Assert.That(order.CtorCalled, Is.False); }
public void TryGetObject_Invalid() { var domainObject = ClassWithAllDataTypes.NewObject(); domainObject.Delete(); Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid)); Assert.That(LifetimeService.TryGetObject(TestableClientTransaction, domainObject.ID), Is.SameAs(domainObject)); }
public void TryGetObject_Deleted() { var order = DomainObjectIDs.Order1.GetObject <Order> (); order.Delete(); var orderAgain = LifetimeService.TryGetObject(TestableClientTransaction, DomainObjectIDs.Order1); Assert.That(orderAgain, Is.SameAs(order)); }
public void TryGetObject_NotFound() { var id = new ObjectID(typeof(Order), Guid.NewGuid()); Assert.That(TestableClientTransaction.IsInvalid(id), Is.False); var result = LifetimeService.TryGetObject(TestableClientTransaction, id); Assert.That(result, Is.Null); Assert.That(TestableClientTransaction.IsInvalid(id), Is.True); }
public void TryGetObject_Invalid() { var instance = Order.NewObject(); instance.Delete(); Assert.That(instance.State, Is.EqualTo(StateType.Invalid)); var instanceAgain = LifetimeService.TryGetObject(TestableClientTransaction, instance.ID); Assert.That(instanceAgain, Is.SameAs(instance)); }
public void TryGetObject_NotFound() { var notFoundID = new ObjectID(typeof(Order), Guid.NewGuid()); var domainObject = LifetimeService.TryGetObject(TestableClientTransaction, notFoundID); Assert.That(domainObject, Is.Null); domainObject = LifetimeService.TryGetObject(TestableClientTransaction, notFoundID); Assert.That(domainObject, Is.Not.Null); Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid)); }
public void TryGetObject_Twice() { DomainObject domainObject1 = LifetimeService.TryGetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1); Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(1)); var domainObjects = _eventReceiver.LoadedDomainObjectLists[0]; Assert.That(domainObjects.Count, Is.EqualTo(1)); Assert.That(domainObjects[0], Is.SameAs(domainObject1)); _eventReceiver.Clear(); DomainObject domainObject2 = LifetimeService.TryGetObject(TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1); Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(0)); Assert.That(domainObject2, Is.SameAs(domainObject1)); }
public IBusinessObjectWithIdentity GetObject(BindableObjectClassWithIdentity classWithIdentity, string uniqueIdentifier) { ArgumentUtility.CheckNotNull("classWithIdentity", classWithIdentity); ArgumentUtility.CheckNotNullOrEmpty("uniqueIdentifier", uniqueIdentifier); var objectID = ObjectID.Parse(uniqueIdentifier); var domainObjectOrNull = LifetimeService.TryGetObject(ClientTransaction.Current, objectID); if (domainObjectOrNull == null) { return(null); } if (domainObjectOrNull.State == StateType.Invalid) { return(null); } if (domainObjectOrNull.State == StateType.Deleted) { return(null); } return((IBusinessObjectWithIdentity)domainObjectOrNull); }
/// <summary> /// Gets a <see cref="DomainObject"/> that already exists or attempts to load it from the data source. /// If an object cannot be found, it will be marked <see cref="StateType.Invalid"/> in the <paramref name="clientTransaction"/>, and the method will /// return a <see langword="null" /> reference in its place. /// </summary> /// <typeparam name="T">The type of <see cref="DomainObject"/> to return. Can be a base type of the actual object type.</typeparam> /// <param name="handle">A handle to the <see cref="DomainObject"/> that should be loaded. Must not be <see langword="null"/>.</param> /// <param name="clientTransaction">The <see cref="ClientTransaction"/>. If <see langword="null" /> (or unspecified), the /// <see cref="ClientTransaction.Current"/> transaction is used.</param> /// <returns> /// The <see cref="DomainObject"/> with the specified <paramref name="handle"/>, or <see langword="null" /> if it couldn't be found. /// </returns> /// <exception cref="System.ArgumentNullException"><paramref name="clientTransaction"/> or <paramref name="handle"/> are <see langword="null"/>.</exception> /// <exception cref="Persistence.StorageProviderException"> /// The Mapping does not contain a class definition for the given <paramref name="handle"/>.<br/> -or- <br/> /// An error occurred while reading a <see cref="PropertyValue"/>.<br/> -or- <br/> /// An error occurred while accessing the data source. /// </exception> public static T TryGetObject <T> ([NotNull] this IDomainObjectHandle <T> handle, ClientTransaction clientTransaction = null) where T : DomainObject, ISupportsGetObject { ArgumentUtility.CheckNotNull("handle", handle); return((T)LifetimeService.TryGetObject(GetMandatoryClientTransaction(clientTransaction), handle.ObjectID)); }