public void ValidateTypeMapping_UniqueMapping_DoesNotThrowException() { var validator = new TypeMappingValidator(AutomapperConfig.Create(), target, MappingBehaviors.None); // Act validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); }
public AutomapperConfig CreateConfiguration() { return(AutomapperConfig.Create() .AndDoNotMapFor(typeof(InterfaceToIgnore)) .AndMapAsSingleton(typeof(SingletonInterface)) .AndUseMultimappingFor(typeof(MultimappingInterface)) .AndUseNamedMappingFor(typeof(NamedType), "Bananas")); }
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); }
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 <,>)); }
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_ConcreteDoesNotMatch_ReturnsNoMappings() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IInterface), typeof(String)); // Assert Assert.IsFalse(mappings.Any()); }
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))); }
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_ClosedGenericImplementationForNonGenericInterface_MapsIt() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IInterface), typeof(ClosedGenericImplementation)); // Assert AssertMapping <IInterface, ClosedGenericImplementation>(mappings); }
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)); }
public void CreateLifetimeManager_InterfaceHasCustomLifetimeManager_ReturnsIt() { var factory = new ConfigLifetimeManagerFactory(AutomapperConfig.Create().AndMapWithLifetimeManager <HierarchicalLifetimeManager>(typeof(IEnumerable))); // Act var lifetimeManager = factory.CreateLifetimeManager(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); // Assert Assert.IsInstanceOfType(lifetimeManager, typeof(HierarchicalLifetimeManager)); }
public void CreateLifetimeManager_ImplementationIsASingleton_ReturnsTransientLifetimeManager() { var factory = new ConfigLifetimeManagerFactory(AutomapperConfig.Create().AndMapAsSingleton(typeof(ArrayList))); // Act var lifetimeManager = factory.CreateLifetimeManager(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); // Assert Assert.IsInstanceOfType(lifetimeManager, typeof(TransientLifetimeManager)); }
public void CreateLifetimeManager_InterfaceIsASingleton_ReturnsContainerControlledLifetimeManager() { var factory = new ConfigLifetimeManagerFactory(AutomapperConfig.Create().AndMapAsSingleton(typeof(IEnumerable))); // Act var lifetimeManager = factory.CreateLifetimeManager(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); // Assert Assert.IsInstanceOfType(lifetimeManager, typeof(ContainerControlledLifetimeManager)); }
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_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 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 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 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 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 void CreatMappings_MultipleInterfacesWithSameConcreteImplentation_ReturnsBothMappings() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IInterface), typeof(CompoundImplementation), typeof(IOther)); // Assert AssertMapping <IInterface, CompoundImplementation>(mappings); AssertMapping <IOther, CompoundImplementation>(mappings); Assert.AreEqual(2, mappings.Count()); }
public void CreateMappings_MultipleInterfacesBothHaveADifferentMatch_ReturnsBothMappings() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IInterface), typeof(InterfaceImplementation), typeof(IOther), typeof(OtherImplementation)); // Assert AssertMapping <IInterface, InterfaceImplementation>(mappings); AssertMapping <IOther, OtherImplementation>(mappings); Assert.AreEqual(2, mappings.Count()); }
public void CreateMappings_MultipleSimpleMatches_ReturnsAllTypeMappings() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IInterface), typeof(InterfaceImplementation), typeof(InterfaceImplementationTwo)); // Assert AssertMapping <IInterface, InterfaceImplementation>(mappings); AssertMapping <IInterface, InterfaceImplementationTwo>(mappings); Assert.AreEqual(2, mappings.Count()); }
public void CreateMappings_GenericInterfaceWithMultipleOpenImplementations_MapsThem() { // Act var mappings = factory.CreateMappings(MappingBehaviors.None, AutomapperConfig.Create(), typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>), typeof(OpenGenericConcreteTwo <,>)); // Assert AssertMapping(mappings, typeof(IGenericInterface <,>), typeof(OpenGenericConcrete <,>)); AssertMapping(mappings, typeof(IGenericInterface <,>), typeof(OpenGenericConcreteTwo <,>)); Assert.AreEqual(2, mappings.Count()); }
private static AutomapperConfig GetFactory(Boolean useMultiMapping = false, String namedMapping = null) { var config = AutomapperConfig.Create(); if (useMultiMapping) { config = config.AndUseMultimappingFor(typeof(Object)); } if (namedMapping != null) { config = config.AndUseNamedMappingFor(typeof(String), namedMapping); } return(config); }
public AutomapperConfig CreateConfiguration() { var config = AutomapperConfig.Create() .AndMapAsSingleton(singletons.ToArray()) .AndUsePolicyInjectionFor(policyInjections.ToArray()) .AndUseMultimappingFor(multimaps.ToArray()) .AndDoNotMapFor(doNotMaps.ToArray()); foreach (var mapping in namedMappings) { config = config.AndUseNamedMappingFor(mapping.Item1, mapping.Item2); } return(config); }
public void ValidateTypeMapping_InterfaceAlreadyMapped_ThrowsDuplicateMappingException() { var validator = new TypeMappingValidator(AutomapperConfig.Create(), target, MappingBehaviors.None); target.RegisterType <IEnumerable, SortedList>(); // Act try { validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); } catch (DuplicateMappingException ex) { Assert.AreEqual("Attempted to map at least two concrete types (System.Collections.SortedList and System.Collections.ArrayList) to the same interface (System.Collections.IEnumerable).", ex.Message); Assert.AreEqual(typeof(IEnumerable), ex.MappingInterface); Assert.AreEqual(typeof(ArrayList), ex.DuplicateMappingConcrete); Assert.AreEqual(typeof(SortedList), ex.MappedConcrete); throw; } }
public void ValidateTypeMapping_MultimappingExistsWithSameImplicitNameForSameType_ThrowsDuplicateMappingException() { var validator = new TypeMappingValidator(AutomapperConfig.Create(), target, MappingBehaviors.MultimapByDefault); target.RegisterType <IEnumerable, SortedList>("System.Collections.ArrayList"); // Act try { validator.ValidateTypeMapping(new TypeMapping(typeof(IEnumerable), typeof(ArrayList))); } catch (DuplicateMappingException ex) { Assert.AreEqual("Attempted to map at least two concrete types (System.Collections.SortedList and System.Collections.ArrayList) with the same name ('System.Collections.ArrayList').", ex.Message); Assert.AreEqual(typeof(IEnumerable), ex.MappingInterface); Assert.AreEqual(typeof(ArrayList), ex.DuplicateMappingConcrete); Assert.AreEqual(typeof(SortedList), ex.MappedConcrete); throw; } }
public void CreateMappings_CollectionRegistrationAndMultipleMappingsAcrossManyTimes_DoesNotCreateCollectionMapping() { // Act var mappings = factory.CreateMappings(MappingBehaviors.CollectionRegistration, AutomapperConfig.Create(), typeof(IInterface), typeof(InterfaceImplementation), typeof(IOther), typeof(OtherImplementation)); // Assert AssertMapping <IEnumerable <IInterface>, UnityCollectionFacade <IInterface> >(mappings, Expectation.ShouldNotExist); AssertMapping <IEnumerable <IOther>, UnityCollectionFacade <IOther> >(mappings, Expectation.ShouldNotExist); }
public void CreateMappings_CollectionRegistrationAndSingleMappingThatIsMultimapped_CreatesCollectionMapping() { // Act var mappings = factory.CreateMappings(MappingBehaviors.CollectionRegistration, AutomapperConfig.Create() .AndUseMultimappingFor(typeof(IInterface)), typeof(IInterface), typeof(InterfaceImplementation)); // Assert AssertMapping <IEnumerable <IInterface>, UnityCollectionFacade <IInterface> >(mappings, Expectation.ShouldExist); }
public void CreateMappings_CollectionRegistrationAndMultipleMappings_CreatesCollectionMapping() { // Act var mappings = factory.CreateMappings(MappingBehaviors.CollectionRegistration, AutomapperConfig.Create(), typeof(IInterface), typeof(InterfaceImplementation), typeof(InterfaceImplementationTwo)); // Assert AssertMapping <IEnumerable <IInterface>, UnityCollectionFacade <IInterface> >(mappings); }