LevelTests ClassDelta Engine Documentation
Inheritance Hierarchy

System Object
  DeltaEngine.Platforms TestWithMocksOrVisually
    DeltaEngine.GameLogic.Tests LevelTests

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

public class LevelTests : TestWithMocksOrVisually

The LevelTests type exposes the following members.

Constructors

  NameDescription
Public methodLevelTests
Initializes a new instance of the LevelTests class
Top
Methods

  NameDescription
Protected methodAdvanceTimeAndUpdateEntities (Inherited from TestWithMocksOrVisually.)
Public methodCanNotCreateTileMapWithoutData
Public methodCanNotCreateTileMapWithoutValidData
Public methodConvertMapCoordinatesToWorldCoordinates
Public methodConvertWorldCoordinatesToMapCoordinates
Public methodFetchMapCoordinatesOfClosestTileCenter
Public methodInitializeResolver (Inherited from TestWithMocksOrVisually.)
Public methodInteractWithOnlyInteractableTiles
Protected methodRegisterMock T  (Inherited from TestWithMocksOrVisually.)
Protected methodResolve T  (Inherited from TestWithMocksOrVisually.)
Protected methodRunAfterFirstFrame (Inherited from TestWithMocksOrVisually.)
Public methodRunTestAndDisposeResolverWhenDone (Inherited from TestWithMocksOrVisually.)
Public methodSaveAndLoadMapData
Public methodStart
Public methodStart2
Public methodTestAddWave
Public methodTestGetAllTilesOfType
Public methodTestIsInsideLevelGrid
Public methodTestLevelTileChange
Public methodTestLevelTileColor
Public methodTestLoadData
Public methodTestSetTileWithScreenPositionIn2D
Public methodTestSetTileWithScreenPositionIn3D
Public methodTestToTextForXml
Public methodTilesOutsideOfTheGridAreNotInteractable
Top
Properties

  NameDescription
Protected propertyIsMockResolver (Inherited from TestWithMocksOrVisually.)
Top
Examples

[Test, CloseAfterFirstFrame]
public void Start()
{
    TileMap map = CreateSimple2X3TileMap();
    Assert.AreEqual(2, map.Width);
    Assert.AreEqual(3, map.Height);
}
[Test, CloseAfterFirstFrame]
public void SaveAndLoadMapData()
{
    TileMap map = CreateSimple2X3TileMap();
    string mapData = map.Save();
    string newLine = Environment.NewLine;
    string expectedData = "E." + newLine + "X." + newLine + "S." + newLine;
    Assert.AreEqual(expectedData, mapData);
    var loadedMap = new TileMap(mapData);
    Assert.AreEqual(expectedData, loadedMap.Save());
}
[Test, CloseAfterFirstFrame]
public void CanNotCreateTileMapWithoutData()
{
    const string MapData = "";
    Assert.Throws<TileMap.NoTileMapData>(() => new TileMap(MapData));
}
[Test, CloseAfterFirstFrame]
public void CanNotCreateTileMapWithoutValidData()
{
    const string MapData = "   ";
    Assert.Throws<TileMap.NoTileMapData>(() => new TileMap(MapData));
}
[Test, CloseAfterFirstFrame]
public void Start2()
{
    TileMap map = CreateSimple2X3TileMap();
    Assert.Throws<TileMap.StartPointNotFound>(() => map.FindPath(LevelTileType.Red));
    Assert.DoesNotThrow(() => map.FindPath(LevelTileType.SpawnPoint));
}
[Test, CloseAfterFirstFrame]
public void TestLevelTileChange()
{
    var level = new MockLevel(new Size(1));
    level.TileChanged += position => CheckTileHasChanged(level, position);
    level.SetTile(Vector2D.Zero, LevelTileType.Blocked);
}
[Test, CloseAfterFirstFrame]
public void TestLevelTileColor()
{
    var level = new MockLevel(new Size(5));
    Assert.AreEqual(Color.LightGray, level.GetColor(LevelTileType.Blocked));
    Assert.AreEqual(Color.CornflowerBlue, level.GetColor(LevelTileType.Placeable));
    Assert.AreEqual(Color.LightBlue, level.GetColor(LevelTileType.BlockedPlaceable));
    Assert.AreEqual(Color.LightBlue, level.GetColor(LevelTileType.LightBlue));
    Assert.AreEqual(Color.Red, level.GetColor(LevelTileType.Red));
    Assert.AreEqual(Color.Green, level.GetColor(LevelTileType.Green));
    Assert.AreEqual(Color.Blue, level.GetColor(LevelTileType.Blue));
    Assert.AreEqual(Color.Yellow, level.GetColor(LevelTileType.Yellow));
    Assert.AreEqual(Color.Brown, level.GetColor(LevelTileType.Brown));
    Assert.AreEqual(Color.Gray, level.GetColor(LevelTileType.Gray));
    Assert.AreEqual(Color.PaleGreen, level.GetColor(LevelTileType.SpawnPoint));
    Assert.AreEqual(Color.DarkGreen, level.GetColor(LevelTileType.ExitPoint));
    Assert.AreEqual(Color.Black, level.GetColor(LevelTileType.Nothing));
    Assert.AreEqual(Color.TransparentBlack, level.GetColor(LevelTileType.NoSelection));
}
[Test, CloseAfterFirstFrame]
public void TestGetAllTilesOfType()
{
    var level = new MockLevel(new Size(2));
    level.SetTile(new Vector2D(0, 0), LevelTileType.SpawnPoint);
    level.SetTile(new Vector2D(0, 1), LevelTileType.SpawnPoint);
    level.SetTile(new Vector2D(1, 0), LevelTileType.ExitPoint);
    Assert.AreEqual(2, level.GetAllTilesOfType(LevelTileType.SpawnPoint).Count);
}
[Test, CloseAfterFirstFrame]
public void TestIsInsideLevelGrid()
{
    var level = new MockLevel(new Size(3));
    Assert.IsTrue(level.IsInsideLevelGrid(new Vector2D(0, 0)));
    Assert.IsTrue(level.IsInsideLevelGrid(new Vector2D(1, 1)));
    Assert.IsTrue(level.IsInsideLevelGrid(new Vector2D(3, 3)));
    Assert.IsFalse(level.IsInsideLevelGrid(new Vector2D(-0.1f, -0.1f)));
    Assert.IsFalse(level.IsInsideLevelGrid(new Vector2D(3.1f, 3.1f)));
}
[Test, CloseAfterFirstFrame]
public void TestAddWave()
{
    var level = new MockLevel(new Size(3));
    Assert.AreEqual(0, level.Waves.Count);
    level.AddWave(new Wave(0.0f, 0.0f, ""));
    Assert.AreEqual(1, level.Waves.Count);
}
[Test, CloseAfterFirstFrame]
public void TestToTextForXml()
{
    var level = new MockLevel(new Size(3, 4));
    level.SetTile(new Vector2D(0, 0), LevelTileType.Nothing);
    level.SetTile(new Vector2D(1, 0), LevelTileType.Blocked);
    level.SetTile(new Vector2D(2, 0), LevelTileType.Placeable);
    level.SetTile(new Vector2D(0, 1), LevelTileType.BlockedPlaceable);
    level.SetTile(new Vector2D(1, 1), LevelTileType.Red);
    level.SetTile(new Vector2D(2, 1), LevelTileType.Green);
    level.SetTile(new Vector2D(0, 2), LevelTileType.Blue);
    level.SetTile(new Vector2D(1, 2), LevelTileType.Yellow);
    level.SetTile(new Vector2D(2, 2), LevelTileType.Brown);
    level.SetTile(new Vector2D(0, 3), LevelTileType.Gray);
    level.SetTile(new Vector2D(1, 3), LevelTileType.SpawnPoint);
    level.SetTile(new Vector2D(2, 3), LevelTileType.ExitPoint);
    string text = level.ToTextForXml();
    Assert.AreEqual("\r\n.XP\r\nLRG\r\nBYO\r\nASE\r\n", text);
}
[Test, CloseAfterFirstFrame]
public void TestLoadData()
{
    var level = new MockLevel(new Size());
    Assert.AreEqual(new Size(), level.Size);
    level.LoadTestData();
    Assert.AreEqual(new Size(4, 3), level.Size);
}
[Test, CloseAfterFirstFrame]
public void ConvertMapCoordinatesToWorldCoordinates()
{
    var level = new Level(new Size(3, 5));
    level.RenderIn3D = true;
    Assert.AreEqual(new Vector2D(0, 0), level.GetWorldCoordinates(new Vector2D(1, 2)));
    Assert.AreEqual(new Vector2D(-1, 2), level.GetWorldCoordinates(new Vector2D(0, 0)));
    Assert.AreEqual(new Vector2D(1, 2), level.GetWorldCoordinates(new Vector2D(2, 0)));
    Assert.AreEqual(new Vector2D(-1, -2), level.GetWorldCoordinates(new Vector2D(0, 4)));
    Assert.AreEqual(new Vector2D(1, -2), level.GetWorldCoordinates(new Vector2D(2, 4)));
}
[Test, CloseAfterFirstFrame]
public void FetchMapCoordinatesOfClosestTileCenter()
{
    var level = new Level(new Size(3, 3));
    level.RenderIn3D = true;
    Assert.AreEqual(new Vector2D(0, 0), level.GetWorldCoordinates(new Vector2D(1.1f, 1.1f)));
    Assert.AreEqual(new Vector2D(0, 0), level.GetWorldCoordinates(new Vector2D(1.1f, 1.9f)));
    Assert.AreEqual(new Vector2D(0, 0), level.GetWorldCoordinates(new Vector2D(1.9f, 1.9f)));
    Assert.AreEqual(new Vector2D(0, 0), level.GetWorldCoordinates(new Vector2D(1.9f, 1.1f)));
}
[Test, CloseAfterFirstFrame]
public void ConvertWorldCoordinatesToMapCoordinates()
{
    var level = new Level(new Size(3, 5));
    level.RenderIn3D = true;
    Assert.AreEqual(new Vector2D(1, 2), level.GetMapCoordinates(new Vector2D(0, 0)));
    Assert.AreEqual(new Vector2D(0, 0), level.GetMapCoordinates(new Vector2D(-1, 2)));
    Assert.AreEqual(new Vector2D(2, 0), level.GetMapCoordinates(new Vector2D(1, 2)));
    Assert.AreEqual(new Vector2D(0, 4), level.GetMapCoordinates(new Vector2D(-1, -2)));
    Assert.AreEqual(new Vector2D(2, 4), level.GetMapCoordinates(new Vector2D(1, -2)));
}
[Test, CloseAfterFirstFrame]
public void TestSetTileWithScreenPositionIn2D()
{
    var level = new MockLevel(new Size(3));
    SetTilesWithScreenPosition(level);
    AssertTilesWithScreenPosition(level);
}
[Test, CloseAfterFirstFrame]
public void TestSetTileWithScreenPositionIn3D()
{
    SetUpCamera();
    var level = new MockLevel(new Size(3)) { RenderIn3D = true };
    SetTilesWithScreenPosition(level);
    AssertTilesWithScreenPosition(level);
}
[Test, CloseAfterFirstFrame]
public void InteractWithOnlyInteractableTiles()
{
    var level = new Level(new Size(2, 2));
    level.RenderIn3D = true;
    level.SetTile(new Vector2D(0, 0), LevelTileType.Blocked);
    level.SetTile(new Vector2D(1, 0), LevelTileType.ExitPoint);
    level.SetTile(new Vector2D(0, 1), LevelTileType.SpawnPoint);
    level.SetTile(new Vector2D(1, 1), LevelTileType.Placeable);
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(0, 0)));
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(1, 0)));
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(0, 1)));
    Assert.IsTrue(level.IsTileInteractable(new Vector2D(1, 1)));
    Assert.IsTrue(level.IsTileInteractable(new Vector2D(2, 2)));
}
[Test, CloseAfterFirstFrame]
public void TilesOutsideOfTheGridAreNotInteractable()
{
    var level = new Level(new Size(2, 2));
    level.RenderIn3D = true;
    level.SetTile(new Vector2D(0, 0), LevelTileType.Placeable);
    level.SetTile(new Vector2D(1, 0), LevelTileType.Placeable);
    level.SetTile(new Vector2D(0, 1), LevelTileType.Placeable);
    level.SetTile(new Vector2D(1, 1), LevelTileType.Placeable);
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(-0.1f, 0)));
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(0, -0.1f)));
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(2.1f, 0)));
    Assert.IsFalse(level.IsTileInteractable(new Vector2D(0, 2.1f)));
}
See Also