| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451 |
- using QuestPDF.Fluent;
- using QuestPDF.Helpers;
- using QuestPDF.Infrastructure;
- namespace QuestPDF.VisualTests;
- public class StyledBoxTests
- {
- #region Background
- private static readonly IEnumerable<Color> BackgroundColorValues = [ Colors.Red.Medium, Colors.Green.Medium, Colors.Blue.Medium ];
-
- [Test, TestCaseSource(nameof(BackgroundColorValues))]
- public void BackgroundColor(Color color)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Background(color);
- });
- }
- private static readonly IEnumerable<Color[]> BackgroundGradientColorsValues =
- [
- [Colors.Red.Medium, Colors.Green.Darken2],
- [Colors.Red.Medium, Colors.Yellow.Medium, Colors.Green.Medium],
- [Colors.Blue.Medium, Colors.LightBlue.Medium, Colors.Cyan.Medium, Colors.Teal.Medium, Colors.Green.Medium]
- ];
-
- [Test, TestCaseSource(nameof(BackgroundGradientColorsValues))]
- public void BackgroundGradientColors(Color[] gradientColors)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .BackgroundLinearGradient(0, gradientColors);
- });
- }
-
- [Test]
- public void BackgroundGradientAngle(
- [Values(0, 30, 45, 60, 90)] float angle)
- {
- var gradient = new[]
- {
- Colors.Black,
- Colors.White
- };
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .BackgroundLinearGradient(angle, gradient);
- });
- }
-
- [Test]
- public void BackgroundUniformRoundedCorners(
- [Values(0, 5, 10, 25, 50, 100)] float radius)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Background(Colors.Grey.Medium)
- .CornerRadius(radius);
- });
- }
-
- [TestCase(0, 10, 20, 40)]
- [TestCase(10, 20, 40, 0)]
- [TestCase(20, 40, 0, 10)]
- [TestCase(40, 0, 10, 20)]
- public void BackgroundRoundedCorners(float topLeft, float topRight, float bottomRight, float bottomLeft)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Background(Colors.Grey.Medium)
- .CornerRadiusTopLeft(topLeft)
- .CornerRadiusTopRight(topRight)
- .CornerRadiusBottomRight(bottomRight)
- .CornerRadiusBottomLeft(bottomLeft);
- });
- }
-
- #endregion
-
- #region Border
-
- [Test]
- public void BorderThicknessUniform(
- [Values(1, 2, 4, 8)] float thickness)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(100)
- .Border(thickness)
- .BorderColor(Colors.Black)
- .Background(Colors.Grey.Lighten2);
- });
- }
-
- [Test]
- public void BorderThickness(
- [Values(0, 2)] float left,
- [Values(0, 4)] float top,
- [Values(0, 6)] float right,
- [Values(0, 8)] float bottom)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(100)
- .BorderLeft(left)
- .BorderTop(top)
- .BorderRight(right)
- .BorderBottom(bottom)
- .BorderColor(Colors.Black)
- .Background(Colors.Grey.Lighten2);
- });
- }
-
- [Test]
- public void BorderRoundedCornersUniform(
- [Values(0, 5, 10, 25, 50, 100)] float radius)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Border(2)
- .CornerRadius(radius)
- .BorderColor(Colors.Black)
- .Background(Colors.Grey.Lighten2);
- });
- }
-
- [Test]
- public void BorderRoundedCornersWithVariousCornerRadius(
- [Values(0, 5)] float left,
- [Values(0, 5)] float top,
- [Values(0, 5)] float right,
- [Values(0, 5)] float bottom,
- [Values(5, 15)] float roundedRadius)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(50)
- .BorderLeft(left)
- .BorderTop(top)
- .BorderRight(right)
- .BorderBottom(bottom)
- .CornerRadius(roundedRadius)
- .Background(Colors.Blue.Lighten3);
- });
- }
-
- public static readonly IEnumerable<Color> BorderColorCases = [ Colors.Red.Medium, Colors.Green.Medium, Colors.Blue.Medium ];
-
- [Test, TestCaseSource(nameof(BorderColorCases))]
- public void BorderColor(Color color)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Border(5)
- .BorderColor(color)
- .Background(Colors.Grey.Lighten2);
- });
- }
- private static readonly IEnumerable<Color[]> BorderGradientColorsValues =
- [
- [Colors.Red.Medium, Colors.Green.Darken2],
- [Colors.Red.Medium, Colors.Yellow.Medium, Colors.Green.Medium],
- [Colors.Blue.Medium, Colors.LightBlue.Medium, Colors.Cyan.Medium, Colors.Teal.Medium, Colors.Green.Medium]
- ];
-
- [Test, TestCaseSource(nameof(BorderGradientColorsValues))]
- public void BorderGradientColors(Color[] gradientColors)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Border(10)
- .CornerRadius(5)
- .BorderLinearGradient(0, gradientColors)
- .Background(Colors.Grey.Lighten2);
- });
- }
-
- [Test]
- public void BorderGradientAngle(
- [Values(0, 30, 45, 60, 90)] float angle)
- {
- var gradient = new[]
- {
- Colors.Black,
- Colors.White
- };
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Border(10)
- .CornerRadius(5)
- .BorderLinearGradient(angle, gradient);
- });
- }
-
- private void BorderAlignmentTest(Func<IContainer, IContainer> configuration)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Border(10)
- .CornerRadius(10)
- .BorderColor(Colors.Black.WithAlpha(0.5f))
- .Apply(configuration)
- .Background(Colors.Blue.Lighten3);
- });
- }
-
- [Test]
- public void BorderAlignmentInside()
- {
- BorderAlignmentTest(x => x.BorderAlignmentInside());
- }
-
- [Test]
- public void BorderAlignmentMiddle()
- {
- BorderAlignmentTest(x => x.BorderAlignmentMiddle());
- }
-
- [Test]
- public void BorderAlignmentOutside()
- {
- BorderAlignmentTest(x => x.BorderAlignmentOutside());
- }
-
- #endregion
-
- #region Shadow
-
- private static readonly IEnumerable<Color> ShadowColorValues = [ Colors.Red.Medium, Colors.Green.Medium, Colors.Blue.Medium ];
-
- [Test, TestCaseSource(nameof(ShadowColorValues))]
- public void ShadowColor(Color shadowColor)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .Height(100)
- .Background(Colors.White)
- .Shadow(new BoxShadowStyle
- {
- Color = shadowColor,
- Blur = 8
- });
- });
- }
-
- [Test]
- public void ShadowBlur(
- [Values(2, 4, 8, 16)] float blur)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(50)
- .Background(Colors.White)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- Blur = blur,
- });
- });
- }
-
- [Test]
- public void ShadowWithoutBlur(
- [Values] bool applyRoundedCorners,
- [Values] bool applySpread,
- [Values] bool applyOffset)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(50)
- .CornerRadius(applyRoundedCorners ? 20f : 0f)
- .Background(Colors.LightBlue.Medium)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- OffsetX = applyOffset ? 4f : 0f,
- OffsetY = applyOffset ? 4f : 0f,
- Spread = applySpread ? 8f : 0f,
- });
- });
- }
-
- [Test]
- public void ShadowSpread(
- [Values(-4, 0, 4, 8, 12)] float spread)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(100)
- .Background(Colors.White)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- Blur = 4,
- Spread = spread
- });
- });
- }
-
- [Test]
- public void ShadowOffsetX(
- [Values(-8, -4, 0, 4, 8)] float offsetX)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(100)
- .Background(Colors.White)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- Blur = 8,
- OffsetX = offsetX
- });
- });
- }
-
- [Test]
- public void ShadowOffsetY(
- [Values(-8, -4, 0, 4, 8)] float offsetY)
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(100)
- .Height(100)
- .Background(Colors.White)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- Blur = 8,
- OffsetY = offsetY
- });
- });
- }
-
- #endregion
-
- #region Clipping
-
- [Test]
- public void ClipImage()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(200)
- .CornerRadius(25)
- .Shadow(new BoxShadowStyle
- {
- Color = Colors.Grey.Darken2,
- Blur = 8
- })
- .Image("Resources/gradient.png");
- });
- }
-
- [Test]
- public void ClipText()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(300)
- .Border(2, Colors.Black)
- .CornerRadius(75)
- .Text(Placeholders.LoremIpsum());
- });
- }
-
- [Test]
- public void ClipContent()
- {
- VisualTest.PerformWithDefaultPageSettings(container =>
- {
- container
- .Width(400)
- .Border(2, Colors.Black)
- .CornerRadius(150)
- .Table(table =>
- {
- table.ColumnsDefinition(columns =>
- {
- foreach (var i in Enumerable.Range(1, 10))
- columns.RelativeColumn();
- });
- foreach (var i in Enumerable.Range(0, 100))
- {
- table.Cell()
- .Border(1)
- .Padding(5)
- .AlignCenter()
- .Text(i.ToString());
- }
- });
- });
- }
-
- #endregion
- }
|