public void GetConverter_WithNonExistingEntry_ThrowsMappingException()
        {
            void Act() => _sut.GetConverter(typeof(int));

            var exception = Assert.Throws <MappingException>(Act);

            Assert.That(exception.Message, Is.EqualTo("No converter for type Int32."));
        }
Beispiel #2
0
        public ITokenStreamMapper <T> CreateForMap(IMap <T> map)
        {
            var setters    = CreateSetterDelegates();
            var converters = GetConverters();

            return(new TokenStreamMapper <T>(setters, converters));

            Action <T, object>[] CreateSetterDelegates()
            {
                var result = new Action <T, object> [map.ColumnCount];

                for (var i = 0; i < map.ColumnCount; i++)
                {
                    result[i] = map.HasDefinitionForColumn(i) ? GetPropSetter(map.GetTargetPropertyName(i)) : _emptyAction;
                }
                return(result);
            }

            IConverter[] GetConverters()
            {
                var result = new IConverter[map.ColumnCount];

                for (var i = 0; i < map.ColumnCount; i++)
                {
                    var targetType = map.GetTargetPropertyType(i);
                    result[i] = _converterRegistry.GetConverter(targetType);
                }

                return(result);
            }
        }