Example #1
0
        void WhenCreatingFromModelWithMappingByLetterAttribute_LetterAttributeIsSetInConfig()
        {
            var result = new MappingConfigByAttributeCreator <LetterAttributeTestModel>().CreateMappingConfig();

            result.Value.ColumnMappings.Single().Should().BeOfType <LetterColumnMapping>()
            .Which.ColumnIndex.Should().Be(2);
        }
Example #2
0
        void WhenCreatingFromModelWithoutAttributes_PropertyIsAutoMapped()
        {
            var result = new MappingConfigByAttributeCreator <AutoMapTestModel>().CreateMappingConfig();

            result.Value.HasHeaders.Should().BeTrue();
            result.Value.ColumnMappings.Should().Contain(c =>
                                                         ((PropertyColumnMapping)c).ColumnName == nameof(AutoMapTestModel.Emailaddress));
        }
Example #3
0
        void WhenPropertyShouldBeUniqueInColumn_UniqueInColumnRuleIsSet()
        {
            var columnName = "UniqueInColumnProperty";

            var result = new MappingConfigByAttributeCreator <AttributeTestModel>().CreateMappingConfig();

            var columnMapping = result.Value.ColumnMappings.Single(c => c.PropertyName.Equals(columnName));

            columnMapping.Rules.OfType <UniqueValuesInColumnRule>().Should().NotBeNull();
        }
Example #4
0
        void WhenPropertyIsRequiredInHeaderRow_RequiredInHeaderRowIsSet()
        {
            var columnName = "RequiredInHeaderProperty";

            var result = new MappingConfigByAttributeCreator <AttributeTestModel>().CreateMappingConfig();

            var columnMapping = result.Value.ColumnMappings.Single(c => c.PropertyName.Equals(columnName)) as IUseHeaderRow;

            columnMapping.IsRequiredInHeaderRow.Should().BeTrue();
        }
Example #5
0
        void WhenCreatingDateTimeWithDefaultValue_DefaultValueIsSet()
        {
            var defaultValue = "Default String Value";

            var result = new MappingConfigByAttributeCreator <AttributeTestModel>().CreateMappingConfig();

            var columnMapping = result.Value.ColumnMappings.Single(c => c.ColumnIndex.Equals(3));

            columnMapping.DefaultValue.Should().Be(defaultValue);
        }
Example #6
0
        void WhenCreatingFromModelWithAttributes_AttributesAreSetInConfig()
        {
            var result = new MappingConfigByAttributeCreator <AttributeTestModel>().CreateMappingConfig();

            var columnMapping = result.Value.ColumnMappings.Single(c => c.ColumnIndex.Equals(3));

            columnMapping.Should().BeOfType <IndexColumnMapping>();
            columnMapping.Rules.OfType <RequiredRule>().Should().NotBeNull();
            columnMapping.Rules.OfType <RegexRule>().Should().NotBeNull();
        }
Example #7
0
        void WhenCreatingFromModelWithMappingByNameAttributeAndRequiredSettingWithWhitespace_NameAttributeIsSetInConfig()
        {
            var columnName = "StringColumn";

            var result = new MappingConfigByAttributeCreator <ColumnNameAttributeTestModel>().CreateMappingConfig();

            result.Value.ColumnMappings.Single().Should().BeOfType <NameColumnMapping>()
            .Which.ColumnName.Should().Be(columnName);

            result.Value.ColumnMappings.Single().ParsingRules.OfType <RequiredRule>().Single().WhiteSpaceAllowed.Should().BeTrue();
        }
Example #8
0
        private MappingConfig GetMappingConfig <T>()
        {
            var type = typeof(T);

            if (_mappingConfigs.TryGetValue(type, out var mappingConfig))
            {
                return(mappingConfig);
            }

            var result = new MappingConfigByAttributeCreator <T>().CreateMappingConfig();

            if (result.IsSuccess)
            {
                return(result.Value);
            }

            throw new ArgumentException($"Could not find mapping configuration for type {type} " +
                                        $"and no SheetToObjectConfig attribute was set on the model " +
                                        $"to map the properties by data attributes");
        }
Example #9
0
        void WhenCreatingDateTimeWithFormat_FormatIsSet()
        {
            var result = new MappingConfigByAttributeCreator <AttributeTestModel>().CreateMappingConfig();

            result.Value.ColumnMappings.Should().Contain(c => c.Format.IsNotNull() && c.Format.Equals("yyyy-MM-dd"));
        }
Example #10
0
        void WhenCreatingFromModelWithoutSheetToObjectConfigAttribute_ItFailsToCreateMappingConfig()
        {
            var result = new MappingConfigByAttributeCreator <WithoutSheetToObjectConfigModel>().CreateMappingConfig();

            result.IsFailure.Should().BeTrue();
        }