public static PropertyDefinition CreateAndAddPropertyDefinition(ClassDefinition classDefinition, string propertyName, IPropertyInformation propertyInformation)
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForPropertyInformation(classDefinition, propertyName, propertyInformation);

            classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition }, true));
            return(propertyDefinition);
        }
        public void SeveralInvalidProperties()
        {
            var propertyDefinition1 = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(_classDefinition, _invalidType, "StringPropertyWithMandatoryPropertyAttribute");
            var propertyDefinition2 = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(_classDefinition, _invalidType, "StringPropertyWithExtensibleEnumPropertyAttribute");
            var propertyDefinition3 = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(_classDefinition, _invalidType, "BoolPropertyWithBinaryPropertyAttribute");

            _classDefinition.SetPropertyDefinitions(new PropertyDefinitionCollection(new[] { propertyDefinition1, propertyDefinition2, propertyDefinition3 }, true));
            _classDefinition.SetReadOnly();

            var validationResult = _validtionRule.Validate(_classDefinition).ToArray();

            var expectedMessage1 = "The 'MandatoryAttribute' may be only applied to properties assignable to types 'DomainObject' or 'ObjectList`1'.\r\n\r\n"
                                   + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.Reflection."
                                   + "MappingAttributesAreSupportedForPropertyTypeValidationRule.ClassWithInvalidPropertyAttributes\r\n"
                                   + "Property: StringPropertyWithMandatoryPropertyAttribute";
            var expectedMessage2 = "The 'ExtensibleEnumPropertyAttribute' may be only applied to properties of type 'IExtensibleEnum'.\r\n\r\n"
                                   + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.Reflection."
                                   + "MappingAttributesAreSupportedForPropertyTypeValidationRule.ClassWithInvalidPropertyAttributes\r\n"
                                   + "Property: StringPropertyWithExtensibleEnumPropertyAttribute";
            var expectedMessage3 = "The 'BinaryPropertyAttribute' may be only applied to properties of type 'Byte[]'.\r\n\r\n"
                                   + "Declaring type: Remotion.Data.DomainObjects.UnitTests.Mapping.TestDomain.Validation.Reflection."
                                   + "MappingAttributesAreSupportedForPropertyTypeValidationRule.ClassWithInvalidPropertyAttributes\r\n"
                                   + "Property: BoolPropertyWithBinaryPropertyAttribute";

            Assert.That(validationResult.Length, Is.EqualTo(3));
            AssertMappingValidationResult(validationResult[0], false, expectedMessage1);
            AssertMappingValidationResult(validationResult[1], false, expectedMessage2);
            AssertMappingValidationResult(validationResult[2], false, expectedMessage3);
        }
        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));
        }
Esempio 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);
        }
        private PropertyDefinition CreateForeignKeyPropertyDefinition(ClassDefinition classDefinition)
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID(classDefinition, "OrderTicket");

            propertyDefinition.SetStorageProperty(_foreignKeyStoragePropertyDefinitionStrictMock);
            return(propertyDefinition);
        }
Esempio n. 6
0
        public void IsRelationProperty_True()
        {
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID();
            var propertyValue1 = new PropertyValue(propertyDefinition, null);

            Assert.That(propertyValue1.IsRelationProperty, Is.True);
        }
Esempio n. 7
0
        public void PropertyValue_WithReferenceType_NotAllowed()
        {
            var classDefinition = ClassDefinitionObjectMother.CreateClassDefinition("ClassName");
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(classDefinition, "test", typeof(List <object>));

            new PropertyValue(propertyDefinition, null);
        }
Esempio n. 8
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));
        }
Esempio n. 9
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);
        }
Esempio n. 10
0
        public void SetNullableExtensibleEnum()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(Color), true);

            var propertyValue = new PropertyValue(definition, null);

            Assert.That(propertyValue.Value, Is.Null);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public void SetNotNullableBinaryToNullViaConstructor()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo("test", typeof(byte[]), false);

            var propertyValue = new PropertyValue(definition, null);

            Assert.That(propertyValue.Value, Is.Null);
        }
Esempio n. 13
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);
        }
Esempio n. 14
0
        public void DoesNotPerformMaxLengthCheckInConstructor()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_MaxLength("test", typeof(string), 10);

            var propertyValue = new PropertyValue(definition, "12345678901");

            Assert.That(propertyValue.Value, Is.EqualTo("12345678901"));
        }
Esempio n. 15
0
        private PropertyDefinition CreatePersistentPropertyDefinition(
            ClassDefinition classDefinition, IStoragePropertyDefinition storagePropertyDefinition, IPropertyInformation propertyInformation)
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForPropertyInformation(classDefinition, StorageClass.Persistent, propertyInformation);

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);
            return(propertyDefinition);
        }
        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));
        }
Esempio n. 18
0
        public void SetRelationPropertyDirectly()
        {
            PropertyDefinition definition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID();
            var propertyValue             = new PropertyValue(definition, null);

            propertyValue.Value = DomainObjectIDs.Customer1;

            Assert.That(propertyValue.Value, Is.EqualTo(DomainObjectIDs.Customer1));
        }
        public void GetStoragePropertyDefinition_NoRdbmsDefinition()
        {
            var propertyDefinition        = PropertyDefinitionObjectMother.CreateForFakePropertyInfo(_classDefinition, "OrderNumber");
            var storagePropertyDefinition = new FakeStoragePropertyDefinition("Test");

            propertyDefinition.SetStorageProperty(storagePropertyDefinition);

            _provider.GetStoragePropertyDefinition(propertyDefinition);
        }
Esempio n. 20
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[]'."));
        }
Esempio n. 21
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));
        }
Esempio n. 22
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'."));
        }
Esempio n. 23
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));
        }
Esempio n. 24
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'."));
        }
Esempio n. 25
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'."));
        }
Esempio n. 26
0
        public void GetRelationClassIDColumnName()
        {
            var classDefinition    = ClassDefinitionObjectMother.CreateClassDefinition(classType: typeof(FileSystemItem), baseClass: null);
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForRealPropertyInfo(classDefinition, typeof(FileSystemItem), "ParentFolder");
            var relationDefinition = new RelationEndPointDefinition(propertyDefinition, true);

            var result = _provider.GetRelationClassIDColumnName(relationDefinition);

            Assert.That(result, Is.EqualTo("ParentFolderIDClassID"));
        }
Esempio n. 27
0
        private PropertyDefinition CreatePropertyWithStubbedStorageProperty(
            ClassDefinition classDefinition, IRdbmsStoragePropertyDefinition storagePropertyDefinition, string propertyName, IPropertyInformation propertyInfo)
        {
            PropertyDefinition propertyDefinition = PropertyDefinitionObjectMother.CreateForPropertyInformation(classDefinition, propertyName, propertyInfo);

            _persistenceModelProviderStub
            .Stub(stub => stub.GetStoragePropertyDefinition(propertyDefinition))
            .Return(storagePropertyDefinition);
            return(propertyDefinition);
        }
Esempio n. 28
0
        public void PropertyValueChanging_WithObjectIDProperty_DoesNotRaiseEvent()
        {
            var propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo_ObjectID();

            EventSinkWithMock.Replay();

            EventListener.PropertyValueChanging(_dataContainer, propertyDefinition, "oldValue", "newValue");

            EventSinkWithMock.VerifyAllExpectations();
        }
Esempio n. 29
0
        public override void SetUp()
        {
            base.SetUp();

            _eventListener = new DataContainerEventListener(EventSinkWithMock);

            _domainObject       = DomainObjectMother.CreateFakeObject();
            _dataContainer      = DataContainerObjectMother.Create(domainObject: _domainObject);
            _propertyDefinition = PropertyDefinitionObjectMother.CreateForFakePropertyInfo();
        }
Esempio n. 30
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."));
        }