Skip to content

Commit a32aef4

Browse files
committed
FillLinearGradientBrushTests SixLabors#1
1 parent f351614 commit a32aef4

File tree

1 file changed

+69
-65
lines changed

1 file changed

+69
-65
lines changed

tests/ImageSharp.Tests/Drawing/FillLinearGradientBrushTests.cs

Lines changed: 69 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -20,50 +20,48 @@ public class FillLinearGradientBrushTests
2020
{
2121
[Theory]
2222
[WithBlankImages(10, 10, PixelTypes.Rgba32)]
23-
public void WithEqualColorsReturnsUnicolorImage<TPixel>(
24-
TestImageProvider<TPixel> provider)
23+
public void WithEqualColorsReturnsUnicolorImage<TPixel>(TestImageProvider<TPixel> provider)
2524
where TPixel : struct, IPixel<TPixel>
2625
{
27-
TPixel red = NamedColors<TPixel>.Red;
28-
using (var image = provider.GetImage())
29-
{
30-
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
31-
new LinearGradientBrush<TPixel>(
32-
new SixLabors.Primitives.Point(0, 0),
33-
new SixLabors.Primitives.Point(10, 0),
34-
GradientRepetitionMode.None,
35-
new ColorStop<TPixel>(0, red),
36-
new ColorStop<TPixel>(1, red));
37-
38-
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
39-
image.DebugSave(provider);
40-
image.CompareToReferenceOutput(provider);
41-
}
26+
provider.VerifyOperation(
27+
image =>
28+
{
29+
TPixel red = NamedColors<TPixel>.Red;
30+
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
31+
new SixLabors.Primitives.Point(0, 0),
32+
new SixLabors.Primitives.Point(10, 0),
33+
GradientRepetitionMode.None,
34+
new ColorStop<TPixel>(0, red),
35+
new ColorStop<TPixel>(1, red));
36+
37+
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
38+
},
39+
false,
40+
false);
4241
}
4342

4443
[Theory]
4544
[WithBlankImages(500, 10, PixelTypes.Rgba32)]
46-
public void HorizontalReturnsUnicolorColumns<TPixel>(
47-
TestImageProvider<TPixel> provider)
45+
public void HorizontalReturnsUnicolorColumns<TPixel>(TestImageProvider<TPixel> provider)
4846
where TPixel : struct, IPixel<TPixel>
4947
{
50-
using (var image = provider.GetImage())
51-
{
52-
TPixel red = NamedColors<TPixel>.Red;
53-
TPixel yellow = NamedColors<TPixel>.Yellow;
54-
55-
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
56-
new LinearGradientBrush<TPixel>(
57-
new SixLabors.Primitives.Point(0, 0),
58-
new SixLabors.Primitives.Point(image.Width, 0),
59-
GradientRepetitionMode.None,
60-
new ColorStop<TPixel>(0, red),
61-
new ColorStop<TPixel>(1, yellow));
62-
63-
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
64-
image.DebugSave(provider);
65-
image.CompareToReferenceOutput(provider);
66-
}
48+
provider.VerifyOperation(
49+
image =>
50+
{
51+
TPixel red = NamedColors<TPixel>.Red;
52+
TPixel yellow = NamedColors<TPixel>.Yellow;
53+
54+
LinearGradientBrush<TPixel> unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
55+
new SixLabors.Primitives.Point(0, 0),
56+
new SixLabors.Primitives.Point(image.Width, 0),
57+
GradientRepetitionMode.None,
58+
new ColorStop<TPixel>(0, red),
59+
new ColorStop<TPixel>(1, yellow));
60+
61+
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
62+
},
63+
false,
64+
false);
6765
}
6866

6967
[Theory]
@@ -76,23 +74,23 @@ public void HorizontalGradientWithRepMode<TPixel>(
7674
GradientRepetitionMode repetitionMode)
7775
where TPixel : struct, IPixel<TPixel>
7876
{
79-
using (var image = provider.GetImage())
80-
{
81-
TPixel red = NamedColors<TPixel>.Red;
82-
TPixel yellow = NamedColors<TPixel>.Yellow;
83-
84-
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
85-
new LinearGradientBrush<TPixel>(
86-
new SixLabors.Primitives.Point(0, 0),
87-
new SixLabors.Primitives.Point(image.Width / 10, 0),
88-
repetitionMode,
89-
new ColorStop<TPixel>(0, red),
90-
new ColorStop<TPixel>(1, yellow));
91-
92-
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
93-
image.DebugSave(provider, repetitionMode);
94-
image.CompareToReferenceOutput(provider, repetitionMode);
95-
}
77+
provider.VerifyOperation(
78+
image =>
79+
{
80+
TPixel red = NamedColors<TPixel>.Red;
81+
TPixel yellow = NamedColors<TPixel>.Yellow;
82+
83+
var unicolorLinearGradientBrush = new LinearGradientBrush<TPixel>(
84+
new SixLabors.Primitives.Point(0, 0),
85+
new SixLabors.Primitives.Point(image.Width / 10, 0),
86+
repetitionMode,
87+
new ColorStop<TPixel>(0, red),
88+
new ColorStop<TPixel>(1, yellow));
89+
90+
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
91+
},
92+
false,
93+
false);
9694
}
9795

9896
[Theory]
@@ -104,7 +102,7 @@ public void WithDoubledStopsProduceDashedPatterns<TPixel>(
104102
float[] pattern)
105103
where TPixel : struct, IPixel<TPixel>
106104
{
107-
string variant = string.Join(",", pattern.Select(i => i.ToString(CultureInfo.InvariantCulture)));
105+
string variant = string.Join("_", pattern.Select(i => i.ToString(CultureInfo.InvariantCulture)));
108106

109107
// ensure the input data is valid
110108
Assert.True(pattern.Length > 0);
@@ -127,25 +125,31 @@ public void WithDoubledStopsProduceDashedPatterns<TPixel>(
127125

128126
using (Image<TPixel> image = provider.GetImage())
129127
{
130-
LinearGradientBrush<TPixel> unicolorLinearGradientBrush =
128+
var unicolorLinearGradientBrush =
131129
new LinearGradientBrush<TPixel>(
132130
new SixLabors.Primitives.Point(0, 0),
133131
new SixLabors.Primitives.Point(image.Width, 0),
134132
GradientRepetitionMode.None,
135133
colorStops);
136134

137135
image.Mutate(x => x.Fill(unicolorLinearGradientBrush));
138-
image.DebugSave(provider, variant);
139-
140-
using (PixelAccessor<TPixel> sourcePixels = image.Lock())
141-
{
142-
// the result must be a black and white pattern, no other color should occur:
143-
Assert.All(
144-
Enumerable.Range(0, image.Width).Select(i => sourcePixels[i, 0]),
145-
color => Assert.True(color.Equals(black) || color.Equals(white)));
146-
}
147136

148-
image.CompareToReferenceOutput(provider, variant);
137+
image.DebugSave(
138+
provider,
139+
variant,
140+
appendPixelTypeToFileName: false,
141+
appendSourceFileOrDescription: false);
142+
143+
// the result must be a black and white pattern, no other color should occur:
144+
Assert.All(
145+
Enumerable.Range(0, image.Width).Select(i => image[i, 0]),
146+
color => Assert.True(color.Equals(black) || color.Equals(white)));
147+
148+
image.CompareToReferenceOutput(
149+
provider,
150+
variant,
151+
appendPixelTypeToFileName: false,
152+
appendSourceFileOrDescription: false);
149153
}
150154
}
151155

0 commit comments

Comments
 (0)