public void GivenNullFooterText_WhenSetupFooter_ThenFooterIsEmpty() { byte[] templateData = File.ReadAllBytes(@"TestData\StudentProfileExportTemplate.xltx"); string outputPath = Path.ChangeExtension(Path.Combine("TestData", MethodBase.GetCurrentMethod().Name), ".xlsx"); using (MemoryStream stream = new MemoryStream()) { stream.Write(templateData, 0, (int)templateData.Length); using (var target = new StudentProfileExportFile()) { target.Create(stream); target.SetupFooter(null); } File.WriteAllBytes(outputPath, stream.ToArray()); } using (XLWorkbook workbook = new XLWorkbook(outputPath)) { IXLWorksheet worksheet = workbook.Worksheet(1); string actualOdd = worksheet.PageSetup.Footer.GetText(XLHFOccurrence.OddPages); string actualEven = worksheet.PageSetup.Footer.GetText(XLHFOccurrence.EvenPages); Assert.AreEqual(string.Empty, actualOdd); Assert.AreEqual(string.Empty, actualEven); } }
public void GivenCreateNotCalled_WhenSetupFooter_ThenThrowException() { using (var target = new StudentProfileExportFile()) { target.ExpectException <InvalidOperationException>(() => target.SetupFooter("whatever")); } }
public void GivenCreateCalled_WhenSetupFooter_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.SetupFooter("whatever"); } } }
public void GivenFooterText_AndFooterTextExceeds255Characters_WhenSetupFooter_ThenThrowException() { StringBuilder tooLong = new StringBuilder(); for (int i = 0; i < 256; i++) { tooLong.Append('a'); } 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.ExpectException <ArgumentException>(() => target.SetupFooter(tooLong.ToString())); } } }