private static IEnumerable<TypeMapping> CreateAcrMappings(IEnumerable<TypeMapping> mappings, AutomapperConfig configurationDetails)
		{
			Contract.Requires(mappings != null);
			return mappings
					.GroupBy(m => m.From)
					.Where(g => g.Count() > 1 || configurationDetails.IsMultimap(g.Key))
					.Select(g => new TypeMapping(GetGenericTypeSafely(typeof(IEnumerable<>), g.Key), GetGenericTypeSafely(typeof(UnityCollectionFacade<>), g.Key)));
		}
 public override void Load()
 {
     Kernel.Bind <IEmployeeService>().To <EmployeeService>();
     Kernel.Bind <IVacationService>().To <VacationService>();
     Kernel.Bind <IBaseService <JobBll> >().To <JobService>();
     Kernel.Bind <IBaseService <DepartamentBll> >().To <DepartamentService>();
     Kernel.Bind <MyDbContext>().ToSelf();
     Kernel.Bind <IMapper>().ToMethod((_) => AutomapperConfig.GetMapper());
 }
 private void InvoiceDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(InvoiceDg.SelectedItem is Employee employee))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Employee, EmployeeViewModel>();
     EmployeeInfo.DataContext = _cfg.CreateMapper().Map <EmployeeViewModel>(employee);
 }
示例#4
0
        public static void Main(string[] args)
        {
            var host     = BuildWebHost(args);
            var services = host.Services;

            DbConfig.Initialize(services);
            AutomapperConfig.Configure();
            host.Run();
        }
示例#5
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AutomapperConfig.CreateMaps();
     AutofacConfig.RegisterDependencies();
 }
        protected override void RegisterAdditionalServices(IWindsorContainer container)
        {
            AutomapperConfig.Configure();

            //Fixes problem where .Fetch is used in a query
            container.Register(Component.For <IQueryExtensionProvider>().ImplementedBy <QueryExtensionFakes>().Named("queryExtensionProvider"));

            base.RegisterAdditionalServices(container);
        }
 private void InvoiceDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(InvoiceDg.SelectedItem is Supplier supplier))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Supplier, SupplierViewModel>();
     CustomerInfo.DataContext = _cfg.CreateMapper().Map <SupplierViewModel>(supplier);
 }
示例#8
0
        public static void RegisterTypes()
        {
            var container = new UnityContainer();

            container.RegisterInstance <IUnityContainer>(container);
            AutomapperConfig.RegisterWithUnity(container);

            DependencyResolver.SetResolver(new UnityDependencyResolver(container));
        }
        public void CreateMappings_GenericInterfaceWithClosedImplementation_MapsIt()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(),
                                                  typeof(IGenericInterface <,>), typeof(ClosedGenericConcrete));

            // Assert
            AssertMapping(mappings, typeof(IGenericInterface <String, Boolean>), typeof(ClosedGenericConcrete));
        }
 private static AutomapperConfig GetConfigurationDetails(IEnumerable <Type> types)
 {
     return(types
            .Where(type => typeof(IAutomapperConfigProvider).IsAssignableFrom(type))
            .Select(providerType => (IAutomapperConfigProvider)Activator.CreateInstance(providerType))
            .Cast <IAutomapperConfigProvider>()
            .Select(provider => provider.CreateConfiguration())
            .Aggregate(AutomapperConfig.CreateFromAttributes(types), (accumulator, config) => accumulator.MergeWith(config)));
 }
示例#11
0
        public void ValidateTypeMapping_InterfaceAlreadyMappedAndIsAMultimap_DoesNotThrowException()
        {
            var validator = new TypeMappingValidator(AutomapperConfig.Create().AndUseMultimappingFor(typeof(IEnumerable)), target, MappingBehaviors.None);

            target.RegisterType <IEnumerable, SortedList>();

            // Act
            validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList)));
        }
        public void CreateMappings_ClosedGenericImplementationForNonGenericInterface_MapsIt()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(),
                                                  typeof(IInterface), typeof(ClosedGenericImplementation));

            // Assert
            AssertMapping <IInterface, ClosedGenericImplementation>(mappings);
        }
示例#13
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     AutomapperConfig.Configure();
 }
        public void CreateMappings_InterfaceIsDoNotMap_DoesNotMap()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create().AndDoNotMapFor(typeof(IInterface)),
                                                  typeof(IInterface), typeof(InterfaceImplementation));

            // Assert
            AssertMapping <IInterface, InterfaceImplementation>(mappings, Expectation.ShouldNotExist);
        }
示例#15
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     GlobalConfiguration.Configure(WebApiConfig.Register);
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     AutomapperConfig.Register();
     Cache.Add(CacheVariables.Roles.ToString(), Starter.GetAuthorization());
 }
 private void InvoiceDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(InvoiceDg.SelectedItem is Patient patient))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Patient, PatientViewModel>();
     PatientInfo.DataContext = _cfg.CreateMapper().Map <PatientViewModel>(patient);
 }
示例#17
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     FluentValidation.Mvc.FluentValidationModelValidatorProvider.Configure();
     AutomapperConfig.RegisterMaps();
 }
示例#18
0
 private void InvoiceDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(InvoiceDg.SelectedItem is Product product))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Product, ProductViewModel>();
     CustomerInfo.DataContext = _cfg.CreateMapper().Map <ProductViewModel>(product);
 }
 private void InvoiceDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(InvoiceDg.SelectedItem is Medicine medicine))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Medicine, MedicineViewModel>();
     CustomerInfo.DataContext = _cfg.CreateMapper().Map <MedicineViewModel>(medicine);
 }
示例#20
0
        public void ValidateTypeMapping_MappingExistsForTypeWithAnotherName_DoesNotThrowException()
        {
            var validator = new TypeMappingValidator(AutomapperConfig.Create().AndUseNamedMappingFor(typeof(ArrayList), "TEST"), target, MappingBehaviors.MultimapByDefault);

            target.RegisterType <IEnumerable, SortedList>("ANOTHER NAME");

            // Act
            validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList)));
        }
        public void CreateMappings_OpenGenericInterfaceWithOpenImplementation_MapsIt()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(),
                                                  typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>));

            // Assert
            AssertMapping(mappings, typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>));
        }
示例#22
0
        public void ValidateTypeMapping_ConcreteMappedToOtherInterface_DoesNotThrowException()
        {
            var validator = new TypeMappingValidator(AutomapperConfig.Create(), target, MappingBehaviors.None);

            target.RegisterType <Object, ArrayList>();

            // Act
            validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList)));
        }
 private void CategoryDg_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (!(CategoryDg.SelectedItem is Category category))
     {
         return;
     }
     _cfg = AutomapperConfig.Config <Category, CategoryViewModel>();
     CategoryInfo.DataContext = _cfg.CreateMapper().Map <CategoryViewModel>(category);
 }
示例#24
0
        public void TestInsertNewUserReturnsExpectedValue1()
        {
            #region Arrange
            const string applicationName = "Name2";
            ControllerRecordFakes.FakeUsers(3, UserRepository);
            AutomapperConfig.Configure();
            var serviceUser = CreateValidEntities.ServiceUser(4);
            ControllerRecordFakes.FakeApplications(3, ApplicationRepository);
            ControllerRecordFakes.FakeRoles(3, RoleRepository);
            ControllerRecordFakes.FakeUnits(3, UnitRepository);
            ControllerRecordFakes.FakePermissions(3, PermissionRepository);
            ControllerRecordFakes.FakeUnitAssociations(3, UnitAssociationRepository);
            #endregion Arrange

            #region Act
            var result = Controller.InsertNewUser(applicationName, serviceUser, 3, 2)
                         .AssertResultIs <JsonResult>();
            #endregion Act

            #region Assert
            Assert.IsNotNull(result);
            var result2 = (ServiceUser)result.Data;
            Assert.IsNotNull(result2);
            Assert.AreEqual("*****@*****.**", result2.Email);
            Assert.AreEqual("FirstName4", result2.FirstName);
            Assert.AreEqual("LastName4", result2.LastName);
            Assert.AreEqual("LoginId4", result2.Login);
            Assert.AreEqual("+1 530 755 7777", result2.Phone);

            UserRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <User> .Is.Anything));
            var userArgs = (User)UserRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <User> .Is.Anything))[0][0];
            Assert.AreEqual("*****@*****.**", userArgs.Email);
            Assert.AreEqual("FirstName4", userArgs.FirstName);
            Assert.IsFalse(userArgs.Inactive);
            Assert.AreEqual("LastName4", userArgs.LastName);
            Assert.AreEqual("LoginId4", userArgs.LoginId);
            Assert.AreEqual("+1 530 755 7777", userArgs.Phone);

            PermissionRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <Permission> .Is.Anything));
            var permissionArgs = (Permission)PermissionRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <Permission> .Is.Anything))[0][0];
            Assert.IsNotNull(permissionArgs);
            Assert.AreEqual(applicationName, permissionArgs.Application.ToString());
            Assert.AreEqual("Name3", permissionArgs.Role.Name);
            Assert.IsFalse(permissionArgs.Inactive);
            Assert.AreEqual(userArgs.LoginId, permissionArgs.User.LoginId);

            UnitAssociationRepository.AssertWasCalled(a => a.EnsurePersistent(Arg <UnitAssociation> .Is.Anything));
            var unitAssociationArgs = (UnitAssociation)UnitAssociationRepository.GetArgumentsForCallsMadeOn(a => a.EnsurePersistent(Arg <UnitAssociation> .Is.Anything))[0][0];
            Assert.IsNotNull(unitAssociationArgs);
            Assert.AreEqual(applicationName, unitAssociationArgs.Application.ToString());
            Assert.AreEqual("ShortName2", unitAssociationArgs.Unit.ShortName);
            Assert.IsFalse(unitAssociationArgs.Inactive);
            Assert.AreEqual(userArgs.LoginId, unitAssociationArgs.User.LoginId);

            #endregion Assert
        }
		private static void CheckForExistingNamedMapping(IUnityContainer target, TypeMapping mapping, AutomapperConfig configurationDetails)
		{
			var mappingName = configurationDetails.GetNamedMapping(mapping);
			var existingRegistration = target.Registrations
												.Where(r => String.Equals(r.Name, mappingName))
												.Where(r => r.RegisteredType.Equals(mapping.From))
												.FirstOrDefault();
			if (existingRegistration != null)
				throw new DuplicateMappingException(mapping.From, existingRegistration.MappedToType, mapping.To, mappingName);
		}
		public RegistrationNameFactory(AutomapperConfig configurationDetails, IEnumerable<TypeMapping> typeMappings, MappingBehaviors mappingBehaviors)
		{
			this.mappingBehaviors = mappingBehaviors;
			this.configurationDetails = configurationDetails;
			multimapTypes = typeMappings
								.GroupBy(t => t.From)
								.Where(t => t.Count() > 1)
								.Select(group => group.Key)
								.ToArray();
		}
示例#27
0
        public Startup(IConfiguration configuration, IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true);

            Configuration = configuration;
            AutomapperConfig.Configure();
        }
        public void CreateInjectionMembers_ToTypeMethodHasCallHandlerAttribute_ReturnsInjectionMembers()
        {
            var factory = new InjectionMemberFactory(AutomapperConfig.Create());

            // Act
            var members = factory.CreateInjectionMembers(new TypeMapping(typeof(EmptyInterface), typeof(EmptyInterfaceAttributeOnMethod)));

            // Assert
            AssertHasInjectionMembers(members);
        }
        public void CreateInjectionMembers_FromTypeMethodHasCallHandlerAttribute_ReturnsInjectionMembers()
        {
            var factory = new InjectionMemberFactory(AutomapperConfig.Create());

            // Act
            var members = factory.CreateInjectionMembers(new TypeMapping(typeof(OtherInterface), typeof(SampleImplementer)));

            // Assert
            AssertHasInjectionMembers(members);
        }
        public void CreateInjectionMembers_TypeIsPolicyInjected_ReturnsInjectionMembers()
        {
            var factory = new InjectionMemberFactory(AutomapperConfig.Create().AndUsePolicyInjectionFor(typeof(String)));

            // Act
            var members = factory.CreateInjectionMembers(new TypeMapping(typeof(String), typeof(String)));

            // Assert
            AssertHasInjectionMembers(members);
        }
        public void CreateInjectionMembers_TypeIsNotPolicyInjected_ReturnsEmptyCollection()
        {
            var factory = new InjectionMemberFactory(AutomapperConfig.Create());

            // Act
            var members = factory.CreateInjectionMembers(new TypeMapping(typeof(String), typeof(String)));

            // Assert
            Assert.IsFalse(members.Any());
        }
        public void CreateMappings_MultipleInterfacesOneHasAMatch_ReturnsThatMapping()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(),
                                                  typeof(IInterface), typeof(InterfaceImplementation), typeof(IOther));

            // Assert
            AssertMapping <IInterface, InterfaceImplementation>(mappings);
            Assert.AreEqual(1, mappings.Count());
        }
        public void CreateMappings_GenericInterfaceMultipleImplementationsForDifferentTypes_MapsThem()
        {
            // Act
            var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(),
                                                  typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>), typeof(ClosedGenericConcrete));

            // Assert
            AssertMapping(mappings, typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>));
            AssertMapping(mappings, typeof(IGenericInterface <String, Boolean>), typeof(ClosedGenericConcrete));
        }
		public IEnumerable<TypeMapping> CreateMappings(MappingBehaviors behaviors, AutomapperConfig configurationDetails, params Type[] types)
		{
			var results = from availableInterface in types.Where(type => type.IsInterface)
														  .Where(configurationDetails.IsMappable)
						  from concrete in types.Where(type => !type.IsInterface)
												.Where(configurationDetails.IsMappable)
						  from concreteInterface in concrete.GetGenericallyOpenInterfaces()
															.Where(ci => ci.Item1 == availableInterface)
						  let matchingPair = new { concrete, concreteInterface }
						  group matchingPair by matchingPair.concreteInterface.Item2 into mappingsForAnInterface
						  from mapping in mappingsForAnInterface
						  select new TypeMapping(mapping.concreteInterface.Item2, mapping.concrete);

			if (!behaviors.HasFlag(MappingBehaviors.CollectionRegistration))
				return results.ToArray();

			return CreateAcrMappings(results, configurationDetails)
							.Union(results)
							.ToArray();
		}
		/// <summary>
		/// Initializes a new instance of the TypeMappingValidator class.
		/// </summary>
		/// <param name="configurationDetails"></param>
		/// <param name="target"></param>
		/// <param name="behaviors"></param>
		public TypeMappingValidator(AutomapperConfig configurationDetails, IUnityContainer target, MappingBehaviors behaviors)
		{
			this.target = target;
			this.configurationDetails = configurationDetails;
			this.mappingBehaviors = behaviors;
		}
		public InjectionMemberFactory(AutomapperConfig configurationDetails)
		{
			this.configurationDetails = configurationDetails;
		}
		public ConfigLifetimeManagerFactory(AutomapperConfig configurationDetails)
		{
			this.configurationDetails = configurationDetails;
		}