Ejemplo n.º 1
0
        private dynamic EntityAs(Entity entity, Type requested, Type[] types)
        {
            int     key    = types.Except(new[] { requested }).Aggregate(requested.GetHashCode(), (current, additionalType) => current ^ additionalType.GetHashCode());
            dynamic result = GetFromCache(entity, key);

            if (result != null)
            {
                return(result);
            }

            IEntityMapping mapping;

            switch (types.Length)
            {
            case 1:
                mapping = GetMapping(types[0]);
                break;

            case 0:
                types   = new[] { requested };
                mapping = GetMapping(requested);
                break;

            default:
                mapping = new MultiMapping(types.Select(GetMapping).ToArray());
                break;
            }

            AssertEntityTypes(entity, mapping);
            return(EntityAs(entity, mapping, types, key));
        }
Ejemplo n.º 2
0
        public void Multimapping_should_not_throw_when_getting_derived_properties()
        {
            // given
            IEntityMapping herbivoreMapping = MappingsRepository.MappingFor <IHerbivore>();
            IEntityMapping carnivoreMapping = MappingsRepository.MappingFor <ICarnivore>();

            // when
            var multiMapping = new MultiMapping(herbivoreMapping, carnivoreMapping);

            // then
            Assert.DoesNotThrow(() => multiMapping.PropertyFor("Name"));
        }
        public void Multimapping_should_not_throw_when_getting_derived_properties()
        {
            // given
            IEntityMapping herbivoreMapping = MappingsRepository.MappingFor<IHerbivore>();
            IEntityMapping carnivoreMapping = MappingsRepository.MappingFor<ICarnivore>();

            // when
            var multiMapping = new MultiMapping(herbivoreMapping, carnivoreMapping);

            // then
            Assert.DoesNotThrow(() => multiMapping.PropertyFor("Name"));
        }