ImageTests ClassDelta Engine Documentation
The image tests here are limited to loading and integration tests, not visual tests, which you can find in DeltaEngine.Rendering2D.Tests.SpriteTests. View code on GitHub
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Graphics.Tests ImageTests

Namespace: DeltaEngine.Graphics.Tests
Assembly: DeltaEngine.Graphics.Tests (in DeltaEngine.Graphics.Tests.dll) Version: 1.1.1.0 (1.1.1)
Syntax

public class ImageTests : TestWithMocksOrVisually

The ImageTests type exposes the following members.

Constructors

  NameDescription
Public methodImageTests
Initializes a new instance of the ImageTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodBlendModes
Public methodCreatingTwoImagesWithTheSameDataAlwaysResultsInDifferentImages
Public methodDrawCustomImageFromBytes
Public methodDrawCustomImageFromColorClickToChangeIt
Public methodDrawCustomImageHalfRedHalfGold
From http://forum.deltaengine.net/yaf_postsm6203_Dynamic-textures---v--0-9-8-2.aspx#post6203 View code on GitHub
Public methodDrawCustomImageHalfTransparent
Public methodDrawDefaultTexture
Public methodDrawOpaqueImageWithVertexColors
Public methodFillCustomImageWitDifferentSizeThanImageCausesException
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodLoadExistingImage
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodShouldThrowIfImageNotLoadedWithDebuggerAttached
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, ApproveFirstFrameScreenshot]
public void DrawOpaqueImageWithVertexColors()
{
    Resolve<Window>().BackgroundColor = Color.CornflowerBlue;
    new ColoredSprite(ContentLoader.Load<Image>("DeltaEngineLogoOpaque"));
    RunAfterFirstFrame(
        () => Assert.AreEqual(4, Resolve<Drawing>().NumberOfDynamicVerticesDrawnThisFrame));
}
[Test, CloseAfterFirstFrame]
public void LoadExistingImage()
{
    var image = ContentLoader.Load<Image>("DeltaEngineLogoOpaque");
    Assert.AreEqual("DeltaEngineLogoOpaque", image.Name);
    Assert.IsFalse(image.IsDisposed);
    Assert.AreEqual(new Size(128, 128), image.PixelSize);
}
[Test, CloseAfterFirstFrame]
public void ShouldThrowIfImageNotLoadedWithDebuggerAttached()
{
    //ncrunch: no coverage start 
    if (Debugger.IsAttached)
        Assert.Throws<ContentLoader.ContentNotFound>(
            () => ContentLoader.Load<Image>("UnavailableImage"));
    //ncrunch: no coverage end
}
[Test, ApproveFirstFrameScreenshot]
public void DrawDefaultTexture()
{
    Resolve<Window>().BackgroundColor = Color.CornflowerBlue;
    new ColoredSprite(ContentLoader.Load<Image>("UnavailableImage"));
    RunAfterFirstFrame(
        () => Assert.AreEqual(4, Resolve<Drawing>().NumberOfDynamicVerticesDrawnThisFrame));
}
[Test, ApproveFirstFrameScreenshot]
public void DrawCustomImageFromColorClickToChangeIt()
{
    var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 8)));
    customImage.Fill(Color.Purple);
    new SolidSprite(customImage);
    new Command(Command.Click, () => customImage.Fill(Color.GetRandomColor()));
}
[Test, ApproveFirstFrameScreenshot]
public void DrawCustomImageFromBytes()
{
    var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 8)));
    var bytes = new byte[8 * 8 * 4];
    var color = Color.Purple;
    for (int i = 0; i < 8 * 8; i++)
    {
        bytes[i * 4] = color.R;
        bytes[i * 4 + 1] = color.G;
        bytes[i * 4 + 2] = color.B;
    }
    customImage.FillRgbaData(bytes);
    new SolidSprite(customImage);
}
/// <summary> 
/// From http://forum.deltaengine.net/yaf_postsm6203_Dynamic-textures---v--0-9-8-2.aspx#post6203 
/// </summary>
[Test, ApproveFirstFrameScreenshot]
public void DrawCustomImageHalfRedHalfGold()
{
    var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(64, 64)));
    var colors = new Color[64 * 64];
    for (int i = 0; i < colors.Length; i++)
        colors[i] = i < colors.Length / 2 ? Color.Red : Color.Gold;
    customImage.Fill(colors);
    new SolidSprite(customImage);
}
[Test, ApproveFirstFrameScreenshot]
public void DrawCustomImageHalfTransparent()
{
    Resolve<Window>().BackgroundColor = Color.Yellow;
    var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(64, 64)));
    customImage.Fill(new Color(0, 0, 0, 0.5f));
    customImage.BlendMode = BlendMode.Normal;
    new SolidSprite(customImage);
}
[Test, CloseAfterFirstFrame]
public void FillCustomImageWitDifferentSizeThanImageCausesException()
{
    var customImage = ContentLoader.Create<Image>(new ImageCreationData(new Size(8, 9)));
    var colors = new Color[8 * 8];            
    Assert.Throws<Image.InvalidNumberOfColors>(() => customImage.Fill(colors));
    var byteArray = new byte[8 * 8];
    Assert.Throws<Image.InvalidNumberOfBytes>(() => customImage.FillRgbaData(byteArray));
    var goodByteArray = new byte[8 * 9 * 4];
    customImage.FillRgbaData(goodByteArray);
}
[Test, CloseAfterFirstFrame]
public void CreatingTwoImagesWithTheSameDataAlwaysResultsInDifferentImages()
{
    var data1 = new ImageCreationData(new Size(4, 4));
    var data2 = new ImageCreationData(new Size(4, 4));
    Assert.AreNotEqual(data1, data2);
    var image1 = ContentLoader.Create<Image>(data1);
    var image2 = ContentLoader.Create<Image>(data2);
    Assert.AreEqual(image1.PixelSize, image2.PixelSize);
    Assert.AreEqual(image1.BlendMode, image2.BlendMode);
    Assert.AreNotEqual(image1, image2);
}
[Test, ApproveFirstFrameScreenshot]
public void BlendModes()
{
    new DrawableEntity().OnDraw<RenderBlendModes>();
}
See Also