コード例 #1
0
        /// <summary>
        ///     Checks and throws the <see cref="ExcelValidationException" /> if header columns does not match with properties of
        ///     object
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="worksheet"></param>
        /// <param name="headerRowIndex"></param>
        /// <param name="formattedExceptionMessage"></param>
        public static void CheckHeadersAndThrow <T>(this ExcelWorksheet worksheet, int headerRowIndex, string formattedExceptionMessage = null)
        {
            List <ExcelTableColumnAttributeAndPropertyInfo> properyInfoAndColumnAttributes = typeof(T).GetExcelTableColumnAttributesWithPropertyInfo();

            for (var i = 0; i < properyInfoAndColumnAttributes.Count; i++)
            {
                worksheet.CheckColumnAndThrow(headerRowIndex, i + 1, properyInfoAndColumnAttributes[i].ToString(), formattedExceptionMessage);
            }
        }
コード例 #2
0
        public void Should_check_and_throw_exception_if_column_value_is_wrong_on_specified_index()
        {
            //-----------------------------------------------------------------------------------------------------------
            // Arrange
            //-----------------------------------------------------------------------------------------------------------
            ExcelWorksheet worksheet = excelPackage1.GetWorksheet("TEST6");

            //-----------------------------------------------------------------------------------------------------------
            // Act
            //-----------------------------------------------------------------------------------------------------------
            Action action1 = () => worksheet.CheckColumnAndThrow(2, 3, "Barcode", "Barcode column is missing");

            Action action2 = () => worksheet.CheckColumnAndThrow(2, 1, "Barcode");

            Action action3 = () => worksheet.CheckColumnAndThrow(3, 14, "Barcode");

            //-----------------------------------------------------------------------------------------------------------
            // Assert
            //-----------------------------------------------------------------------------------------------------------
            action1.Should().Throw <ExcelValidationException>().And.Message.Should().Be("Barcode column is missing");
            action2.Should().NotThrow();
            action3.Should().Throw <ExcelValidationException>();
        }