Beispiel #1
0
        public void ConfigureFromAssemblyTest()
        {
            object profileObject = new object();

            Mock <IAutomapperProfile <object> > profileMock = new Mock <IAutomapperProfile <object> >();

            profileMock.Setup(_profile => _profile.Profile).Returns(profileObject);

            IAutomapperProfile <object> profile = profileMock.Object;

            ConfigureCount.Add(profile.Profile, 0);

            profile.ConfigureFromAssembly(GetType().Assembly);

            ConfigureCount[profile.Profile].Should().Be(2);
            ConfigureCount.Remove(profile.Profile);
        }
Beispiel #2
0
        public void ConfigureFromAssemblyTest_ImplicitAssembly()
        {
            object profileObject = new object();

            Mock <IAutomapperProfile <object> > profileMock = new Mock <IAutomapperProfile <object> >();

            profileMock.Setup(_profile => _profile.Profile).Returns(profileObject);

            IAutomapperProfile <object> profile = profileMock.Object;

            ConfigureCount.Add(profile.Profile, 0);

            profile.ConfigureFromAssembly();

            // Moq will give us a dynamic assembly which will not have the anything that implements the type "IAuomapperProfileConfiguration<T>".
            ConfigureCount[profile.Profile].Should().Be(0);
            ConfigureCount.Remove(profile.Profile);
        }
        internal static void ConfigureFromAssembly <T>(
            this IAutomapperProfile <T> aProfile,
            Assembly aAssembly)
        {
            IEnumerable <Type> profileConfigurationTypes =
                aAssembly.GetTypes()
                .Where(type => typeof(IAutomapperProfileConfiguration <T>).IsAssignableFrom(type));

            foreach (Type profileConfigurationType in profileConfigurationTypes)
            {
                IAutomapperProfileConfiguration <T> profileConfiguration =
                    Activator.CreateInstance(profileConfigurationType) as IAutomapperProfileConfiguration <T>;

                if (profileConfiguration == null)
                {
                    throw new NullReferenceException();
                }

                profileConfiguration.Configure(aProfile.Profile);
            }
        }
        public static void ConfigureFromAssembly <T>(this IAutomapperProfile <T> aProfile)
        {
            Assembly assembly = aProfile.GetType().Assembly;

            ConfigureFromAssembly(aProfile, assembly);
        }