Skip to content

Commit

Permalink
Replaced FluentAssertions with Shouldly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvo Isaja committed Jan 18, 2025
1 parent 11e1ca8 commit f6b5c3a
Show file tree
Hide file tree
Showing 15 changed files with 309 additions and 319 deletions.
2 changes: 1 addition & 1 deletion Examples/Large.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static void Run()

private static void DoRun(bool requireCellReferences)
{
using var stream = new FileStream($"{nameof(Large)}.xlsx", FileMode.Create, FileAccess.Write);
using var stream = new FileStream($"{nameof(Large)}_{requireCellReferences}.xlsx", FileMode.Create, FileAccess.Write);
using var xlsxWriter = new XlsxWriter(stream, compressionLevel: CompressionLevel.Level3, requireCellReferences: requireCellReferences);
var whiteFont = new XlsxFont("Calibri", 11, Color.White, bold: true);
var blueFill = new XlsxFill(Color.FromArgb(0, 0x45, 0x86));
Expand Down
2 changes: 1 addition & 1 deletion Examples/StyledLarge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static void Run()
private static void DoRun(bool requireCellReferences)
{
var rnd = new Random();
using var stream = new FileStream($"{nameof(StyledLarge)}.xlsx", FileMode.Create, FileAccess.Write);
using var stream = new FileStream($"{nameof(StyledLarge)}_{requireCellReferences}.xlsx", FileMode.Create, FileAccess.Write);
using var xlsxWriter = new XlsxWriter(stream, compressionLevel: CompressionLevel.Level3, requireCellReferences: requireCellReferences);
var headerStyle = new XlsxStyle(
new XlsxFont("Calibri", 11, Color.White, bold: true),
Expand Down
15 changes: 10 additions & 5 deletions Examples/StyledLargeCreateStyles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,21 @@ public static class StyledLargeCreateStyles
public static void Run()
{
var stopwatch = Stopwatch.StartNew();
DoRun();
DoRun(requireCellReferences: true);
stopwatch.Stop();
Console.WriteLine($"{nameof(StyledLargeCreateStyles)} completed {RowCount} rows, {ColumnCount} columns and {ColorCount} colors in {stopwatch.ElapsedMilliseconds} ms.");
Console.WriteLine($"{nameof(StyledLargeCreateStyles)} requiring references completed {RowCount} rows, {ColumnCount} columns and {ColorCount} colors in {stopwatch.ElapsedMilliseconds} ms.");

stopwatch.Restart();
DoRun(requireCellReferences: false);
stopwatch.Stop();
Console.WriteLine($"{nameof(StyledLargeCreateStyles)} omitting references completed {RowCount} rows, {ColumnCount} columns and {ColorCount} colors in {stopwatch.ElapsedMilliseconds} ms.");
}

private static void DoRun()
private static void DoRun(bool requireCellReferences)
{
var rnd = new Random();
using var stream = new FileStream($"{nameof(StyledLargeCreateStyles)}.xlsx", FileMode.Create, FileAccess.Write);
using var xlsxWriter = new XlsxWriter(stream);
using var stream = new FileStream($"{nameof(StyledLargeCreateStyles)}_{requireCellReferences}.xlsx", FileMode.Create, FileAccess.Write);
using var xlsxWriter = new XlsxWriter(stream, requireCellReferences: requireCellReferences);
var colors = Enumerable.Repeat(0, 100).Select(_ => Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256))).ToList();
var headerStyle = new XlsxStyle(
new XlsxFont("Calibri", 10.5, Color.White, bold: true),
Expand Down
30 changes: 15 additions & 15 deletions LargeXlsx.Tests/AlignmentTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
using System.IO;
using FluentAssertions;
using NUnit.Framework;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Shouldly;

namespace LargeXlsx.Tests;

Expand All @@ -50,7 +50,7 @@ public static void HorizontalAlignment(XlsxAlignment.Horizontal alignment, Excel
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(horizontal: alignment)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.HorizontalAlignment.Should().Be(expected);
package.Workbook.Worksheets[0].Cells["A1"].Style.HorizontalAlignment.ShouldBe(expected);
}

[TestCase(XlsxAlignment.Vertical.Top, ExcelVerticalAlignment.Top)]
Expand All @@ -65,7 +65,7 @@ public static void VerticalAlignment(XlsxAlignment.Vertical alignment, ExcelVert
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(vertical: alignment)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.VerticalAlignment.Should().Be(expected);
package.Workbook.Worksheets[0].Cells["A1"].Style.VerticalAlignment.ShouldBe(expected);
}

[Test]
Expand All @@ -76,7 +76,7 @@ public static void TextRotation()
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(textRotation: 45)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.TextRotation.Should().Be(45);
package.Workbook.Worksheets[0].Cells["A1"].Style.TextRotation.ShouldBe(45);
}

[Test]
Expand All @@ -87,7 +87,7 @@ public static void Indent()
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(indent: 2)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.Indent.Should().Be(2);
package.Workbook.Worksheets[0].Cells["A1"].Style.Indent.ShouldBe(2);
}

[Test]
Expand All @@ -98,7 +98,7 @@ public static void WrapText()
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(wrapText: true)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.WrapText.Should().Be(true);
package.Workbook.Worksheets[0].Cells["A1"].Style.WrapText.ShouldBe(true);
}

[Test]
Expand All @@ -109,7 +109,7 @@ public static void ShrinkToFit()
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(shrinkToFit: true)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.ShrinkToFit.Should().Be(true);
package.Workbook.Worksheets[0].Cells["A1"].Style.ShrinkToFit.ShouldBe(true);
}

[TestCase(XlsxAlignment.ReadingOrder.ContextDependent, ExcelReadingOrder.ContextDependent)]
Expand All @@ -122,7 +122,7 @@ public static void ReadingOrder(XlsxAlignment.ReadingOrder readingOrder, ExcelRe
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow()
.Write("Test", XlsxStyle.Default.With(new XlsxAlignment(readingOrder: readingOrder)));
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Cells["A1"].Style.ReadingOrder.Should().Be(expected);
package.Workbook.Worksheets[0].Cells["A1"].Style.ReadingOrder.ShouldBe(expected);
}

[Test]
Expand All @@ -134,13 +134,13 @@ public static void Defaults()
using (var package = new ExcelPackage(stream))
{
var style = package.Workbook.Worksheets[0].Cells["A1"].Style;
style.HorizontalAlignment.Should().Be(ExcelHorizontalAlignment.General);
style.VerticalAlignment.Should().Be(ExcelVerticalAlignment.Bottom);
style.ShrinkToFit.Should().BeFalse();
style.WrapText.Should().BeFalse();
style.TextRotation.Should().Be(0);
style.Indent.Should().Be(0);
style.ReadingOrder.Should().Be(ExcelReadingOrder.ContextDependent);
style.HorizontalAlignment.ShouldBe(ExcelHorizontalAlignment.General);
style.VerticalAlignment.ShouldBe(ExcelVerticalAlignment.Bottom);
style.ShrinkToFit.ShouldBeFalse();
style.WrapText.ShouldBeFalse();
style.TextRotation.ShouldBe(0);
style.Indent.ShouldBe(0);
style.ReadingOrder.ShouldBe(ExcelReadingOrder.ContextDependent);
}
}
}
30 changes: 15 additions & 15 deletions LargeXlsx.Tests/BorderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
*/
using System.Drawing;
using System.IO;
using FluentAssertions;
using NUnit.Framework;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Shouldly;

namespace LargeXlsx.Tests;

Expand Down Expand Up @@ -57,8 +57,8 @@ public static void HorizontalAlignment(XlsxBorder.Style borderStyle, ExcelBorder
.Write("Test", XlsxStyle.Default.With(new XlsxBorder(top: new XlsxBorder.Line(Color.DeepPink, borderStyle))));
using var package = new ExcelPackage(stream);
var border = package.Workbook.Worksheets[0].Cells["A1"].Style.Border;
border.Top.Color.Rgb.Should().Be("FFFF1493");
border.Top.Style.Should().Be(expected);
border.Top.Color.Rgb.ShouldBe("FFFF1493");
border.Top.Style.ShouldBe(expected);
}


Expand All @@ -70,17 +70,17 @@ public static void Defaults()
xlsxWriter.BeginWorksheet("Sheet 1").BeginRow().Write("Test");
using var package = new ExcelPackage(stream);
var style = package.Workbook.Worksheets[0].Cells["A1"].Style;
style.Border.Top.Color.Rgb.Should().BeNull();
style.Border.Top.Style.Should().Be(ExcelBorderStyle.None);
style.Border.Right.Color.Rgb.Should().BeNull();
style.Border.Right.Style.Should().Be(ExcelBorderStyle.None);
style.Border.Bottom.Color.Rgb.Should().BeNull();
style.Border.Bottom.Style.Should().Be(ExcelBorderStyle.None);
style.Border.Left.Color.Rgb.Should().BeNull();
style.Border.Left.Style.Should().Be(ExcelBorderStyle.None);
style.Border.Diagonal.Color.Rgb.Should().BeNull();
style.Border.Diagonal.Style.Should().Be(ExcelBorderStyle.None);
style.Border.DiagonalDown.Should().BeFalse();
style.Border.DiagonalUp.Should().BeFalse();
style.Border.Top.Color.Rgb.ShouldBeNull();
style.Border.Top.Style.ShouldBe(ExcelBorderStyle.None);
style.Border.Right.Color.Rgb.ShouldBeNull();
style.Border.Right.Style.ShouldBe(ExcelBorderStyle.None);
style.Border.Bottom.Color.Rgb.ShouldBeNull();
style.Border.Bottom.Style.ShouldBe(ExcelBorderStyle.None);
style.Border.Left.Color.Rgb.ShouldBeNull();
style.Border.Left.Style.ShouldBe(ExcelBorderStyle.None);
style.Border.Diagonal.Color.Rgb.ShouldBeNull();
style.Border.Diagonal.Style.ShouldBe(ExcelBorderStyle.None);
style.Border.DiagonalDown.ShouldBeFalse();
style.Border.DiagonalUp.ShouldBeFalse();
}
}
28 changes: 14 additions & 14 deletions LargeXlsx.Tests/ColumnFormattingTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
using System.Linq;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using FluentAssertions;
using NUnit.Framework;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using Shouldly;
using Color = System.Drawing.Color;

namespace LargeXlsx.Tests;
Expand All @@ -46,7 +46,7 @@ public static void Width()
using (var xlsxWriter = new XlsxWriter(stream))
xlsxWriter.BeginWorksheet("Sheet 1", columns: new[] { XlsxColumn.Formatted(width: 20) });
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Column(1).Width.Should().Be(20);
package.Workbook.Worksheets[0].Column(1).Width.ShouldBe(20);
}

[Test]
Expand All @@ -58,9 +58,9 @@ public static void Style()
xlsxWriter.BeginWorksheet("Sheet 1", columns: new[] { XlsxColumn.Formatted(width: 20, style: blueStyle) });
using var package = new ExcelPackage(stream);
var style = package.Workbook.Worksheets[0].Column(1).Style;
style.Fill.PatternType.Should().Be(ExcelFillStyle.Solid);
style.Fill.BackgroundColor.Rgb.Should().Be("FF004586");
style.Font.Color.Rgb.Should().Be("FFFFFFFF");
style.Fill.PatternType.ShouldBe(ExcelFillStyle.Solid);
style.Fill.BackgroundColor.Rgb.ShouldBe("FF004586");
style.Font.Color.Rgb.ShouldBe("FFFFFFFF");
}

[Test]
Expand All @@ -70,7 +70,7 @@ public static void Hidden()
using (var xlsxWriter = new XlsxWriter(stream))
xlsxWriter.BeginWorksheet("Sheet 1", columns: new[] { XlsxColumn.Formatted(width: 0, hidden: true) });
using (var package = new ExcelPackage(stream))
package.Workbook.Worksheets[0].Column(1).Hidden.Should().BeTrue();
package.Workbook.Worksheets[0].Column(1).Hidden.ShouldBeTrue();
}

[Test]
Expand All @@ -86,13 +86,13 @@ public static void SkipUnformatted()
});
using var package = new ExcelPackage(stream);
var worksheet = package.Workbook.Worksheets[0];
worksheet.Column(1).Hidden.Should().BeTrue();
worksheet.Column(2).Hidden.Should().BeTrue();
worksheet.Column(3).Hidden.Should().BeFalse();
worksheet.Column(4).Hidden.Should().BeFalse();
worksheet.Column(5).Hidden.Should().BeFalse();
worksheet.Column(6).Hidden.Should().BeTrue();
worksheet.Column(7).Hidden.Should().BeFalse();
worksheet.Column(1).Hidden.ShouldBeTrue();
worksheet.Column(2).Hidden.ShouldBeTrue();
worksheet.Column(3).Hidden.ShouldBeFalse();
worksheet.Column(4).Hidden.ShouldBeFalse();
worksheet.Column(5).Hidden.ShouldBeFalse();
worksheet.Column(6).Hidden.ShouldBeTrue();
worksheet.Column(7).Hidden.ShouldBeFalse();
}

[Test]
Expand All @@ -105,6 +105,6 @@ public static void OnlyUnformatted()
using var spreadsheetDocument = SpreadsheetDocument.Open(stream, false);
var sheetId = spreadsheetDocument.WorkbookPart!.Workbook.Sheets!.Elements<Sheet>().Single(s => s.Name == "Sheet 1").Id!.ToString()!;
var worksheetPart = (WorksheetPart)spreadsheetDocument.WorkbookPart!.GetPartById(sheetId);
worksheetPart.Worksheet.Descendants<Columns>().Should().BeEmpty();
worksheetPart.Worksheet.Descendants<Columns>().ShouldBeEmpty();
}
}
Loading

0 comments on commit f6b5c3a

Please sign in to comment.