public void ConstructedObjectIsDerived() { ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That(classWithAllDataTypes, Is.Not.TypeOf <ClassWithAllDataTypes>()); Assert.That(classWithAllDataTypes, Is.InstanceOf <ClassWithAllDataTypes>()); }
public static DomainObject GetNewObject() { var newInstance = ClassWithAllDataTypes.NewObject(); Assert.That(newInstance.State, Is.EqualTo(StateType.New)); return(newInstance); }
public void CommitSavesPropertyValuesToParentTransaction() { Order loadedOrder = DomainObjectIDs.Order1.GetObject <Order> (); ClassWithAllDataTypes newClassWithAllDataTypes = ClassWithAllDataTypes.NewObject(); loadedOrder.OrderNumber = 5; newClassWithAllDataTypes.Int16Property = 7; using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { loadedOrder.OrderNumber = 13; newClassWithAllDataTypes.Int16Property = 47; ClientTransactionScope.CurrentTransaction.Commit(); Assert.That(loadedOrder.State, Is.EqualTo(StateType.Unchanged)); Assert.That(newClassWithAllDataTypes.State, Is.EqualTo(StateType.Unchanged)); Assert.That(loadedOrder.OrderNumber, Is.EqualTo(13)); Assert.That(newClassWithAllDataTypes.Int16Property, Is.EqualTo(47)); } Assert.That(loadedOrder.OrderNumber, Is.EqualTo(13)); Assert.That(newClassWithAllDataTypes.Int16Property, Is.EqualTo(47)); Assert.That(loadedOrder.State, Is.EqualTo(StateType.Changed)); Assert.That(newClassWithAllDataTypes.State, Is.EqualTo(StateType.New)); }
public void SetValidEnumValue() { var instance = ClassWithAllDataTypes.NewObject(); instance.EnumProperty = ClassWithAllDataTypes.EnumType.Value0; Assert.That(instance.EnumProperty, Is.EqualTo(ClassWithAllDataTypes.EnumType.Value0)); }
public void CommitSub_ObjectNewInParent() { var newObject = ClassWithAllDataTypes.NewObject(); CheckNotMarkedAsChanged(newObject); Assert.That(newObject.State, Is.EqualTo(StateType.New)); using (ClientTransaction.Current.CreateSubTransaction().EnterDiscardingScope()) { CheckNotMarkedAsChanged(newObject); Assert.That(newObject.State, Is.EqualTo(StateType.Unchanged)); newObject.RegisterForCommit(); CheckMarkedAsChanged(newObject); Assert.That(newObject.State, Is.EqualTo(StateType.Changed)); ClientTransaction.Current.Commit(); CheckNotMarkedAsChanged(newObject); Assert.That(newObject.State, Is.EqualTo(StateType.Unchanged)); } CheckNotMarkedAsChanged(newObject); Assert.That(newObject.State, Is.EqualTo(StateType.New)); }
public ClassWithAllDataTypes GetNewChanged() { ClassWithAllDataTypes newChanged = ClassWithAllDataTypes.NewObject(); newChanged.Int32Property = 13; return(newChanged); }
private ClassWithAllDataTypes CreateSaveableNewObject() { var result = ClassWithAllDataTypes.NewObject(); result.FillMandatoryProperties(); return(result); }
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 SetPropertyValue_WithNullAndAbstractProperty() { ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); classWithAllDataTypes.StringWithNullValueProperty = null; Assert.That(classWithAllDataTypes.StringWithNullValueProperty, Is.Null); }
public void IsNullPropertyValue() { ClassWithAllDataTypes cwadt = ClassWithAllDataTypes.NewObject(); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].IsNull, Is.True); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.BooleanProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].SetValue <bool?> (true); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].SetValue <bool?> (null); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].IsNull, Is.True); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].SetValue <bool?> (null); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.NaBooleanProperty"].IsNull, Is.True); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringWithNullValueProperty"].IsNull, Is.True); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringWithNullValueProperty"].SetValue(""); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringWithNullValueProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringWithNullValueProperty"].SetValue <string> (null); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.StringWithNullValueProperty"].IsNull, Is.True); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumWithNullValueProperty"].IsNull, Is.True); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumWithNullValueProperty"].SetValue(Color.Values.Green()); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumWithNullValueProperty"].IsNull, Is.False); cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumWithNullValueProperty"].SetValue <Color> (null); Assert.That(cwadt.Properties["Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.ExtensibleEnumWithNullValueProperty"].IsNull, Is.True); }
public override void SetUp() { base.SetUp(); _loadedClassWithAllDataTypes = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); _newClassWithAllDataTypes = ClassWithAllDataTypes.NewObject(); _loadedClassWithAllDataTypesMixin = Mixin.Get <MixinWithAccessToDomainObjectProperties <ClassWithAllDataTypes> > (_loadedClassWithAllDataTypes); _newClassWithAllDataTypesMixin = Mixin.Get <MixinWithAccessToDomainObjectProperties <ClassWithAllDataTypes> > (_newClassWithAllDataTypes); }
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 SetNullIntoNonNullableValueType() { ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That( () => SetPropertyValue(classWithAllDataTypes.InternalDataContainer, typeof(ClassWithAllDataTypes), "BooleanProperty", null), Throws.InvalidOperationException.With.Message.EqualTo( "Property 'Remotion.Data.DomainObjects.UnitTests.TestDomain.ClassWithAllDataTypes.BooleanProperty' does not allow null values.")); }
public void CommitRoot() { var newObject = ClassWithAllDataTypes.NewObject(); newObject.DateTimeProperty = new DateTime(2012, 12, 12); newObject.DateProperty = new DateTime(2012, 12, 12); Assert.That(newObject.State, Is.EqualTo(StateType.New)); var changedObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); ++changedObject.Int32Property; Assert.That(changedObject.State, Is.EqualTo(StateType.Changed)); var unchangedObject = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> (); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged)); newObject.RegisterForCommit(); changedObject.RegisterForCommit(); unchangedObject.RegisterForCommit(); Assert.That(newObject.State, Is.EqualTo(StateType.New)); CheckNotMarkedAsChanged(newObject); Assert.That(changedObject.State, Is.EqualTo(StateType.Changed)); CheckMarkedAsChanged(changedObject); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Changed)); CheckMarkedAsChanged(unchangedObject); var objectEventReceiverMock = MockRepository.GenerateMock <DomainObjectMockEventReceiver> (newObject); var transactionEventReceiverMock = MockRepository.GenerateMock <ClientTransactionMockEventReceiver> (TestableClientTransaction); var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction); SetDatabaseModifyable(); CommitTransactionAndCheckTimestamps(newObject, changedObject, unchangedObject); listenerMock.AssertWasCalled( mock => mock.TransactionCommitting( Arg.Is(TestableClientTransaction), Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(new[] { newObject, changedObject, unchangedObject }), Arg <ICommittingEventRegistrar> .Is.Anything)); listenerMock.AssertWasCalled( mock => mock.TransactionCommitValidate( Arg.Is(TestableClientTransaction), Arg <ReadOnlyCollection <PersistableData> > .Matches( x => x.Select(d => d.DomainObject).SetEquals(new[] { newObject, changedObject, unchangedObject })))); objectEventReceiverMock.AssertWasCalled(mock => mock.Committing()); objectEventReceiverMock.AssertWasCalled(mock => mock.Committed()); transactionEventReceiverMock.AssertWasCalled(mock => mock.Committing(newObject, changedObject, unchangedObject)); transactionEventReceiverMock.AssertWasCalled(mock => mock.Committed(newObject, changedObject, unchangedObject)); Assert.That(newObject.State, Is.EqualTo(StateType.Unchanged)); CheckNotMarkedAsChanged(newObject); Assert.That(changedObject.State, Is.EqualTo(StateType.Unchanged)); CheckNotMarkedAsChanged(changedObject); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged)); CheckNotMarkedAsChanged(unchangedObject); }
public void NeedsLoadModeDataContainerOnly_Serialization_ISerializable_True() { var classWithAllDataTypes = _transaction.ExecuteInScope(() => ClassWithAllDataTypes.NewObject()); Assert.That(classWithAllDataTypes.NeedsLoadModeDataContainerOnly, Is.True); var deserializedClassWithAllDataTypes = Serializer.SerializeAndDeserialize(classWithAllDataTypes); Assert.That(deserializedClassWithAllDataTypes.NeedsLoadModeDataContainerOnly, Is.True); }
public void NewObject_NoOp() { var domainObject = ClassWithAllDataTypes.NewObject(); Assert.That(domainObject.State, Is.EqualTo(StateType.New)); domainObject.RegisterForCommit(); Assert.That(domainObject.State, Is.EqualTo(StateType.New)); CheckNotMarkedAsChanged(domainObject); }
public void ConstructionOfSimpleObjectWorks() { Order order = Order.NewObject(); Assert.That(WasCreatedByFactory(order), Is.True); ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That(classWithAllDataTypes, Is.Not.Null); Assert.That(WasCreatedByFactory(classWithAllDataTypes), Is.True); }
private ClassWithAllDataTypes CreateClassWithAllDataTypes() { ClassWithAllDataTypes newObject = ClassWithAllDataTypes.NewObject(); newObject.DateProperty = DateTime.Now; newObject.DateTimeProperty = DateTime.Now; newObject.StringProperty = "value"; newObject.StringPropertyWithoutMaxLength = "value"; newObject.TransactionOnlyStringProperty = "value"; newObject.BinaryProperty = new byte[10]; newObject.TransactionOnlyBinaryProperty = new byte[10]; return newObject; }
public void Count() { Assert.That(_order.Properties.GetPropertyCount(), Is.EqualTo(6)); OrderItem orderItem = _transaction.ExecuteInScope(() => OrderItem.NewObject()); Assert.That(orderItem.Properties.GetPropertyCount(), Is.EqualTo(3)); ClassWithAllDataTypes cwadt = _transaction.ExecuteInScope(() => ClassWithAllDataTypes.NewObject()); Assert.That(cwadt.Properties.GetPropertyCount(), Is.EqualTo(48)); }
public void ParentTransactionStillReadOnlyAfterCommit() { using (_subTransaction.EnterDiscardingScope()) { Assert.That(TestableClientTransaction.IsWriteable, Is.False); ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That(classWithAllDataTypes.Int32Property, Is.Not.EqualTo(7)); classWithAllDataTypes.Int32Property = 7; _subTransaction.Commit(); Assert.That(TestableClientTransaction.IsWriteable, Is.False); } }
public void DomainObjects_CreatedInSubTransaction_CommitMakesValidInParent() { ClientTransaction subTransaction = TestableClientTransaction.CreateSubTransaction(); using (subTransaction.EnterDiscardingScope()) { var instance = ClassWithAllDataTypes.NewObject(); Assert.That(instance.TransactionContext[subTransaction].State, Is.EqualTo(StateType.New)); Assert.That(instance.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.Invalid)); subTransaction.Commit(); Assert.That(instance.TransactionContext[TestableClientTransaction].State, Is.EqualTo(StateType.New)); } }
public void CommitPropagatesChangesToNewObjectsToParentTransaction() { ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { classWithAllDataTypes.Int32Property = 7; ClientTransactionScope.CurrentTransaction.Commit(); } Assert.That(classWithAllDataTypes.Int32Property, Is.EqualTo(7)); }
public void ValidateDataContainer_IntegrationTest_PropertyWithValueOk() { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var person = ClassWithAllDataTypes.NewObject(); person.BinaryProperty = new byte[10]; person.NullableBinaryProperty = new byte[1000000]; person.StringProperty = "value"; person.StringPropertyWithoutMaxLength = "value"; var dataContainer = person.InternalDataContainer; Assert.That(() => _validator.Validate(dataContainer), Throws.Nothing); } }
public void ValidatePersistableData_IntegrationTest_PropertyWithValueOk() { using (ClientTransaction.CreateRootTransaction().EnterDiscardingScope()) { var person = ClassWithAllDataTypes.NewObject(); person.BinaryProperty = new byte[10]; person.NullableBinaryProperty = new byte[1000000]; person.StringProperty = "value"; person.StringPropertyWithoutMaxLength = "value"; var persistableData = PersistableDataObjectMother.Create(ClientTransaction.Current, person); Assert.That(() => _validator.Validate(ClientTransaction.Current, persistableData), Throws.Nothing); } }
public void GetObject_Invalid() { var domainObject = ClassWithAllDataTypes.NewObject(); domainObject.Delete(); var expectedMessage = string.Format("Object '{0}' is invalid in this transaction.", domainObject.ID); Assert.That( () => LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, true), Throws.TypeOf <ObjectInvalidException> ().With.Message.EqualTo(expectedMessage)); Assert.That( () => LifetimeService.GetObject(TestableClientTransaction, domainObject.ID, false), Throws.TypeOf <ObjectInvalidException> ().With.Message.EqualTo(expectedMessage)); }
public void InvalidObject() { var domainObject = ClassWithAllDataTypes.NewObject(); domainObject.Delete(); Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid)); Assert.That(() => domainObject.RegisterForCommit(), Throws.TypeOf <ObjectInvalidException> ()); Assert.That(domainObject.State, Is.EqualTo(StateType.Invalid)); ResurrectionService.ResurrectInvalidObject(TestableClientTransaction, domainObject.ID); Assert.That(domainObject.State, Is.EqualTo(StateType.NotLoadedYet)); }
public void CommitPropagatesNewObjectsToParentTransaction() { ClassWithAllDataTypes classWithAllDataTypes; using (_subTransaction.EnterDiscardingScope()) { classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That(classWithAllDataTypes.Int32Property, Is.Not.EqualTo(7)); classWithAllDataTypes.Int32Property = 7; _subTransaction.Commit(); Assert.That(classWithAllDataTypes.Int32Property, Is.EqualTo(7)); } Assert.That(classWithAllDataTypes, Is.Not.Null); Assert.That(classWithAllDataTypes.Int32Property, Is.EqualTo(7)); }
public void OnLoadedWithNewInParentAndGetInSubTransaction() { ClassWithAllDataTypes classWithAllDataTypes = ClassWithAllDataTypes.NewObject(); Assert.That(classWithAllDataTypes.OnLoadedCalled, Is.False); Assert.That(classWithAllDataTypes.OnLoadedCallCount, Is.EqualTo(0)); using (TestableClientTransaction.CreateSubTransaction().EnterDiscardingScope()) { Dev.Null = classWithAllDataTypes.Int32Property; Assert.That(classWithAllDataTypes.OnLoadedCalled, Is.True); Assert.That(classWithAllDataTypes.OnLoadedCallCount, Is.EqualTo(1)); Assert.That(classWithAllDataTypes.OnLoadedLoadMode, Is.EqualTo(LoadMode.DataContainerLoadedOnly)); } }
public void Rollback() { var newObject = ClassWithAllDataTypes.NewObject(); Assert.That(newObject.State, Is.EqualTo(StateType.New)); var changedObject = DomainObjectIDs.ClassWithAllDataTypes1.GetObject <ClassWithAllDataTypes> (); ++changedObject.Int32Property; Assert.That(changedObject.State, Is.EqualTo(StateType.Changed)); var unchangedObject = DomainObjectIDs.ClassWithAllDataTypes2.GetObject <ClassWithAllDataTypes> (); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged)); newObject.RegisterForCommit(); changedObject.RegisterForCommit(); unchangedObject.RegisterForCommit(); Assert.That(newObject.State, Is.EqualTo(StateType.New)); CheckNotMarkedAsChanged(newObject); Assert.That(changedObject.State, Is.EqualTo(StateType.Changed)); CheckMarkedAsChanged(changedObject); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Changed)); CheckMarkedAsChanged(unchangedObject); var objectEventReceiverMock = MockRepository.GenerateMock <DomainObjectMockEventReceiver> (unchangedObject); var transactionEventReceiverMock = MockRepository.GenerateMock <ClientTransactionMockEventReceiver> (TestableClientTransaction); var listenerMock = ClientTransactionTestHelperWithMocks.CreateAndAddListenerMock(TestableClientTransaction); TestableClientTransaction.Rollback(); listenerMock.AssertWasCalled( mock => mock.TransactionRollingBack( Arg.Is(TestableClientTransaction), Arg <ReadOnlyCollection <DomainObject> > .List.Equivalent(new[] { newObject, changedObject, unchangedObject }))); objectEventReceiverMock.AssertWasCalled(mock => mock.RollingBack()); objectEventReceiverMock.AssertWasCalled(mock => mock.RolledBack()); transactionEventReceiverMock.AssertWasCalled(mock => mock.RollingBack(newObject, changedObject, unchangedObject)); transactionEventReceiverMock.AssertWasCalled(mock => mock.RolledBack(changedObject, unchangedObject)); Assert.That(newObject.State, Is.EqualTo(StateType.Invalid)); Assert.That(changedObject.State, Is.EqualTo(StateType.Unchanged)); CheckNotMarkedAsChanged(changedObject); Assert.That(unchangedObject.State, Is.EqualTo(StateType.Unchanged)); CheckNotMarkedAsChanged(unchangedObject); }
private ClassWithAllDataTypes CreateTestObjectWithAllDataTypes() { ClassWithAllDataTypes test = ClassWithAllDataTypes.NewObject(); test.ByteProperty = 23; test.DateProperty = DateTime.Now; test.DateTimeProperty = DateTime.Now; test.DecimalProperty = 23.2m; test.DoubleProperty = 23.2; test.GuidProperty = new Guid("{00000008-0000-0000-0000-000000000009}"); test.Int16Property = 2; test.Int32Property = 4; test.Int64Property = 8; test.SingleProperty = 9.8f; test.StringProperty = "aasdf"; return(test); }