public void GetObjects_LoadedObjects_Events() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var eventReceiver = new ClientTransactionEventReceiver(subTransaction); DomainObjectIDs.Order1.GetObject <Order> (); DomainObjectIDs.Order3.GetObject <Order> (); DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); eventReceiver.Clear(); var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); PrivateInvoke.InvokeNonPublicMethod(subTransaction, "AddListener", listenerMock); LifetimeService.GetObjects <DomainObject> (subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(eventReceiver.LoadedDomainObjectLists, Is.Empty); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoading( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <ObjectID> > .Is.Anything)); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoaded( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything)); } }
public void GetObjects_UnloadedObjects_Events() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); PrivateInvoke.InvokeNonPublicMethod(subTransaction, "AddListener", listenerMock); var eventReceiver = new ClientTransactionEventReceiver(subTransaction); DomainObject[] objects = LifetimeService.GetObjects <DomainObject> ( subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(1)); Assert.That(eventReceiver.LoadedDomainObjectLists[0], Is.EqualTo(objects)); listenerMock.AssertWasCalled(mock => mock.ObjectsLoading( Arg.Is(subTransaction), Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 }))); listenerMock.AssertWasCalled(mock => mock.ObjectsLoaded( Arg.Is(subTransaction), Arg <ReadOnlyCollection <DomainObject> > .List.Equal(objects))); } }
public void GetObjects_Discarded() { SetDatabaseModifyable(); DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ().Delete(); TestableClientTransaction.Commit(); LifetimeService.GetObjects <ClassWithAllDataTypes> (TestableClientTransaction, DomainObjectIDs.ClassWithAllDataTypes1); }
public void SpecialStrategy() { TransportItem[] items; using (ClientTransaction.CreateRootTransaction().EnterNonDiscardingScope()) { items = new[] { TransportItem.PackageDataContainer(DomainObjectIDs.Order1.GetObject <Order> ().InternalDataContainer) }; } var repository = new MockRepository(); var strategyMock = repository.StrictMock <IImportStrategy>(); var streamFake = repository.Stub <Stream> (); strategyMock.Expect(mock => mock.Import(streamFake)).Return(items); strategyMock.Replay(); var importer = DomainObjectImporter.CreateImporterFromStream(streamFake, strategyMock); TransportedDomainObjects result = importer.GetImportedObjects(); Assert.That( result.TransportedObjects, Is.EquivalentTo(LifetimeService.GetObjects <Order> (result.DataTransaction, DomainObjectIDs.Order1))); strategyMock.VerifyAllExpectations(); }
public void GetObjects_UnloadedObjects_PropagatedToParent() { ClientTransaction parent = ClientTransaction.CreateRootTransaction(); ClientTransaction subTransaction = parent.CreateSubTransaction(); LifetimeService.GetObject(subTransaction, DomainObjectIDs.ClassWithAllDataTypes1, false); // preload ClassWithAllDataTypes var extensionMock = MockRepository.GenerateMock <IClientTransactionExtension> (); extensionMock.Stub(stub => stub.Key).Return("mock"); parent.Extensions.Add(extensionMock); LifetimeService.GetObjects <DomainObject> ( subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.ClassWithAllDataTypes1, // this has already been loaded DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); extensionMock.AssertWasCalled(mock => mock.ObjectsLoading(Arg.Is(parent), Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 }))); extensionMock.AssertWasNotCalled(mock => mock.ObjectsLoading(Arg.Is(parent), Arg <ReadOnlyCollection <ObjectID> > .List.ContainsAll(new[] { DomainObjectIDs.ClassWithAllDataTypes1 }))); }
public void GetObjects_NewObjects() { var expectedObjects = new DomainObject[] { Order.NewObject(), OrderItem.NewObject() }; DomainObject[] objects = LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, expectedObjects[0].ID, expectedObjects[1].ID); Assert.That(objects, Is.EqualTo(expectedObjects)); }
public void GetObjects_InvalidType() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { LifetimeService.GetObjects <OrderItem> (subTransaction, DomainObjectIDs.Order1); } }
public void GetObjects_WithInvalidObject_Throws() { var order = Order.NewObject(); order.Delete(); Assert.That(order.State, Is.EqualTo(StateType.Invalid)); Assert.That(() => LifetimeService.GetObjects <Order> (TestableClientTransaction, order.ID), Throws.TypeOf <ObjectInvalidException> ()); }
public void GetObjects_Deleted() { var order = DomainObjectIDs.Order1.GetObject <Order> (); order.Delete(); var result = LifetimeService.GetObjects <Order> (TestableClientTransaction, DomainObjectIDs.Order1); Assert.That(result[0], Is.SameAs(order)); }
public void GetObjects_NotFound() { var guid = new Guid("33333333333333333333333333333333"); ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { LifetimeService.GetObjects <DomainObject> (subTransaction, new ObjectID(typeof(Order), guid)); } }
public void GetObjects_NewObjects() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var expectedObjects = new DomainObject[] { Order.NewObject(), OrderItem.NewObject() }; DomainObject[] objects = LifetimeService.GetObjects <DomainObject> (subTransaction, expectedObjects[0].ID, expectedObjects[1].ID); Assert.That(objects, Is.EqualTo(expectedObjects)); } }
public void GetObjects_Invalid_Throws() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> ().Delete(); subTransaction.Commit(); LifetimeService.GetObjects <ClassWithAllDataTypes> (subTransaction, DomainObjectIDs.ClassWithAllDataTypes1); } }
public void GetObjects() { var deletedObjectID = DomainObjectIDs.Order4; var deletedObject = deletedObjectID.GetObject <Order> (); deletedObject.Delete(); Order[] orders = LifetimeService.GetObjects <Order> (TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, deletedObjectID); Assert.That(orders, Is.EqualTo(new[] { DomainObjectIDs.Order1.GetObject <Order> (), DomainObjectIDs.Order3.GetObject <Order> (), deletedObject })); }
public void GetObjects_LoadedObjects() { var expectedObjects = new object[] { DomainObjectIDs.Order1.GetObject <Order> (), DomainObjectIDs.Order3.GetObject <Order> (), DomainObjectIDs.OrderItem1.GetObject <OrderItem>() }; DomainObject[] objects = LifetimeService.GetObjects <DomainObject> ( TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(objects, Is.EqualTo(expectedObjects)); }
public void GetObjects_Deleted() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var order = DomainObjectIDs.Order1.GetObject <Order> (); order.Delete(); var result = LifetimeService.GetObjects <Order> (subTransaction, DomainObjectIDs.Order1); Assert.That(result[0], Is.SameAs(order)); } }
public void GetObjects_DeletedInParentTransaction_Throws() { var order1 = DomainObjectIDs.Order1.GetObject <Order> (); var order3 = DomainObjectIDs.Order3.GetObject <Order> (); var order4 = DomainObjectIDs.Order4.GetObject <Order> (); order3.Delete(); order4.Delete(); ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { Assert.That( () => LifetimeService.GetObjects <Order> (subTransaction, order1.ID, order3.ID, order4.ID), Throws.TypeOf <ObjectInvalidException> ().With.Message.EqualTo( "Object 'Order|83445473-844a-4d3f-a8c3-c27f8d98e8ba|System.Guid' is invalid in this transaction.")); } }
public void GetObjects_LoadedObjects() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var expectedObjects = new object[] { DomainObjectIDs.Order1.GetObject <Order> (), DomainObjectIDs.Order3.GetObject <Order> (), DomainObjectIDs.OrderItem1.GetObject <OrderItem>() }; DomainObject[] objects = LifetimeService.GetObjects <DomainObject> ( subTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(objects, Is.EqualTo(expectedObjects)); } }
public void GetObjects_NewObjects_Events() { var expectedObjects = new DomainObject[] { Order.NewObject(), OrderItem.NewObject() }; _eventReceiver.Clear(); var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); TestableClientTransaction.AddListener(listenerMock); LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, expectedObjects[0].ID, expectedObjects[1].ID); Assert.That(_eventReceiver.LoadedDomainObjectLists, Is.Empty); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoading( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <ObjectID> > .Is.Anything)); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoaded( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything)); }
public void GetObjects_UnloadedObjects_Events() { var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); TestableClientTransaction.AddListener(listenerMock); DomainObject[] objects = LifetimeService.GetObjects <DomainObject> ( TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(_eventReceiver.LoadedDomainObjectLists.Count, Is.EqualTo(1)); Assert.That(_eventReceiver.LoadedDomainObjectLists[0], Is.EqualTo(objects)); listenerMock.AssertWasCalled(mock => mock.ObjectsLoading( Arg.Is(TestableClientTransaction), Arg <ReadOnlyCollection <ObjectID> > .List.Equal(new[] { DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1 }))); listenerMock.AssertWasCalled(mock => mock.ObjectsLoaded( Arg.Is(TestableClientTransaction), Arg <ReadOnlyCollection <DomainObject> > .List.Equal(objects))); }
public void GetObjects_LoadedObjects_Events() { DomainObjectIDs.Order1.GetObject <Order> (); DomainObjectIDs.Order3.GetObject <Order> (); DomainObjectIDs.OrderItem1.GetObject <OrderItem>(); _eventReceiver.Clear(); var listenerMock = MockRepository.GenerateMock <IClientTransactionListener> (); TestableClientTransaction.AddListener(listenerMock); LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3, DomainObjectIDs.OrderItem1); Assert.That(_eventReceiver.LoadedDomainObjectLists, Is.Empty); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoading( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <ObjectID> > .Is.Anything)); listenerMock.AssertWasNotCalled(mock => mock.ObjectsLoaded( Arg <ClientTransaction> .Is.Anything, Arg <ReadOnlyCollection <DomainObject> > .Is.Anything)); }
public void OnLoadedAccessingObject_LoadedLaterInSameBatch_IsSupported_AndDoesNotThrow() { var order1 = DomainObjectIDs.Order1.GetObjectReference <Order> (); var order3 = DomainObjectIDs.Order3.GetObjectReference <Order> (); bool order1LoadedCalled = false; order1.ProtectedLoaded += (sender, args) => { order3.EnsureDataAvailable(); order1LoadedCalled = true; }; int order2LoadedCount = 0; order3.ProtectedLoaded += (sender, args) => { order2LoadedCount++; }; var domainObjects = LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order3); Assert.That(domainObjects, Is.EqualTo(new[] { order1, order3 })); Assert.That(order1LoadedCalled, Is.True); Assert.That(order2LoadedCount, Is.EqualTo(1)); }
/// <summary> /// Gets a number of objects that are already loaded or attempts to load them from the data source. /// If an object's data can't be found, an exception is thrown, and the object is marked <see cref="StateType.Invalid"/> in the /// <see cref="ClientTransaction"/>. /// </summary> /// <typeparam name="T">The type of <see cref="DomainObject"/> instances to return. Can be a base type of the actual object type.</typeparam> /// <param name="handles">Handles to the <see cref="DomainObject"/> that should be loaded.</param> /// <param name="clientTransaction">The <see cref="ClientTransaction"/>. If <see langword="null" /> (or unspecified), the /// <see cref="ClientTransaction.Current"/> transaction is used.</param> /// <returns>A list of objects of type <typeparamref name="T"/> corresponding to (and in the same order as) the IDs specified in /// <paramref name="handles"/>. This list might include deleted objects.</returns> /// <exception cref="ArgumentNullException">The <paramref name="handles"/> parameter is <see langword="null"/>.</exception> /// <exception cref="InvalidCastException">One of the retrieved objects doesn't fit the expected type <typeparamref name="T"/>.</exception> /// <exception cref="ObjectInvalidException">One of the retrieved objects is invalid in this transaction.</exception> /// <exception cref="ObjectsNotFoundException"> /// One or more objects could not be found in the data source. Note that the <see cref="ClientTransaction"/> marks /// not found objects as <see cref="StateType.Invalid"/>, so calling this API again witht he same <see cref="ObjectID"/> results in a /// <see cref="ObjectInvalidException"/> being thrown. /// </exception> public static T[] GetObjects <T> ([NotNull] this IEnumerable <IDomainObjectHandle <T> > handles, ClientTransaction clientTransaction = null) where T : DomainObject, ISupportsGetObject { ArgumentUtility.CheckNotNull("handles", handles); return(LifetimeService.GetObjects <T> (GetMandatoryClientTransaction(clientTransaction), handles.Select(h => h.ObjectID))); }
public void GetObjects_NotFound() { var guid = new Guid("33333333333333333333333333333333"); LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, new ObjectID(typeof(Order), guid)); }
public void GetObjects_InvalidType() { LifetimeService.GetObjects <OrderItem> (TestableClientTransaction, DomainObjectIDs.Order1); }
public void GettingSameObjectID_MultipleTimes() { var domainObjects = LifetimeService.GetObjects <DomainObject> (TestableClientTransaction, DomainObjectIDs.Order1, DomainObjectIDs.Order1); Assert.That(domainObjects, Is.EqualTo(new[] { DomainObjectIDs.Order1.GetObject <Order>(), DomainObjectIDs.Order1.GetObject <Order>() })); }