Esempio n. 1
0
 protected override void Because_of()
 {
     try
     {
         Configuration.AssertConfigurationIsValid();
     }
     catch (AutoMapperConfigurationException ex)
     {
         _exception = ex;
     }
 }
Esempio n. 2
0
        public void Validate()
        {
            Mapper.Initialize(cfg => cfg.CreateMap <Source, Destination>()
                              .ForMember(dest => dest.Bar, opt => opt.Ignore()));

            try
            {
                Mapper.Configuration.AssertConfigurationIsValid();
            }
            catch (AutoMapperConfigurationException exception)
            {
                Exception = exception;
            }
        }
        public void Map()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Source, Destination>();
                cfg.CreateMissingTypeMaps = false;
            });

            try
            {
                config.AssertConfigurationIsValid();
            }
            catch (AutoMapperConfigurationException exception)
            {
                Exception = exception;
            }
        }
        public static string AddUnmappedPropertyHelperInfo(AutoMapperConfigurationException ex)
        {
            string message = ex.Message;

            try
            {
                var sb = new StringBuilder();

                foreach (AutoMapperConfigurationException.TypeMapConfigErrors errors in ex.Errors)
                {
                    string[] unmappedPropertyNames = errors.UnmappedPropertyNames;
                    if (unmappedPropertyNames.Length > 0)
                    {
                        TypeMap typeMap    = errors.TypeMap;
                        string  typeString = $"<{typeMap.SourceType.Name}, {typeMap.DestinationType.Name}>";

                        sb.AppendLine(
                            $"\n\tcfg.CreateMap<{typeMap.SourceType.Name}, {typeMap.DestinationType.Name}>()\n\n"
                            + $"\t\t.IgnoreMember{(unmappedPropertyNames.Length == 1 ? "" : "s")}(dest => dest."
                            + string.Join(", dest => dest.", unmappedPropertyNames)
                            + ");");
                    }
                }

                if (sb.Length > 0)
                {
                    string separator = new string('_', 100);
                    sb.Insert(0,
                              $"\n{separator}\nIf you want to ignore the properties shown above, you can cut/paste the following code stub(s):\n");
                    message = ex.Message + sb;
                }
            }
            catch
            {
            }

            return(message);
        }
 protected override void Because_of()
 {
     try
     {
         Mapper.AssertConfigurationIsValid();
     }
     catch (AutoMapperConfigurationException ex)
     {
         _exception = ex;
     }
 }
Esempio n. 6
0
 public HappyMapperConfigurationException(AutoMapperConfigurationException amce) : base(amce.Message, amce)
 {
     Errors      = amce.Errors;
     Types       = amce.Types;
     PropertyMap = amce.PropertyMap;
 }