public void Should_throw_an_exception_when_columns_of_worksheet_not_matched_with_ExcelTableAttribute() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet1 = excelPackage1.GetWorksheet("TEST6"); ExcelWorksheet emptySheet1 = excelPackage1.GetWorksheet("EmptySheet"); ExcelWorksheet emptySheet2 = excelPackage1.GetWorksheet("EmptySheet"); //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action1 = () => worksheet1.CheckHeadersAndThrow <NamedMap>(2, "The {0}.column of worksheet should be '{1}'."); Action action2 = () => worksheet1.CheckHeadersAndThrow <NamedMap>(2); Action action3 = () => worksheet1.CheckHeadersAndThrow <StocksNullable>(2); Action action4 = () => worksheet1.CheckHeadersAndThrow <Car>(2); Action actionForEmptySheet1 = () => emptySheet1.CheckHeadersAndThrow <StocksValidation>(1, "The {0}.column of worksheet should be '{1}'."); Action actionForEmptySheet2 = () => emptySheet2.CheckHeadersAndThrow <Cars>(1, "The {0}.column of worksheet should be '{1}'."); //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action1.Should().Throw <ExcelValidationException>().And.Message.Should().Be("The 1.column of worksheet should be 'Name'."); action2.Should().Throw <ExcelValidationException>().And.Message.Should().Be("The 1. column of worksheet should be 'Name'."); action3.Should().NotThrow <ExcelValidationException>(); action4.Should().Throw <ArgumentException>(); actionForEmptySheet1.Should().Throw <ExcelValidationException>().And.Message.Should().Be("The 1.column of worksheet should be 'Barcode'."); actionForEmptySheet2.Should().Throw <ExcelValidationException>().And.Message.Should().Be("The 1.column of worksheet should be 'LicensePlate'."); }
public void Should_throw_an_exception_when_columns_of_worksheet_not_matched_with_ExcelTableAttribute() { //----------------------------------------------------------------------------------------------------------- // Arrange //----------------------------------------------------------------------------------------------------------- ExcelWorksheet worksheet = excelPackage.Workbook.Worksheets["TEST6"]; //----------------------------------------------------------------------------------------------------------- // Act //----------------------------------------------------------------------------------------------------------- Action action1 = () => { worksheet.CheckHeadersAndThrow <NamedMap>(1, "The {0}.column of worksheet should be '{1}'."); }; Action action2 = () => { worksheet.CheckHeadersAndThrow <NamedMap>(1); }; Action action3 = () => { worksheet.CheckHeadersAndThrow <StocksNullable>(1); }; Action action4 = () => { worksheet.CheckHeadersAndThrow <Car>(1); }; //----------------------------------------------------------------------------------------------------------- // Assert //----------------------------------------------------------------------------------------------------------- action1.Should().Throw <ExcelTableValidationException>().And.Message.Should().Be("The 1.column of worksheet should be 'Name'."); action2.Should().Throw <ExcelTableValidationException>().And.Message.Should().Be("The 1. column of worksheet should be 'Name'."); action3.Should().NotThrow <ExcelTableValidationException>(); action4.Should().Throw <ArgumentException>(); }