Beispiel #1
0
        public void MakeOptional_HasMapper_ReturnsExpected()
        {
            var innerReader = new ColumnIndexValueReader(1);
            OneToOneMap <string> propertyMap = Map(t => t.Value).WithReader(innerReader);

            Assert.False(propertyMap.Optional);
            Assert.Same(propertyMap, propertyMap.MakeOptional());
            Assert.True(propertyMap.Optional);
            Assert.Same(innerReader, propertyMap.CellReader);
        }
Beispiel #2
0
        public void WithColumnIndex_ValidColumnIndex_Success(int columnIndex)
        {
            SingleExcelPropertyMap <string> propertyMap = Map(t => t.Value);

            Assert.Same(propertyMap, propertyMap.WithColumnIndex(columnIndex));

            ColumnIndexValueReader reader = Assert.IsType <ColumnIndexValueReader>(propertyMap.CellReader);

            Assert.Equal(columnIndex, reader.ColumnIndex);
        }
Beispiel #3
0
        public void WithColumnIndex_OptionalColumn_Success()
        {
            SingleExcelPropertyMap <string> propertyMap = Map(t => t.Value).MakeOptional();

            Assert.Same(propertyMap, propertyMap.WithColumnIndex(1));

            OptionalCellValueReader reader      = Assert.IsType <OptionalCellValueReader>(propertyMap.CellReader);
            ColumnIndexValueReader  innerReader = Assert.IsType <ColumnIndexValueReader>(reader.InnerReader);

            Assert.Equal(1, innerReader.ColumnIndex);
        }
Beispiel #4
0
        public void MakeOptional_HasMapper_ReturnsExpected()
        {
            var innerReader = new ColumnIndexValueReader(1);
            SingleExcelPropertyMap <string> propertyMap = Map(t => t.Value).WithReader(innerReader);

            Assert.Same(propertyMap, propertyMap.MakeOptional());

            OptionalCellValueReader reader = Assert.IsType <OptionalCellValueReader>(propertyMap.CellReader);

            Assert.Same(innerReader, reader.InnerReader);
        }
Beispiel #5
0
        public void WithColumnIndex_MultiColumnIndex_Success(int columnIndex)
        {
            MemberInfo propertyInfo = typeof(TestClass).GetProperty(nameof(TestClass.Value));
            var        propertyMap  = new SubPropertyMap(propertyInfo).WithColumnNames("ColumnName");

            Assert.Same(propertyMap, propertyMap.WithColumnIndex(columnIndex));

            SplitCellValueReader   valueReader = Assert.IsType <SplitCellValueReader>(propertyMap.ColumnsReader);
            ColumnIndexValueReader innerReader = Assert.IsType <ColumnIndexValueReader>(valueReader.CellReader);

            Assert.Equal(columnIndex, innerReader.ColumnIndex);
        }
Beispiel #6
0
        public void WithColumnIndex_OptionalColumn_Success()
        {
            OneToOneMap <string> propertyMap = Map(t => t.Value).MakeOptional();

            Assert.True(propertyMap.Optional);
            Assert.Same(propertyMap, propertyMap.WithColumnIndex(1));
            Assert.True(propertyMap.Optional);

            ColumnIndexValueReader innerReader = Assert.IsType <ColumnIndexValueReader>(propertyMap.CellReader);

            Assert.Equal(1, innerReader.ColumnIndex);
        }
        public void WithColumnIndex_MultiColumnIndex_Success(int columnIndex)
        {
            var cellValuesReader = new MultipleColumnNamesValueReader("Column");
            var elementPipeline  = new ValuePipeline <string>();
            CreateElementsFactory <string> createElementsFactory = elements => elements;
            var propertyMap = new ManyToOneEnumerableMap <string>(cellValuesReader, elementPipeline, createElementsFactory).WithColumnNames("ColumnName");

            Assert.Same(propertyMap, propertyMap.WithColumnIndex(columnIndex));

            CharSplitCellValueReader valueReader = Assert.IsType <CharSplitCellValueReader>(propertyMap.CellValuesReader);
            ColumnIndexValueReader   innerReader = Assert.IsType <ColumnIndexValueReader>(valueReader.CellReader);

            Assert.Equal(columnIndex, innerReader.ColumnIndex);
        }
Beispiel #8
0
        /// <summary>
        /// Sets the reader for multiple values to split the value of a single cell contained in the column
        /// at the given zero-based index.
        /// </summary>
        /// <param name="columnIndex">The zero-bassed index of the column containing the cell to split.</param>
        /// <returns>The property map that invoked this method.</returns>
        public EnumerableExcelPropertyMap <T> WithColumnIndex(int columnIndex)
        {
            var reader = new ColumnIndexValueReader(columnIndex);

            if (ColumnsReader is SplitCellValueReader splitColumnReader)
            {
                splitColumnReader.CellReader = reader;
            }
            else
            {
                ColumnsReader = new SplitCellValueReader(reader);
            }

            return(this);
        }
        public void Ctor_ColumnIndex(int columnIndex)
        {
            var reader = new ColumnIndexValueReader(columnIndex);

            Assert.Equal(columnIndex, reader.ColumnIndex);
        }