Skip to content

Investigate the use of some level of snapshot testing #12

@bijington

Description

@bijington

Something along the lines should work but we need to find a way to wrap it up nicely for use:

[Test]
public void SceneShouldRenderAsExpected()
{
    var scenery = new Scenery();
    var canvas = new SkiaCanvas();
    var bitmap = new SKBitmap(new SKImageInfo(1000, 1000));
    canvas.Canvas = new SKCanvas(bitmap);

    // Test our Render implementation
    scenery.Render(canvas, new Microsoft.Maui.Graphics.RectF(0, 0, 1000, 1000));

    using var stream = File.Create("snapshot.png");
    bitmap.Encode(stream, SKEncodedImageFormat.Png, 100);
}

public class Scenery : GameScene
{
    public override void Render(Canvas canvas, RectF dimensions)
    {
        base.Render(canvas, dimensions);

        canvas.FillColor = Colors.PaleGoldenrod;
        canvas.FillRectangle(new Rect(0, 0, 100, 100));
    }
}

This currently just involves a GameScene implementation that simply draws a rectangle on screen.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions