Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some tests #45

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions engine/Orbit.Engine.Tests/GameObjectTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
using Microsoft.Maui;
using Microsoft.Maui.Graphics;

namespace Orbit.Engine.Tests;

public class GameObjectTests
{
[Test]

Check failure on line 8 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 8 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)
public void AddShouldCallOnAddedToNewChild()
{
var parent = new MockGameObject();
var child = new MockGameObject();

child.OnAddedCount.Should().Be(0);

parent.Add(child);

child.OnAddedCount.Should().Be(1);
}

[Test]

Check failure on line 21 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 21 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 21 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 21 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)
public void RemoveShouldCallOnRemovedToNewChild()
{
var parent = new MockGameObject();
var child = new MockGameObject();

child.OnRemovedCount.Should().Be(0);

parent.Add(child);

child.OnRemovedCount.Should().Be(0);

parent.Remove(child);

child.OnRemovedCount.Should().Be(1);
}

[Test]

Check failure on line 38 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 38 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)
public void RenderShouldCallRenderOnChildren()
{
var parent = new MockGameObject();
var child = new MockGameObject();

parent.Render(null, RectF.Zero);

parent.RenderCount.Should().Be(1);
child.RenderCount.Should().Be(0);

parent.Add(child);

parent.Render(null, RectF.Zero);

parent.RenderCount.Should().Be(2);
child.RenderCount.Should().Be(1);
}

[Test]

Check failure on line 57 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'TestAttribute' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 57 in engine/Orbit.Engine.Tests/GameObjectTests.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'Test' could not be found (are you missing a using directive or an assembly reference?)
public void UpdateShouldCallUpdateOnChildren()
{
var parent = new MockGameObject();
var child = new MockGameObject();

parent.Update(16);

parent.UpdateCount.Should().Be(1);
child.UpdateCount.Should().Be(0);

parent.Add(child);

parent.Update(16);

parent.UpdateCount.Should().Be(2);
child.UpdateCount.Should().Be(1);
}
}
52 changes: 51 additions & 1 deletion engine/Orbit.Engine.Tests/GameSceneManagerTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using FluentAssertions;
using FluentAssertions;
using NUnit.Framework;
using Orbit.Engine.Tests.Mocks;

Expand Down Expand Up @@ -31,4 +31,54 @@ public void LoadSceneShouldChangeStateToLoaded()

manager.CurrentScene.Should().Be(sceneInstance);
}

[Test]
public void CompleteShouldMoveStateToCompleted()
{
GameSceneManager manager = new(new MockDispatcher(), null);

manager.Complete();

manager.State.Should().Be(GameState.Completed);
}

[Test]
public void GameOverShouldMoveStateToGameOver()
{
GameSceneManager manager = new(new MockDispatcher(), null);

manager.GameOver();

manager.State.Should().Be(GameState.GameOver);
}

[Test]
public void PauseShouldMoveStateToPaused()
{
GameSceneManager manager = new(new MockDispatcher(), null);

manager.Pause();

manager.State.Should().Be(GameState.Paused);
}

[Test]
public void StartShouldMoveStateToStarted()
{
GameSceneManager manager = new(new MockDispatcher(), null);

manager.Start();

manager.State.Should().Be(GameState.Started);
}

[Test]
public void StopShouldMoveStateToLoaded()
{
GameSceneManager manager = new(new MockDispatcher(), null);

manager.Stop();

manager.State.Should().Be(GameState.Loaded);
}
}
36 changes: 36 additions & 0 deletions engine/Orbit.Engine.Tests/Mocks/MockGameObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using Orbit.Engine;

namespace Orbit.Engine.Tests;

public class MockGameObject : GameObject
{
internal int OnAddedCount { get; private set; }

internal int OnRemovedCount { get; private set; }

internal int RenderCount { get; private set; }

internal int UpdateCount { get; private set; }

public override void OnAdded()
{
}

public override void OnRemoved()
{
}

public override void Render(ICanvas canvas, RectF dimensions)

Check failure on line 23 in engine/Orbit.Engine.Tests/Mocks/MockGameObject.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ICanvas' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in engine/Orbit.Engine.Tests/Mocks/MockGameObject.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'RectF' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in engine/Orbit.Engine.Tests/Mocks/MockGameObject.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'ICanvas' could not be found (are you missing a using directive or an assembly reference?)

Check failure on line 23 in engine/Orbit.Engine.Tests/Mocks/MockGameObject.cs

View workflow job for this annotation

GitHub Actions / build

The type or namespace name 'RectF' could not be found (are you missing a using directive or an assembly reference?)
{
base.Render(canvas, dimensions);

RenderCount++;
}

public override void Update(double millisecondsSinceLastUpdate)
{
base.Update(millisecondsSinceLastUpdate);

UpdateCount++;
}
}
11 changes: 1 addition & 10 deletions engine/Orbit.Engine/GameObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Orbit.Engine;
/// <summary>
/// Base class definition representing an object in a game.
/// </summary>
public abstract class GameObject : GameObjectContainer, IGameObject, IDrawable
public abstract class GameObject : GameObjectContainer, IGameObject
{
private GameScene currentScene;

Expand All @@ -32,15 +32,6 @@ public GameScene CurrentScene
}
}

void IDrawable.Draw(ICanvas canvas, RectF dirtyRect)
{
canvas.SaveState();

Render(canvas, dirtyRect);

canvas.RestoreState();
}

/// <summary>
/// Lifecycle method called to inform this <see cref="GameObject"/> that it has been added to a container and ultimately a game.
/// </summary>
Expand Down
Loading