Beispiel #1
0
        public void MappingConfigurationTest()
        {
            MappingConfigurationSection target      = new MappingConfigurationSection();
            TypeMappingElement          typeMapping = new TypeMappingElement();

            typeMapping.TargetType = typeof(TestClassA).FullName;
            typeMapping.SourceType = typeof(TestClassB).FullName;

            MemberMappingElement propMapping = new MemberMappingElement();

            propMapping.TargetMemberName = "A";
            propMapping.SourceMemberName = "B";
            typeMapping.MemberMappings.Add(propMapping);
            target.TypeMappings.Add(typeMapping);

            // TODO: change this call to SerializeSection
            var methodInfo = target.GetType().GetMethod(
                "SerializeElement",
                BindingFlags.Instance | BindingFlags.NonPublic);
            var sb = new StringBuilder();

            using (var writer = XmlWriter.Create(sb))
            {
                var res = methodInfo.Invoke(
                    target,
                    new object[] { writer, false });

                writer.Flush();
            }

            const string Expected = @"<MemberMappings><add TargetMemberName=""A"" SourceMemberName=""B"" /></MemberMappings>";

            StringAssert.Contains(Expected, sb.ToString());
        }
        public void GetTypeMappingNoSectionTest()
        {
            TypeMappingElement actual =
                ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping("thisConfigDoesNotExist");

            Assert.IsNull(actual);
        }
Beispiel #3
0
        /// <summary>Returns all internal mappings from the mapper.</summary>
        /// <returns>
        ///     An enumerator that allows foreach to be used to get mappings in this collection.
        /// </returns>
        protected internal override IEnumerable <MemberMappingInfo <TSource, TTarget> > GetMappings()
        {
            TypeMappingElement element = GetTypeMapping();

            if (element != null)
            {
                return(from propMapping in element.MemberMappings.Cast <MemberMappingElement>()
                       select new ReflectionPropertyMappingInfo <TSource, TTarget>(
                           typeof(TSource).GetProperty(propMapping.SourceMemberName),
                           typeof(TTarget).GetProperty(propMapping.TargetMemberName),
                           true));
            }
            return(null);
        }
 internal TypeMapping(TypeMappingElement mapping)
     : this(mapping.Type, mapping.TargetTable)
 {
     AWSSDKUtils.FillDictionary(mapping.PropertyConfigs.Items, p => p.Name, p => new PropertyConfig(p), PropertyConfigs);
 }
        public void GetTypeMappingTest()
        {
            TypeMappingElement actual = ConfigurationMapper <TestClassA, TestClassB> .GetTypeMapping();

            Assert.IsNotNull(actual);
        }