public void GivenCreateCalled_AndListOfHeaderNamesProvided_WhenSetupColumnHeaders_ThenSavedFileContainsEachHeaderName() { string expectedE2Column = "Test"; string expectedF2Column = "Column"; string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx"); byte[] templateData = File.ReadAllBytes(@"TestData\StudentProfileExportTemplate.xltx"); using (MemoryStream stream = new MemoryStream()) { stream.Write(templateData, 0, (int)templateData.Length); using (var target = new StudentProfileExportFile()) { target.Create(stream); target.SetupColumnHeaders(new[] { expectedE2Column, expectedF2Column }); } File.WriteAllBytes(outputPath, stream.ToArray()); } using (XLWorkbook workbook = new XLWorkbook(outputPath)) { IXLWorksheet worksheet = workbook.Worksheet(1); IXLCell actualE2Cell = worksheet.Cell(2, "A"); IXLCell actualF2Cell = worksheet.Cell(2, "B"); Assert.AreEqual(expectedE2Column, actualE2Cell.Value); Assert.AreEqual(expectedF2Column, actualF2Cell.Value); } }
public void GivenCreateNotCalled_WhenSetupColumnHeaders_ThenThrowException() { using (var target = new StudentProfileExportFile()) { target.ExpectException <InvalidOperationException>(() => target.SetupColumnHeaders(new[] { "whatever" })); } }
public void GivenNullColumnNames_WhenSetupColumnHeaders_ThenThrowException() { using (var target = new StudentProfileExportFile()) { target.ExpectException <ArgumentNullException>(() => target.SetupColumnHeaders(null)); } }
public void GivenCreateCalled_AndHeaderTextProvided_WhenSetupColumnHeaders_ThenSavedFileContainsAddedHeaderCellWithFormatting() { string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx"); byte[] templateData = File.ReadAllBytes(@"TestData\StudentProfileExportTemplate.xltx"); using (MemoryStream stream = new MemoryStream()) { stream.Write(templateData, 0, (int)templateData.Length); using (var target = new StudentProfileExportFile()) { target.Create(stream); target.SetupColumnHeaders(new[] { "whatever", "to be formatted" }); } File.WriteAllBytes(outputPath, stream.ToArray()); } using (XLWorkbook workbook = new XLWorkbook(outputPath)) { IXLWorksheet worksheet = workbook.Worksheet(1); IXLCell preexistingHeaderCell = worksheet.Cell(2, "A"); IXLCell actualAddedHeaderCell = worksheet.Cell(2, "B"); Assert.AreEqual(preexistingHeaderCell.Style, actualAddedHeaderCell.Style); } }
public void GivenCreateCalled_WhenSetupColumnHeaders_ThenSucceed() { byte[] templateData = File.ReadAllBytes(@"TestData\StudentProfileExportTemplate.xltx"); using (MemoryStream stream = new MemoryStream()) { stream.Write(templateData, 0, (int)templateData.Length); using (var target = new StudentProfileExportFile()) { target.Create(stream); target.SetupColumnHeaders(new[] { "whatever" }); } } }