示例#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 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}'");
        }