-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: unit tests for conour legend
- Loading branch information
1 parent
b942f3f
commit 7166b44
Showing
1 changed file
with
30 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,45 @@ | ||
using GsaGH.Helpers; | ||
using System.Drawing; | ||
|
||
using GsaGH.Helpers; | ||
using GsaGH.Helpers.GH; | ||
|
||
using Moq; | ||
|
||
using Xunit; | ||
|
||
namespace GsaGHTests.Helpers { | ||
[Collection("GrasshopperFixture collection")] | ||
public class ContourLegendTests { | ||
private readonly Mock<IContourLegendConfiguration> _mockConfiguration; | ||
private readonly ContourLegend legend; | ||
private readonly Bitmap _mockBitmap; | ||
|
||
public ContourLegendTests() { | ||
_mockBitmap = new Bitmap(10, 10); | ||
_mockConfiguration = new Mock<IContourLegendConfiguration>(); | ||
_mockConfiguration.Setup(c => c.Bitmap).Returns(_mockBitmap); | ||
_mockConfiguration.Setup(c => c.Scale).Returns(1.0); | ||
legend = new ContourLegend(_mockConfiguration.Object); | ||
} | ||
|
||
[Fact] | ||
public void Constructor_InitializesConfiguration() { | ||
// Arrange | ||
var mockConfiguration = new Mock<IContourLegendConfiguration>(); | ||
Assert.NotNull(legend); | ||
} | ||
|
||
// Act | ||
var legend = new ContourLegend(mockConfiguration.Object); | ||
[Fact] | ||
public void DrawGradientLegend_UpdatesBitmapCorrectly() { | ||
var color = Color.FromArgb(0, 255, 255, 0); | ||
legend.DrawGradientLegend(2, 5, color); | ||
|
||
// Assert | ||
Assert.NotNull(legend); | ||
for (int y = 2; y < 5; y++) { | ||
for (int x = 0; x < _mockBitmap.Width; x++) { | ||
Assert.Equal(color, _mockBitmap.GetPixel(x, _mockBitmap.Height - y - 1)); | ||
} | ||
} | ||
} | ||
//other methods need to be tested manually or by integration tests. | ||
//we are not able to mock or inherit DisplayPipeline(which is needed to draw stuff) | ||
//so we aren't able to check if drawings are correct | ||
} | ||
} |