Exemplo n.º 1
0
        public void PropertyValue_WithReferenceType_NotAllowed()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition("ClassName");
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "test", typeof(List <object>));

            new PropertyValue(propertyDefinition, null);
        }
        public static PropertyDefinition CreateAndAddPropertyDefinition(ClassDefinition classDefinition, string propertyName)
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, propertyName);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true));
            return(propertyDefinition);
        }
        public void CreateStoragePropertyDefinition_PropertyDefinition_OverridesNullability_ForClassBelowBelowDbTableAttribute()
        {
            var propertyDefinitionNotNullable = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_someClassDefinitionWithBaseBaseClass, false);
            var propertyDefinitionNullable    = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_someClassDefinitionWithBaseBaseClass, true);

            _storageNameProviderStub
            .Stub(stub => stub.GetTableName(_someClassDefinitionWithBaseBaseClass))
            .Return(null);
            _storageNameProviderStub
            .Stub(stub => stub.GetTableName(_someClassDefinitionWithBaseBaseClass.BaseClass))
            .Return(null);
            _storageNameProviderStub
            .Stub(stub => stub.GetTableName(_someClassDefinitionWithBaseBaseClass.BaseClass.BaseClass))
            .Return(new EntityNameDefinition(null, "some"));

            _storageTypeInformationProviderMock
            .Expect(mock => mock.GetStorageType(propertyDefinitionNotNullable, true))
            .Return(_fakeStorageTypeInformation1);
            _storageTypeInformationProviderMock
            .Expect(mock => mock.GetStorageType(propertyDefinitionNullable, true))
            .Return(_fakeStorageTypeInformation2);

            _storageNameProviderStub.Stub(stub => stub.GetColumnName(Arg <PropertyDefinition> .Is.Anything)).Return("FakeColumnName");

            var resultNotNullable =
                (SimpleStoragePropertyDefinition)_factory.CreateStoragePropertyDefinition(propertyDefinitionNotNullable);
            var resultNullable =
                (SimpleStoragePropertyDefinition)_factory.CreateStoragePropertyDefinition(propertyDefinitionNullable);

            _storageTypeInformationProviderMock.VerifyAllExpectations();
            Assert.That(resultNotNullable.ColumnDefinition.StorageTypeInfo, Is.SameAs(_fakeStorageTypeInformation1));
            Assert.That(resultNullable.ColumnDefinition.StorageTypeInfo, Is.SameAs(_fakeStorageTypeInformation2));
        }
Exemplo n.º 4
0
        private PropertyDefinition CreateNonPersistentPropertyDefinition(ClassDefinition classDefinition, string propertyName, IStoragePropertyDefinition storagePropertyDefinition)
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, propertyName, StorageClass.None);

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);
            return(propertyDefinition);
        }
Exemplo n.º 5
0
        public void SetNotNullableStringToNull()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(string), false);
            var propertyValue             = new PropertyValue(definition, string.Empty);

            propertyValue.Value = null;
            Assert.That(propertyValue.Value, Is.Null);
        }
Exemplo n.º 6
0
        public void SetNullableExtensibleEnum()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(Color), true);

            var propertyValue = new PropertyValue(definition, null);

            Assert.That(propertyValue.Value, Is.Null);
        }
Exemplo n.º 7
0
        public void EnumCheck_ValidFlagsEnum()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(AttributeTargets));
            var propertyValue             = new PropertyValue(definition, AttributeTargets.Method);

            propertyValue.Value = AttributeTargets.Field | AttributeTargets.Method;
            Assert.That(propertyValue.Value, Is.EqualTo(AttributeTargets.Field | AttributeTargets.Method));
        }
Exemplo n.º 8
0
        public void SetNotNullableExtensibleEnumToNullViaProperty()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(Color), false);
            var propertyValue             = new PropertyValue(definition, ExtensibleEnum <Color> .Values.Red());

            propertyValue.Value = null;
            Assert.That(propertyValue.Value, Is.Null);
        }
Exemplo n.º 9
0
        public void SetNotNullableBinaryToNullViaProperty()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(byte[]), false);
            var propertyValue             = new PropertyValue(definition, ResourceManager.GetImage1());

            propertyValue.Value = null;
            Assert.That(propertyValue.Value, Is.Null);
        }
Exemplo n.º 10
0
        public void SetNotNullableBinaryToNullViaConstructor()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(byte[]), false);

            var propertyValue = new PropertyValue(definition, null);

            Assert.That(propertyValue.Value, Is.Null);
        }
        public void GetStoragePropertyDefinition_NoDefinition()
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_classDefinition, "OrderNumber");

            Assert.That(propertyDefinition.StoragePropertyDefinition, Is.Null);

            _provider.GetStoragePropertyDefinition(propertyDefinition);
        }
        private SortedPropertySpecification CreateSortedPropertySpecification(
            ClassDefinition classDefinition, IStoragePropertyDefinition columnDefinition, SortOrder sortOrder)
        {
            var sortedPropertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition);

            sortedPropertyDefinition.SetStorageProperty(columnDefinition);
            return(new SortedPropertySpecification(sortedPropertyDefinition, sortOrder));
        }
Exemplo n.º 13
0
        public void SetBinaryWithInvalidType()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(byte[]));

            Assert.That(
                () => new PropertyValue(definition, new int[0]),
                Throws.TypeOf <InvalidTypeException>()
                .With.Message.EqualTo("Actual type 'System.Int32[]' of property 'test' does not match expected type 'System.Byte[]'."));
        }
Exemplo n.º 14
0
        public void EnumCheckInConstructor()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(DayOfWeek));

            Assert.That(
                () => new PropertyValue(definition, (DayOfWeek)17420),
                Throws.TypeOf <InvalidEnumValueException>()
                .With.Message.EqualTo("Value '17420' for property 'test' is not defined by enum type 'System.DayOfWeek'."));
        }
Exemplo n.º 15
0
        public void RaisePropertyValueRead_EventWithNull()
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();

            CheckEventWithListenersLast(
                s => s.RaisePropertyValueReadEvent(_domainObject1, propertyDefinition, null, ValueAccess.Current),
                l => l.PropertyValueRead(_clientTransaction, _domainObject1, propertyDefinition, null, ValueAccess.Current),
                x => x.PropertyValueRead(_clientTransaction, _domainObject1, propertyDefinition, null, ValueAccess.Current));
        }
Exemplo n.º 16
0
        public void EnumCheck_ValidNonFlagsEnum()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(DayOfWeek));

            var propertyValue = new PropertyValue(definition, DayOfWeek.Monday);

            propertyValue.Value = DayOfWeek.Monday;
            Assert.That(propertyValue.Value, Is.EqualTo(DayOfWeek.Monday));
        }
Exemplo n.º 17
0
        public void SetExtensibleEnumWithInvalidType()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(Color), false);

            Assert.That(
                () => new PropertyValue(definition, 12),
                Throws.TypeOf <InvalidTypeException>()
                .With.Message.EqualTo("Actual type 'System.Int32' of property 'test' does not match expected type 'Remotion.Data.DomainObjects.UnitTests.TestDomain.Color'."));
        }
Exemplo n.º 18
0
        public void TypeCheckInConstructor()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(string));

            Assert.That(
                () => new PropertyValue(definition, 123),
                Throws.TypeOf <InvalidTypeException>()
                .With.Message.EqualTo("Actual type 'System.Int32' of property 'test' does not match expected type 'System.String'."));
        }
        public void GetStoragePropertyDefinition_NoRdbmsDefinition()
        {
            var propertyDefinition        = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_classDefinition, "OrderNumber");
            var storagePropertyDefinition = new FakeStoragePropertyDefinition("Test");

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);

            _provider.GetStoragePropertyDefinition(propertyDefinition);
        }
Exemplo n.º 20
0
        public void EnumCheck_InvalidNullEnum()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(DayOfWeek?), true);
            var propertyValue             = new PropertyValue(definition, DayOfWeek.Monday);

            Assert.That(
                () => propertyValue.Value = (DayOfWeek)17420,
                Throws.TypeOf <InvalidEnumValueException>()
                .With.Message.EqualTo("Value '17420' for property 'test' is not defined by enum type 'System.DayOfWeek'."));
        }
Exemplo n.º 21
0
        public void EnumCheck_InvalidFlagsEnum()
        {
            var definition    = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(AttributeTargets));
            var propertyValue = new PropertyValue(definition, AttributeTargets.Method);

            Assert.That(
                () => propertyValue.Value = (AttributeTargets)(-1),
                Throws.TypeOf <InvalidEnumValueException>()
                .With.Message.EqualTo("Value '-1' for property 'test' is not defined by enum type 'System.AttributeTargets'."));
        }
Exemplo n.º 22
0
        public void EnumCheck_InvalidNonNullEnum_Null()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(DayOfWeek), false);
            var propertyValue             = new PropertyValue(definition, DayOfWeek.Monday);

            Assert.That(
                () => propertyValue.Value = null,
                Throws.InvalidOperationException
                .With.Message.EqualTo("Property 'test' does not allow null values."));
        }
Exemplo n.º 23
0
        public override void SetUp()
        {
            base.SetUp();

            _eventListener = new DataContainerEventListener(EventSinkWithMock);

            _domainObject       = DomainObjectMother.CreateFakeObject();
            _dataContainer      = DataContainerObjectMother.Create(domainObject: _domainObject);
            _propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();
        }
        public void GetStoragePropertyDefinition()
        {
            var storagePropertyDefinition = MockRepository.GenerateStub <IRdbmsStoragePropertyDefinition>();
            var propertyDefinition        = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);

            var result = _provider.GetStoragePropertyDefinition(propertyDefinition);

            Assert.That(result, Is.SameAs(storagePropertyDefinition));
        }
Exemplo n.º 25
0
        public void SetNotNullableBinary()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(byte[]), false);

            var propertyValue = new PropertyValue(definition, new byte[0]);

            ResourceManager.IsEmptyImage((byte[])propertyValue.Value);

            propertyValue.Value = ResourceManager.GetImage1();
            ResourceManager.IsEqualToImage1((byte[])propertyValue.Value);
        }
Exemplo n.º 26
0
        public void GetStoragePropertiesForHierarchy_NonPersistentPropertiesAreFiltered()
        {
            var classDefinition       = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(Order), baseClass: null);
            var nonPersistentProperty = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "NonPersistentProperty", StorageClass.None);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { nonPersistentProperty }, true));
            classDefinition.SetDerivedClasses(new ClassDefinition[0]);

            var properties = _resolver.GetStoragePropertiesForHierarchy(classDefinition).ToArray();

            Assert.That(properties, Is.Empty);
        }
Exemplo n.º 27
0
        public void RaisePropertyValueChangedEvent_WithNulls()
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();

            CheckEventWithListenersLast(
                s => s.RaisePropertyValueChangedEvent(_domainObject1, propertyDefinition, null, null),
                l => l.PropertyValueChanged(_clientTransaction, _domainObject1, propertyDefinition, null, null),
                x => x.PropertyValueChanged(_clientTransaction, _domainObject1, propertyDefinition, null, null),
                () => _order1EventReceiverMock
                .Expect(mock => mock.PropertyChanged(propertyDefinition, null, null))
                .WithCurrentTransaction(_clientTransaction));
        }
        private PropertyDefinition CreatePropertyDefinition(Type propertyType, bool isNullable, int?maxLength = null)
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition();

            return(PropertyDefinitionObjectMother.CreateForFakePropertyInfo(
                       classDefinition,
                       "Name",
                       false,
                       propertyType,
                       isNullable,
                       maxLength,
                       StorageClass.Persistent));
        }
Exemplo n.º 29
0
        public void ResolveProperty_CompoundColumn()
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();
            var entityExpression   = CreateEntityDefinition(typeof(Order), "o");

            _rdbmsPersistenceModelProviderStub
            .Stub(stub => stub.GetStoragePropertyDefinition(propertyDefinition))
            .Return(_rdbmsStoragePropertyDefinitionStub);
            _rdbmsStoragePropertyDefinitionStub
            .Stub(stub => stub.GetColumns())
            .Return(new[] { ColumnDefinitionObjectMother.IDColumn, ColumnDefinitionObjectMother.ClassIDColumn });

            _storageSpecificExpressionResolver.ResolveProperty(entityExpression, propertyDefinition);
        }
Exemplo n.º 30
0
        public void RaisePropertyValueChangingEvent()
        {
            var    propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();
            object oldValue           = "old";
            object newValue           = "new";

            CheckEventWithListenersFirst(
                s => s.RaisePropertyValueChangingEvent(_domainObject1, propertyDefinition, oldValue, newValue),
                l => l.PropertyValueChanging(_clientTransaction, _domainObject1, propertyDefinition, oldValue, newValue),
                x => x.PropertyValueChanging(_clientTransaction, _domainObject1, propertyDefinition, oldValue, newValue),
                () => _order1EventReceiverMock
                .Expect(mock => mock.PropertyChanging(propertyDefinition, oldValue, newValue))
                .WithCurrentTransaction(_clientTransaction));
        }