public void LocatorCalledOnceWhenCaching()
        {
            var locator = new Mock<IServiceLocator>(MockBehavior.Strict);
            var engine = new SimpleMappingEngine(locator.Object) { CacheMappers = true };

            var expected = new AnimalAnimalModelMapper();
            var type = typeof(IMapper<Animal, AnimalModel>);
            locator.Setup(x => x.GetInstance(type)).Returns(expected);

            var candidate = engine.Mapper<Animal, AnimalModel>();
            candidate = engine.Mapper<Animal, AnimalModel>();

            Assert.IsNotNull(candidate);
            locator.Verify(x => x.GetInstance(type), Times.Once());
        }
Esempio n. 2
0
        /// <summary>
        /// Check whether a mapper is in a version.
        /// </summary>
        /// <typeparam name="TSource">Source type</typeparam>
        /// <typeparam name="TDestination">Result type</typeparam>
        /// <param name="engine">Engine to use.</param>
        /// <param name="implementation">Type of mapper we expect</param>
        /// <param name="name"></param>
        public static void ResolveMapper <TSource, TDestination>(this SimpleMappingEngine engine, Type implementation, string name = null)
        {
            if (engine == null)
            {
                throw new NotSupportedException("Must supply engine");
            }
            IMapper <TSource, TDestination> mapper;

            if (name == null)
            {
                mapper = engine.Mapper <TSource, TDestination>();
            }
            else
            {
                mapper = engine.Mapper <TSource, TDestination>(name);
            }
            Assert.AreSame(mapper.GetType(), implementation, string.Format("{0} vs {1}", implementation.FullName, mapper.GetType().FullName));
        }
        public void RegisteredMapperIsReturned()
        {
            var locator = new Mock<IServiceLocator>(MockBehavior.Strict);
            var engine = new SimpleMappingEngine(locator.Object);

            engine.RegisterMap(new AnimalAnimalModelMapper());

            var candidate = engine.Mapper<Animal, AnimalModel>();

            Assert.IsNotNull(candidate);
        }
Esempio n. 4
0
        public void LocatorCalledOnceWhenCaching()
        {
            var locator = new Mock <IServiceLocator>(MockBehavior.Strict);
            var engine  = new SimpleMappingEngine(locator.Object)
            {
                CacheMappers = true
            };

            var expected = new AnimalAnimalModelMapper();
            var type     = typeof(IMapper <Animal, AnimalModel>);

            locator.Setup(x => x.GetInstance(type)).Returns(expected);

            var candidate = engine.Mapper <Animal, AnimalModel>();

            candidate = engine.Mapper <Animal, AnimalModel>();

            Assert.IsNotNull(candidate);
            locator.Verify(x => x.GetInstance(type), Times.Once());
        }
Esempio n. 5
0
        public void RegisteredMapperIsReturned()
        {
            var locator = new Mock <IServiceLocator>(MockBehavior.Strict);
            var engine  = new SimpleMappingEngine(locator.Object);

            engine.RegisterMap(new AnimalAnimalModelMapper());

            var candidate = engine.Mapper <Animal, AnimalModel>();

            Assert.IsNotNull(candidate);
        }