SpriteSaveAndLoadTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.Rendering2D.Tests SpriteSaveAndLoadTests

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

public class SpriteSaveAndLoadTests : TestWithMocksOrVisually

The SpriteSaveAndLoadTests type exposes the following members.

Constructors

  NameDescription
Public methodSpriteSaveAndLoadTests
Initializes a new instance of the SpriteSaveAndLoadTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCreateSpriteFromComponents
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSaveAndLoadSprite
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void CreateSpriteFromComponents()
{
    var components = new List<object>();
    components.Add(Rectangle.One);
    components.Add(true);
    var material = new Material(ShaderFlags.Position2DTextured, "DeltaEngineLogo");
    components.Add(material);
    components.Add(material.DiffuseMap.BlendMode);
    components.Add(new RenderingData());
    var sprite = Activator.CreateInstance(typeof(Sprite),
        BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, Type.DefaultBinder,
        null, CultureInfo.CurrentCulture) as Sprite;
    sprite.SetComponents(components);
    Assert.AreEqual(material, sprite.Material);
    Assert.AreEqual(Rectangle.One, sprite.DrawArea);
    Assert.AreEqual(material.DiffuseMap.BlendMode, sprite.BlendMode);
}
[Test, CloseAfterFirstFrame]
public void SaveAndLoadSprite()
{
    var sprite = new Sprite("DeltaEngineLogo", Rectangle.One);
    var data = BinaryDataExtensions.SaveToMemoryStream(sprite);
    Assert.Greater(data.Length, 0);
    var loadedSprite = data.CreateFromMemoryStream() as Sprite;
    Assert.AreEqual(sprite.Material.Shader, loadedSprite.Material.Shader);
    Assert.AreEqual(sprite.Material.DiffuseMap, loadedSprite.Material.DiffuseMap);
    Assert.AreEqual(sprite.DrawArea, loadedSprite.DrawArea);
    Assert.AreEqual(sprite.BlendMode, loadedSprite.BlendMode);
    Assert.AreEqual(sprite.Rotation, loadedSprite.Rotation);
    Assert.AreEqual(1, loadedSprite.GetActiveBehaviors().Count);
    Assert.AreEqual(1, loadedSprite.GetDrawBehaviors().Count);
    Assert.AreEqual("SpriteRenderer",
        loadedSprite.GetDrawBehaviors()[0].GetShortNameOrFullNameIfNotFound());
}
See Also