예제 #1
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfInheritanceMapIsNotForDerivedTypes(TypeMapBase map,
			PropertyMapBase propertyMap, TypeMapBase inheritanceMap)
        {
            Type baseType =
                ReflectionHelper.IsComplexEnumerable(propertyMap.SourcePropertyInfo.PropertyType)
                ? ReflectionHelper.GetEnumerableItemType(propertyMap.SourcePropertyInfo.PropertyType)
                : propertyMap.SourcePropertyInfo.PropertyType;

            Type type =
                (propertyMap.DestinationPropertyInfo != null)
                ? (ReflectionHelper.IsComplexEnumerable(propertyMap.DestinationPropertyInfo.PropertyType)
                    ? ReflectionHelper.GetEnumerableItemType(propertyMap.DestinationPropertyInfo.PropertyType)
                    : propertyMap.DestinationPropertyInfo.PropertyType)
                : null;

            if (!ReflectionHelper.IsAssignable(baseType, inheritanceMap.SourceType)
                || (type != null && !ReflectionHelper.IsAssignable(type, inheritanceMap.DestinationType))
                || (type == null && map.DestinationType != inheritanceMap.DestinationType))
            {
                throw new MapValidationException(string.Format(Resources.InheritanceMapIsNotForDerivedTypes3,
                    (inheritanceMap != null)
                    ? inheritanceMap.ToString()
                    : string.Empty, (propertyMap != null)
                        ? propertyMap.ToString()
                        : string.Empty, (map != null)
                            ? map.ToString()
                            : string.Empty), null);
            }
        }
예제 #2
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
 public static void MapValidationException_IfInheritanceMapDuplicated(TypeMapBase map, IEnumerable<TypeMapBase> maps)
 {
     if (maps.Count((TypeMapBase m) => m.SourceType == map.SourceType || m.DestinationType == map.DestinationType) > 1)
     {
         throw new MapValidationException(string.Format(Resources.InheritanceMapDuplicated1,
             (map != null) ? map.ToString() : string.Empty), null);
     }
 }
예제 #3
0
 public void Validate_IfInheritanceMapIsNotForDerivedTypes_BadSourceType_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<SubEntity, SubSubEntityModel>().get_Map();
     TypeMap map2 = MapBuilder.get_Instance().CreateMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) => o.SubEntityArrayToArray, (MainEntityModel o) => o.SubEntityArrayToArray, new TypeMap[]
     {
         map
     }).get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map2
     };
     new MapValidator().Validate(map2, array);
 }
예제 #4
0
 public void Validate_IfPropertyMapDuplicated_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) => o.SubEntity, delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
     {
     }).MapProperty((MainEntity o) => o.SubEntity, delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
     {
     }).get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #5
0
        public void Validate(TypeMapBase map, IEnumerable<TypeMapBase> maps)
        {
            if (!rootValidators.ContainsKey(map.GetType()))
            {
                Error.MapValidationException_TypeMapIsNotSupported(map);
            }

            var obj = new MapValidator.ValidationContext
            {
                Map = map,
                CurrentNode = map,
                ParentNode = maps
            };

            rootValidators[map.GetType()](obj);
        }
예제 #6
0
        public MapCompiler.CompilationResult Compile(TypeMapBase map, string contextualName)
        {
            if (!rootCompilers.ContainsKey(map.GetType()))
            {
                Error.MapValidationException_TypeMapIsNotSupported(map);
            }

            var arg = new MapCompiler.CompilationContext
            {
                Map = map,
                CurrentNode = map,
                ParentNode = null,
                ContextualName = contextualName
            };

            return rootCompilers[map.GetType()](arg);
        }
예제 #7
0
        public void Validate_IfInheritanceMapIsNotForDerivedTypes_BadSourceType_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<SubEntity, SubSubEntityModel>().Map;
            var map2 = MapBuilder.Instance.CreateMap<MainEntity, MainEntityModel>()
                .MapProperty((MainEntity o) => o.SubEntityArrayToArray, (MainEntityModel o) => o.SubEntityArrayToArray, new TypeMap[]
            {
                map
            }).Map;

            var array = new TypeMapBase[]
            {
                map2
            };

            //Act
            //Assert
            new MapValidator().Validate(map2, array);
        }
예제 #8
0
 public void Validate_IfPropertyMapperOrPropertyUnMapperIsNotDefined_OnlyUnMapper_ThrowsMapValidationException()
 {
     ReversiveTypeMap map = MapBuilder.get_Instance().CreateReversiveMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) => o.SubEntity, (MainEntityModel o) => o.SubEntity, delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
     {
     }, delegate(MainEntityModel source, MainEntity dest, TypeMappingContext context)
     {
     }).get_Map();
     map.get_PropertyMaps().First<ReversivePropertyMap>().set_Mapper(null);
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #9
0
 public void Validate_IfPropertyMapIsForBothEnumerableOrComplexTypes_SourcePropertyIsSimple_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) => (object)o.Simple, (MainEntityModel o) => o.SubEntity, new TypeMap[]
     {
         MapBuilder.get_Instance().CreateMap<SubEntity, SubSubEntityModel>().get_Map()
     }).get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #10
0
        public void Validate_IfPropertyMapDuplicated_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) =>
                o.SubEntity, delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
                {
                }).MapProperty((MainEntity o) => o.SubEntity,
                delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
                {
                }).Map;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #11
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
 public static void MapValidationException_IfTypeMapIsNotForComplexTypes(TypeMapBase map)
 {
     if (map == null || !ReflectionHelper.IsComplex(map.SourceType) || !ReflectionHelper.IsComplex(map.DestinationType))
     {
         throw new MapValidationException(string.Format(Resources.TypeMapIsNotForComplexTypes1,
             (map != null) ? map.ToString() : string.Empty), null);
     }
 }
예제 #12
0
 public void Validate_IfPropertyMapHasMapperAndInheritanceMapsOrNothing_HasNothing_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<MainEntity, MainEntityModel>().MapProperty((MainEntity o) => o.SubEntity, delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
     {
     }).get_Map();
     map.get_PropertyMaps().First<PropertyMap>().set_Mapper(null);
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #13
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapIsNotForBothComplexEnumerableOrComplexTypes(
			TypeMapBase typeMap, PropertyMapBase propertyMap)
        {
            Type propertyType = propertyMap.SourcePropertyInfo.PropertyType;

            Type type = (propertyMap.DestinationPropertyInfo != null) ? propertyMap.DestinationPropertyInfo.PropertyType : null;

            if ((type == null && (ReflectionHelper.IsComplexEnumerable(propertyType)
                || ReflectionHelper.IsSimple(propertyType))) || (type != null && ((ReflectionHelper.IsComplexEnumerable(propertyType) && ReflectionHelper.IsComplex(type)) || (ReflectionHelper.IsComplex(propertyType) && ReflectionHelper.IsComplexEnumerable(type)) || ReflectionHelper.IsSimple(propertyType) || ReflectionHelper.IsSimple(type))))
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapIsNotForBothComplexEnumerableOrComplexTypes2,
                    (propertyMap != null)
                    ? propertyMap.ToString()
                    : string.Empty, (typeMap != null)
                        ? typeMap.ToString()
                        : string.Empty), null);
            }
        }
예제 #14
0
 public void Validate_IfTypeMapIsNotForComplexTypes_ForSimpleTypes_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<string, string>().get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #15
0
        public void Validate_IfTypeMapDuplicated_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<MainEntity, MainEntityModel>().Map;
            var array = new TypeMapBase[]
            {
                map,
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #16
0
        public void Validate_IfPropertyMapperOrPropertyUnMapperIsNotDefined_OnlyUnMapper_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateReversiveMap<MainEntity, MainEntityModel>()
                .MapProperty((MainEntity o) => o.SubEntity, (MainEntityModel o) => o.SubEntity,
                delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
                {
                },
                delegate(MainEntityModel source, MainEntity dest, TypeMappingContext context)
                {
                }).Map;

            map.PropertyMaps.First<ReversivePropertyMap>().Mapper = null;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #17
0
        public void Validate_IfPropertyMapIsForBothEnumerableOrComplexTypes_SourcePropertyIsSimple_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<MainEntity, MainEntityModel>()
                .MapProperty((MainEntity o) => (object)o.Simple, (MainEntityModel o) => o.SubEntity, new TypeMap[]
            {
                MapBuilder.Instance.CreateMap<SubEntity, SubSubEntityModel>().Map
            }).Map;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #18
0
        public void Validate_IfPropertyMapHasMapperAndInheritanceMapsOrNothing_HasNothing_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<MainEntity, MainEntityModel>()
                .MapProperty((MainEntity o) => o.SubEntity,
                delegate(MainEntity source, MainEntityModel dest, TypeMappingContext context)
                {
                }).Map;

            map.PropertyMaps.First<PropertyMap>().Mapper = null;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #19
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapperOrPropertyUnMapperIsNotDefined(
			TypeMapBase typeMap, ReversivePropertyMap propertyMap)
        {
            if ((propertyMap.Mapper == null && propertyMap.UnMapper != null)
                || (propertyMap.Mapper != null && propertyMap.UnMapper == null))
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapperOrPropertyUnMapperIsNotDefined2,
                    (propertyMap != null)
                    ? propertyMap.ToString()
                    : string.Empty, (typeMap != null)
                        ? typeMap.ToString()
                        : string.Empty), null);
            }
        }
예제 #20
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
 public static void MapValidationException_IfTypeMapDuplicated(TypeMapBase map, IEnumerable<TypeMapBase> maps)
 {
     if (maps.Count((TypeMapBase m) => m.Equals(map)) > 1)
     {
         throw new MapValidationException(string.Format(Resources.TypeMapDuplicated1,
             (map != null) ? map.ToString() : string.Empty), null);
     }
 }
예제 #21
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
 public static void MapValidationException_TypeMapIsNotSupported(TypeMapBase map)
 {
     throw new MapValidationException(string.Format(Resources.TypeMapIsNotSupported1,
         (map != null) ? map.ToString() : string.Empty), null);
 }
예제 #22
0
 public void Validate_IfTypeMapDuplicated_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<MainEntity, MainEntityModel>().get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map,
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #23
0
 public void Validate_IfTypeMapIsNotForComplexTypes_ForEnumerableTypes_ThrowsMapValidationException()
 {
     TypeMap map = MapBuilder.get_Instance().CreateMap<MainEntity[], MainEntityModel[]>().get_Map();
     TypeMapBase[] array = new TypeMapBase[]
     {
         map
     };
     new MapValidator().Validate(map, array);
 }
예제 #24
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapDuplicated(TypeMapBase typeMap, PropertyMapBase propertyMap,
			IEnumerable<PropertyMapBase> propertyMaps)
        {
            if (propertyMaps.Count((PropertyMapBase m) => m.SourcePropertyInfo == propertyMap.SourcePropertyInfo
                || m.DestinationPropertyInfo == propertyMap.DestinationPropertyInfo) > 1)
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapDuplicated2,
                    (propertyMap != null) ? propertyMap.ToString() : string.Empty,
                    (typeMap != null) ? typeMap.ToString() : string.Empty), null);
            }
        }
예제 #25
0
 public void Validate_IfTypeMapperOrTypeUnMapperIsNotDefined_OnlyUnMapper_ThrowsMapValidationException()
 {
     ReversiveTypeMap reversiveTypeMap = new ReversiveTypeMap(typeof(MainEntity), typeof(MainEntityModel));
     reversiveTypeMap.set_UnMapper(delegate(object source, object dest, TypeMappingContext context)
     {
     });
     TypeMapBase[] array = new TypeMapBase[]
     {
         reversiveTypeMap
     };
     new MapValidator().Validate(reversiveTypeMap, array);
 }
예제 #26
0
        public void Validate_IfTypeMapIsNotForComplexTypes_ForSimpleTypes_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<string, string>().Map;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #27
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfPropertyMapHasMapperAndInheritanceMapsOrNothing(TypeMapBase typeMap,
			PropertyMapBase propertyMap, Action<object, object, TypeMappingContext> mapper, IEnumerable<TypeMapBase> inheritanceMaps)
        {
            if ((mapper != null && inheritanceMaps != null && inheritanceMaps.Count<TypeMapBase>() > 0)
                || (mapper == null && (inheritanceMaps == null || inheritanceMaps.Count<TypeMapBase>() == 0)))
            {
                throw new MapValidationException(string.Format(Resources.PropertyMapHasMapperAndInheritanceMapsOrNothing2,
                    (propertyMap != null) ? propertyMap.ToString()
                    : string.Empty, (typeMap != null)
                        ? typeMap.ToString()
                        : string.Empty), null);
            }
        }
예제 #28
0
        public void Validate_IfTypeMapperOrTypeUnMapperIsNotDefined_OnlyUnMapper_ThrowsMapValidationException()
        {
            //Arrange
            var reversiveTypeMap = new ReversiveTypeMap(typeof(MainEntity), typeof(MainEntityModel));

            reversiveTypeMap.UnMapper = delegate(object source, object dest, TypeMappingContext context)
            {
            };

            var array = new TypeMapBase[]
            {
                reversiveTypeMap
            };

            //Act
            //Assert
            new MapValidator().Validate(reversiveTypeMap, array);
        }
예제 #29
0
        public void Validate_IfTypeMapIsNotForComplexTypes_ForEnumerableTypes_ThrowsMapValidationException()
        {
            //Arrange
            var map = MapBuilder.Instance.CreateMap<MainEntity[], MainEntityModel[]>().Map;

            var array = new TypeMapBase[]
            {
                map
            };

            //Act
            //Assert
            new MapValidator().Validate(map, array);
        }
예제 #30
0
파일: Error.cs 프로젝트: hennadiilu/Nmap
        public static void MapValidationException_IfTypeMapHasMapperAndPropertyMaps(TypeMapBase map,
			Action<object, object, TypeMappingContext> mapper, IEnumerable<PropertyMapBase> propertyMaps)
        {
            if (mapper != null && propertyMaps != null && propertyMaps.Count<PropertyMapBase>() > 0)
            {
                throw new MapValidationException(string.Format(Resources.TypeMapHasMapperAndMaps1,
                    (map != null) ? map.ToString() : string.Empty), null);
            }
        }