public override void SetUp() { base.SetUp(); _mockRepository = new MockRepository(); _eventSinkWithMock = _mockRepository.StrictMock <IClientTransactionEventSink>(); _persistenceStrategyMock = _mockRepository.StrictMock <IPersistenceStrategy> (); _dataManagerMock = _mockRepository.StrictMock <IDataManager> (); _clientTransaction = ClientTransactionObjectMother.Create(); _agent = new CommitRollbackAgent(_clientTransaction, _eventSinkWithMock, _persistenceStrategyMock, _dataManagerMock); _fakeChangedDomainObject = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty); _fakeNewDomainObject = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty); _fakeDeletedDomainObject = LifetimeService.NewObject(_clientTransaction, typeof(Order), ParamList.Empty); var fakeDataContainer1 = DataContainerObjectMother.Create(); var fakeDataContainer2 = DataContainerObjectMother.Create(); var fakeDataContainer3 = DataContainerObjectMother.Create(); _fakeChangedPersistableItem = new PersistableData(_fakeChangedDomainObject, StateType.Changed, fakeDataContainer1, new IRelationEndPoint[0]); _fakeNewPersistableItem = new PersistableData(_fakeNewDomainObject, StateType.New, fakeDataContainer2, new IRelationEndPoint[0]); _fakeDeletedPersistableItem = new PersistableData(_fakeDeletedDomainObject, StateType.Deleted, fakeDataContainer3, new IRelationEndPoint[0]); }
public void NewObject_NoCtorArgs() { var instance = (Order)LifetimeService.NewObject(TestableClientTransaction, typeof(Order), ParamList.Empty); Assert.That(instance, Is.Not.Null); Assert.That(instance.CtorCalled, Is.True); }
public void GetPropertyDefaultForNonMappingProperties() { var businessObject = (IBusinessObject) LifetimeService.NewObject(ClientTransaction.Current, typeof(BindableDomainObjectWithProperties), ParamList.Empty); Assert.That(businessObject.GetProperty("RequiredPropertyNotInMapping"), Is.Not.Null); Assert.That(businessObject.GetProperty("RequiredPropertyNotInMapping"), Is.EqualTo(true)); }
public void NewObject_WithCtorArgs() { var order = Order.NewObject(); var instance = (OrderItem)LifetimeService.NewObject(TestableClientTransaction, typeof(OrderItem), ParamList.Create(order)); Assert.That(instance, Is.Not.Null); Assert.That(instance.Order, Is.SameAs(order)); }
public static DomainObject GetInvalidObject(ClientTransaction transaction) { var invalidInstance = LifetimeService.NewObject(transaction, typeof(Order), ParamList.Empty); LifetimeService.DeleteObject(transaction, invalidInstance); Assert.That(invalidInstance.TransactionContext[transaction].State, Is.EqualTo(StateType.Invalid)); return(invalidInstance); }
public void NewObject_InitializesMixins() { var domainObject = LifetimeService.NewObject(TestableClientTransaction, typeof(ClassWithAllDataTypes), ParamList.Empty); var mixin = Mixin.Get <MixinWithAccessToDomainObjectProperties <ClassWithAllDataTypes> > (domainObject); Assert.That(mixin, Is.Not.Null); Assert.That(mixin.OnDomainObjectCreatedCalled, Is.True); Assert.That(mixin.OnDomainObjectCreatedTx, Is.SameAs(TestableClientTransaction)); }
/// <summary> /// Loads a new instance of a domain object for transportation. /// </summary> /// <param name="type">The domain object type to instantiate.</param> /// <param name="constructorParameters">A <see cref="ParamList"/> encapsulating the parameters to be passed to the constructor. Instantiate this /// by using one of the <see cref="ParamList.Create{A1,A2}"/> methods.</param> /// <returns>A new instance of <paramref name="type"/> prepared for transport.</returns> public DomainObject LoadNew(Type type, ParamList constructorParameters) { using (_transportTransaction.EnterNonDiscardingScope()) { DomainObject domainObject = LifetimeService.NewObject(ClientTransaction.Current, type, constructorParameters); Load(domainObject.ID); return(domainObject); } }
public void DeserializationEvents() { var instance = (ClassWithSerializationCallbacks) LifetimeService.NewObject(TestableClientTransaction, typeof(ClassWithSerializationCallbacks), ParamList.Empty); Assert.That(((object)instance).GetType(), Is.Not.SameAs(typeof(ClassWithSerializationCallbacks))); new SerializationCallbackTester <ClassWithSerializationCallbacks> (new RhinoMocksRepositoryAdapter(), instance, ClassWithSerializationCallbacks.SetReceiver) .Test_DeserializationCallbacks(); }
public override void SetUp() { base.SetUp(); _transaction = ClientTransaction.CreateRootTransaction(); _cachingListener = new DomainObjectStateCache(_transaction); _existingOrder = (Order)LifetimeService.GetObject(_transaction, DomainObjectIDs.Order1, false); _newOrder = (Order)LifetimeService.NewObject(_transaction, typeof(Order), ParamList.Empty); _notYetLoadedOrder = (Order)LifetimeService.GetObjectReference(_transaction, DomainObjectIDs.Order3); }
public static ObjectID CreateObjectAndSetRelationInOtherTransaction(RelationEndPointDefinition endPointDefinition, ObjectID relatedID) { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var domainObject = LifetimeService.NewObject(ClientTransaction.Current, endPointDefinition.ClassDefinition.ClassType, ParamList.Empty); SetForeignKeyProperty(domainObject, endPointDefinition, relatedID); ClientTransaction.Current.Commit(); return(domainObject.ID); } }
protected SecurableDomainObject CreateSecurableDomainObject(ClientTransaction clientTransaction = null) { clientTransaction = clientTransaction ?? ClientTransaction.CreateRootTransaction(); var securableDomainObject = (SecurableDomainObject)LifetimeService.NewObject(clientTransaction, typeof(SecurableDomainObject), ParamList.Empty); securableDomainObject.SecurableType = typeof(SecurableDomainObject); securableDomainObject.SecurityStrategy = _objectSecurityStrategyStub; return(securableDomainObject); }
public void IsInvalid_AffectsAssociatedRootTransaction() { var order = (Order)LifetimeService.NewObject(_rootTransaction, typeof(Order), ParamList.Empty); Assert.That(GetStateFromTransaction(order, _rootTransaction), Is.EqualTo(StateType.New)); Assert.That(order.State, Is.Not.EqualTo(StateType.Invalid)); order.Delete(); Assert.That(GetStateFromTransaction(order, _rootTransaction), Is.EqualTo(StateType.Invalid)); Assert.That(order.State, Is.EqualTo(StateType.Invalid)); }
protected T CreateObjectInDatabaseAndLoad <T> () where T : DomainObject { ObjectID objectID; using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var domainObject = LifetimeService.NewObject(ClientTransaction.Current, typeof(T), ParamList.Empty); ClientTransaction.Current.Commit(); objectID = domainObject.ID; } return((T)LifetimeService.GetObject(ClientTransaction.Current, objectID, false)); }
public void DomainObject_CallingWrongCtorDuringDeserialization() { var domainObject = LifetimeService.NewObject( TestableClientTransaction, typeof(SerializableClassCallingWrongBaseCtor), ParamList.Empty); Assert.That( () => UnwrapTargetInvocationExceptions(() => Serializer.SerializeAndDeserialize(domainObject)), Throws.InvalidOperationException.With.Message.EqualTo( "The DomainObject constructor may only be called via ClientTransaction.NewObject. " + "If this exception occurs during a base call of a deserialization constructor, adjust the base call to call the DomainObject's " + "deserialization constructor instead.")); }
public static ObjectID CreateObjectAndSetRelationInOtherTransaction <TCreated, TRelated> (ObjectID relatedID, Action <TCreated, TRelated> setter) where TCreated : DomainObject where TRelated : DomainObject { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var domainObject = (TCreated)LifetimeService.NewObject(ClientTransaction.Current, typeof(TCreated), ParamList.Empty); setter(domainObject, relatedID != null ? (TRelated)LifetimeService.GetObject(ClientTransaction.Current, relatedID, true) : null); ClientTransaction.Current.Commit(); return(domainObject.ID); } }
public void ShortNameAndTypeWithShadowedProperties() { var classWithDifferentProperties = (DerivedClassWithDifferentProperties) LifetimeService.NewObject(_transaction, typeof(DerivedClassWithDifferentProperties), ParamList.Empty); var indexer = new PropertyIndexer(classWithDifferentProperties); Assert.That( indexer[typeof(DerivedClassWithDifferentProperties), "String"], Is.EqualTo(indexer[typeof(DerivedClassWithDifferentProperties).FullName + ".String"])); Assert.That( indexer[typeof(ClassWithDifferentProperties), "String"], Is.EqualTo(indexer[typeof(ClassWithDifferentProperties).FullName + ".String"])); }
public void Find_Generic_WithInferredType() { var classWithDifferentProperties = (DerivedClassWithDifferentProperties)LifetimeService.NewObject(_transaction, typeof(DerivedClassWithDifferentProperties), ParamList.Empty); var indexer = new PropertyIndexer(classWithDifferentProperties); var resultOnDerived = indexer.Find(classWithDifferentProperties, "String"); Assert.That(resultOnDerived, Is.EqualTo(indexer[typeof(DerivedClassWithDifferentProperties).FullName + ".String"])); var resultOnBase = indexer.Find((ClassWithDifferentProperties)classWithDifferentProperties, "String"); Assert.That(resultOnBase, Is.EqualTo(indexer[typeof(ClassWithDifferentProperties).FullName + ".String"])); }
public override void SetUp() { base.SetUp(); _mockRepository = new MockRepository(); _cloner = new DomainObjectCloner(); _classWithAllDataTypes = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); _order1 = DomainObjectIDs.Order1.GetObject <Order> (); _computer1 = DomainObjectIDs.Computer1.GetObject <Computer> (); _boundSource = ClientTransaction.CreateRootTransaction().ExecuteInScope(() => ClassWithAllDataTypes.NewObject()); _boundSource.Int32Property = 123; _classWithClonerCallback = (ClassWithClonerCallback)LifetimeService.NewObject(TestableClientTransaction, typeof(ClassWithClonerCallback), ParamList.Empty); }
public void IsInvalid_AffectsActiveLeafTransaction() { using (_leafTransaction.EnterNonDiscardingScope()) { var order = (Order)LifetimeService.NewObject(_leafTransaction, typeof(Order), ParamList.Empty); Assert.That(GetStateFromTransaction(order, _leafTransaction), Is.EqualTo(StateType.New)); Assert.That(order.State, Is.Not.EqualTo(StateType.Invalid)); order.Delete(); Assert.That(GetStateFromTransaction(order, _leafTransaction), Is.EqualTo(StateType.Invalid)); Assert.That(order.State, Is.EqualTo(StateType.Invalid)); } }
public override void SetUp() { base.SetUp(); _order = (Order)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Order1); _location = (Location)LifetimeService.GetObjectReference(WriteableSubTransaction, DomainObjectIDs.Location1); _client1 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client1, false); _client2 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client2, false); _client3 = (Client)LifetimeService.GetObject(WriteableSubTransaction, DomainObjectIDs.Client3, false); _client4 = (Client)LifetimeService.NewObject(WriteableSubTransaction, typeof(Client), ParamList.Empty); _loadEventReceiverMock = MockRepository.GenerateStrictMock <ILoadEventReceiver>(); _order.SetLoadEventReceiver(_loadEventReceiverMock); _location.SetLoadEventReceiver(_loadEventReceiverMock); }
public void MultiplePropertiesWithSameShortName() { var derivedClass = (DerivedClassWithDifferentProperties)LifetimeService.NewObject(TestableClientTransaction, typeof(DerivedClassWithDifferentProperties), ParamList.Empty); ClassWithDifferentProperties baseClass = derivedClass; derivedClass.String = "Derived"; baseClass.String = "Base"; Assert.That(derivedClass.String, Is.EqualTo("Derived")); Assert.That(baseClass.String, Is.EqualTo("Base")); baseClass.String = "NewBase"; derivedClass.String = "NewDerived"; Assert.That(derivedClass.String, Is.EqualTo("NewDerived")); Assert.That(baseClass.String, Is.EqualTo("NewBase")); }
public void OnDomainObjectCreated() { var mixinInstance = new HookedDomainObjectMixin(); Assert.That(mixinInstance.OnLoadedCalled, Is.False); Assert.That(mixinInstance.OnCreatedCalled, Is.False); Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.False); using (new MixedObjectInstantiationScope(mixinInstance)) { var tx = ClientTransaction.CreateRootTransaction(); LifetimeService.NewObject(tx, typeof(HookedTargetClass), ParamList.Empty); } Assert.That(mixinInstance.OnLoadedCalled, Is.False); Assert.That(mixinInstance.OnCreatedCalled, Is.True); Assert.That(mixinInstance.OnDomainObjectReferenceInitializingCalled, Is.True); }
public void CreateClone_InvokesClonerCallback_OnReferencedObjects() { var cloneTransaction = ClientTransaction.CreateRootTransaction(); _cloner.CloneTransaction = cloneTransaction; var referencedObject = (ClassWithClonerCallback)LifetimeService.NewObject(TestableClientTransaction, typeof(ClassWithClonerCallback), ParamList.Empty); referencedObject.Property = 42; _classWithClonerCallback.ReferencedObject = referencedObject; var clone = _cloner.CreateClone(_classWithClonerCallback, new CompleteCloneStrategy()); var clonedReferencedObject = cloneTransaction.ExecuteInScope(() => clone.ReferencedObject); Assert.That(clonedReferencedObject.CallbackInvoked, Is.True); Assert.That(clonedReferencedObject.CallbackOriginal, Is.SameAs(referencedObject)); Assert.That(clonedReferencedObject.CallbackCloneTransaction, Is.SameAs(cloneTransaction)); Assert.That(clonedReferencedObject.CallbackCurrentTransaction, Is.SameAs(ClientTransaction.Current)); Assert.That(clonedReferencedObject.PropertyValueInCallback, Is.EqualTo(42)); }
public override void SetUp() { base.SetUp(); var clientTransaction = ClientTransaction.CreateRootTransaction(); var sampleObject = LifetimeService.NewObject(clientTransaction, typeof(SampleObject), ParamList.Empty); _objectID = sampleObject.ID; clientTransaction.Commit(); var locator = DefaultServiceLocator.Create(); var factory = new LinqToSqlExtensionFactory(); locator.RegisterSingle <IClientTransactionExtensionFactory> (() => factory); locator.RegisterSingle <IPersistenceExtensionFactory> (() => factory); _serviceLocatorScope = new ServiceLocatorScope(locator); _tracingLinqToSqlAppender = new TracingLinqToSqlAppender(); SetAppender(_tracingLinqToSqlAppender); }
public void RelationRead_LongCollection() { var relationEndPointDefinition = MockRepository.GenerateStub <IRelationEndPointDefinition>(); relationEndPointDefinition.Stub(n => n.PropertyName).Return("Items"); var values = new ReadOnlyDomainObjectCollectionAdapter <DomainObject> ( new DomainObjectCollection( Enumerable.Range(0, 100).Select(i => LifetimeService.NewObject(_clientTransaction, typeof(Client), ParamList.Empty)), null)); CheckLoggingMethod( () => _listener.RelationRead(_clientTransaction, _domainObject, relationEndPointDefinition, values, ValueAccess.Current), string.Format( "{0} RelationRead: {1} ({2}, {3}): {4}, +90", _clientTransaction.ID, relationEndPointDefinition.PropertyName, ValueAccess.Current, _domainObject.ID, string.Join(", ", values.Take(10)))); }
public void DomainObjectsAreSerializable() { CheckDomainObjectSerializability(delegate { return(AccessControlEntry.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StatefulAccessControlList.NewObject()); }); CheckDomainObjectSerializability(delegate { return(Permission.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StateCombination.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StateUsage.NewObject()); }); CheckDomainObjectSerializability(delegate { return(AbstractRoleDefinition.NewObject()); }); CheckDomainObjectSerializability(delegate { return(AccessTypeDefinition.NewObject()); }); CheckDomainObjectSerializability(delegate { return(AccessTypeReference.NewObject()); }); CheckDomainObjectSerializability(delegate { return(Culture.NewObject("DE-DE")); }); CheckDomainObjectSerializability(delegate { return(LocalizedName.NewObject("foo", Culture.NewObject("DE-DE"), SecurableClassDefinition.NewObject())); }); CheckDomainObjectSerializability(delegate { return(SecurableClassDefinition.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StateDefinition.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StatePropertyDefinition.NewObject()); }); CheckDomainObjectSerializability(delegate { return(StatePropertyReference.NewObject()); }); CheckDomainObjectSerializability(delegate { return((Group)LifetimeService.NewObject(ClientTransaction.Current, typeof(Group), ParamList.Empty)); }); CheckDomainObjectSerializability(delegate { return((GroupType)LifetimeService.NewObject(ClientTransaction.Current, typeof(GroupType), ParamList.Empty)); }); CheckDomainObjectSerializability(delegate { return(GroupTypePosition.NewObject()); }); CheckDomainObjectSerializability(delegate { return((Position)LifetimeService.NewObject(ClientTransaction.Current, typeof(Position), ParamList.Empty)); }); CheckDomainObjectSerializability(delegate { return(Role.NewObject()); }); CheckDomainObjectSerializability(delegate { return((Tenant)LifetimeService.NewObject(ClientTransaction.Current, typeof(Tenant), ParamList.Empty)); }); CheckDomainObjectSerializability(delegate { return((User)LifetimeService.NewObject(ClientTransaction.Current, typeof(User), ParamList.Empty)); }); }
public static T CreateObjectInTransaction <T> (ClientTransaction transaction) where T : DomainObject { return((T)LifetimeService.NewObject(transaction, typeof(T), ParamList.Empty)); }
public void NewObject_WrongCtorArgs() { LifetimeService.NewObject(TestableClientTransaction, typeof(OrderItem), ParamList.Create(0m)); }
public void WrongConstructorCannotBeInstantiated() { LifetimeService.NewObject(TestableClientTransaction, typeof(Order), ParamList.Create("foo", "bar", "foobar", (object)null)); }
/// <summary> /// Returns a new instance of a concrete domain object for the current <see cref="DomainObjects.ClientTransaction"/>. The object is constructed /// using the supplied constructor arguments in the <see cref="DomainObjects.ClientTransaction.Current"/> <see cref="DomainObjects.ClientTransaction"/>. /// </summary> /// <typeparam name="T">The concrete type to be implemented by the object.</typeparam> /// <param name="constructorParameters">A <see cref="ParamList"/> encapsulating the parameters to be passed to the constructor. Instantiate this /// by using one of the <see cref="ParamList.Create{A1,A2}"/> methods.</param> /// <returns>A new domain object instance.</returns> /// <remarks> /// <para> /// Objects created by this factory method are not directly instantiated; instead a proxy is dynamically created, which will assist in /// management tasks at runtime. /// </para> /// <para>This method should not be directly invoked by a user, but instead by static factory methods of classes derived from /// <see cref="DomainObject"/>.</para> /// <para>For more information, also see the constructor documentation (<see cref="DomainObject()"/>).</para> /// </remarks> /// <seealso cref="DomainObject()"/> /// <exception cref="ArgumentException">The type <typeparamref name="T"/> cannot be extended to a proxy, for example because it is sealed /// or abstract and non-instantiable.</exception> /// <exception cref="MissingMethodException">The given type <typeparamref name="T"/> does not implement the required protected /// constructor (see Remarks section). /// </exception> protected static T NewObject <T> (ParamList constructorParameters) where T : DomainObject { ArgumentUtility.CheckNotNull("constructorParameters", constructorParameters); return((T)LifetimeService.NewObject(ClientTransactionScope.CurrentTransaction, typeof(T), constructorParameters)); }