示例#1
0
        public void GetPropertyMapping_unknown_mapping_with_sub_type_mappings_should_return_null()
        {
            //arrange
            var propertyMappings = new[]
            { _distinguishedName.Object, _storeGenerated.Object, _readOnly.Object, _updateable.Object };

            var mapping = new TestObjectMapping("context", propertyMappings,
                                                "category", false, new[] { "class" }, false);

            mapping.Type.Should().Be.EqualTo(typeof(ParentType));
            var subTypePropertyMapping = new Mock <IPropertyMapping>();
            var subTypeMapping         = new Mock <IObjectMapping>();

            subTypeMapping.Setup(x => x.ObjectClasses)
            .Returns(new[] { "sub" });
            subTypeMapping.Setup(x => x.Type)
            .Returns(typeof(SubType));
            subTypeMapping.Setup(x => x.Properties)
            .Returns(
                new[]
            {
                new KeyValuePair <string, string>("IsSubType", "SubType")
            }.ToDictionary(x => x.Key, x => x.Value).ToReadOnlyDictionary());
            subTypeMapping.Setup(x => x.GetPropertyMapping("IsSubType", null))
            .Returns(subTypePropertyMapping.Object);
            mapping.AddSubTypeMapping(subTypeMapping.Object);

            //assert
            mapping.GetPropertyMapping("error").Should().Be.Null();
        }
示例#2
0
        public void GetPropertyMapping_mapping_from_parent_type_returns_property_name_from_mapping_instance()
        {
            //arrange
            var propertyMappings = new[]
            { _distinguishedName.Object, _storeGenerated.Object, _readOnly.Object, _updateable.Object };

            var mapping = new TestObjectMapping("context", propertyMappings,
                                                "category", false, new[] { "class" }, false);

            mapping.Type.Should().Be.EqualTo(typeof(ParentType));

            var subTypePropertyMapping = new Mock <IObjectMapping>();

            subTypePropertyMapping.Setup(x => x.ObjectClasses)
            .Returns(new[] { "sub" });
            subTypePropertyMapping.Setup(x => x.Type)
            .Returns(typeof(SubType));
            subTypePropertyMapping.Setup(x => x.Properties)
            .Returns(
                new[]
            {
                new KeyValuePair <string, string>("IsSubType", "SubType")
            }.ToDictionary(x => x.Key, x => x.Value).ToReadOnlyDictionary());
            mapping.AddSubTypeMapping(subTypePropertyMapping.Object);

            //act
            var propertyMapping = mapping.GetPropertyMapping("DistinguishedName", mapping.Type);

            //assert
            propertyMapping.Should().Be.EqualTo(_distinguishedName.Object);
        }
示例#3
0
        public void Constructor_Initializes_Correctly()
        {
            //arrange
            var propertyMappings = new[]
            { _distinguishedName.Object, _storeGenerated.Object, _readOnly.Object, _updateable.Object };

            //act
            var mapping = new TestObjectMapping("context", propertyMappings,
                                                "category", false, new[] { "class" }, false);

            //assert
            mapping.NamingContext.Should().Be.EqualTo("context");
            mapping.ObjectCategory.Should().Be.EqualTo("category");
            mapping.ObjectClasses.Should().Have.SameSequenceAs(new[] { "class" });
            propertyMappings.ToList().ForEach(x => mapping.GetPropertyMappings()
                                              .Should().Contain(x));
            mapping.GetDistinguishedNameMapping().Should().Be.EqualTo(_distinguishedName.Object);
            mapping.GetUpdateablePropertyMappings().Should().Contain(_updateable.Object).And.Have.Count.EqualTo(1);
            mapping.IncludeObjectCategory.Should().Be.False();
            mapping.IncludeObjectClasses.Should().Be.False();
            mapping.Properties.ForEach(x =>
            {
                var result = (x.Key == _distinguishedName.Object.PropertyName &&
                              x.Value == _distinguishedName.Object.AttributeName) ||
                             (x.Key == _storeGenerated.Object.PropertyName &&
                              x.Value == _storeGenerated.Object.AttributeName) ||
                             (x.Key == _readOnly.Object.PropertyName &&
                              x.Value == _readOnly.Object.AttributeName) ||
                             (x.Key == _updateable.Object.PropertyName &&
                              x.Value == _updateable.Object.AttributeName);

                result.Should().Be.True();
            });
            mapping.Properties.Count.Should().Be.EqualTo(4);
        }
示例#4
0
        public void AddSubTypeMapping_Should_Reinitialize_PropertyNames_And_Merge_SubType_PropertyNames()
        {
            //arrange
            var propertyMappings = new[]
            { _distinguishedName.Object, _storeGenerated.Object, _readOnly.Object, _updateable.Object };

            var mapping = new TestObjectMapping("context", propertyMappings,
                                                "category", false, new[] { "class" }, false);

            mapping.Properties.ForEach(x =>
            {
                var result = (x.Key == _distinguishedName.Object.PropertyName &&
                              x.Value == _distinguishedName.Object.AttributeName) ||
                             (x.Key == _storeGenerated.Object.PropertyName &&
                              x.Value == _storeGenerated.Object.AttributeName) ||
                             (x.Key == _readOnly.Object.PropertyName &&
                              x.Value == _readOnly.Object.AttributeName) ||
                             (x.Key == _updateable.Object.PropertyName &&
                              x.Value == _updateable.Object.AttributeName);

                result.Should().Be.True();
            });
            mapping.Properties.Count.Should().Be.EqualTo(4);

            var subTypePropertyMapping = new Mock <IObjectMapping>();

            subTypePropertyMapping.Setup(x => x.ObjectClasses)
            .Returns(new[] { "sub" });
            subTypePropertyMapping.Setup(x => x.Type)
            .Returns(typeof(SubType));
            subTypePropertyMapping.Setup(x => x.Properties)
            .Returns(
                new[]
            {
                new KeyValuePair <string, string>("IsSubType", "SubType"),
                new KeyValuePair <string, string>(_distinguishedName.Object.PropertyName, _distinguishedName.Object.AttributeName)
            }.ToDictionary(x => x.Key, x => x.Value).ToReadOnlyDictionary());

            //act
            mapping.AddSubTypeMapping(subTypePropertyMapping.Object);

            //assert
            mapping.Properties.ForEach(x =>
            {
                var result = (x.Key == _distinguishedName.Object.PropertyName &&
                              x.Value == _distinguishedName.Object.AttributeName) ||
                             (x.Key == _storeGenerated.Object.PropertyName &&
                              x.Value == _storeGenerated.Object.AttributeName) ||
                             (x.Key == _readOnly.Object.PropertyName &&
                              x.Value == _readOnly.Object.AttributeName) ||
                             (x.Key == _updateable.Object.PropertyName &&
                              x.Value == _updateable.Object.AttributeName) ||
                             (x.Key == "IsSubType" &&
                              x.Value == "SubType");

                result.Should().Be.True();
            });
            mapping.Properties.Count.Should().Be.EqualTo(5);
        }
示例#5
0
        public void GetPropertyMapping_unknown_mapping_should_throw_exception()
        {
            //arrange
            var propertyMappings = new[]
            { _distinguishedName.Object, _storeGenerated.Object, _readOnly.Object, _updateable.Object };

            var mapping = new TestObjectMapping("context", propertyMappings,
                                                "category", false, new[] { "class" }, false);

            mapping.Type.Should().Be.EqualTo(typeof(ParentType));

            //assert
            Executing.This(() => mapping.GetPropertyMapping("error"))
            .Should()
            .Throw <MappingException>()
            .Exception.Message.Should()
            .Be.EqualTo($"Property mapping with name 'error' was not found for '{mapping.Type.FullName}'");
        }