Update README.md to include project description, developer documentation links, and license information.
CI / build-test (push) Successful in 1m6s
CI / build-test (push) Successful in 1m6s
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
using MrGameEng.Core;
|
||||
using Xunit;
|
||||
|
||||
namespace MrGameEng.Core.Tests;
|
||||
|
||||
public class SceneManagerTests
|
||||
{
|
||||
private sealed class TrackingScene : Scene
|
||||
{
|
||||
public int LoadCount;
|
||||
public int UnloadCount;
|
||||
public int UpdateCount;
|
||||
|
||||
protected override void OnLoad() => LoadCount++;
|
||||
|
||||
protected override void OnUnload() => UnloadCount++;
|
||||
|
||||
public override void Update(GameClock clock)
|
||||
{
|
||||
UpdateCount++;
|
||||
base.Update(clock);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Switch_IsDeferred_UntilNextUpdate()
|
||||
{
|
||||
var context = new EngineContext();
|
||||
var scene = new TrackingScene();
|
||||
|
||||
context.Scenes.Switch(scene);
|
||||
|
||||
Assert.Null(context.Scenes.Current);
|
||||
Assert.Equal(0, scene.LoadCount);
|
||||
|
||||
context.Scenes.Update(context.Clock);
|
||||
|
||||
Assert.Same(scene, context.Scenes.Current);
|
||||
Assert.Equal(1, scene.LoadCount);
|
||||
Assert.Equal(1, scene.UpdateCount);
|
||||
Assert.True(scene.IsLoaded);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Switch_UnloadsPreviousScene_AndLoadsNext()
|
||||
{
|
||||
var context = new EngineContext();
|
||||
var first = new TrackingScene();
|
||||
var second = new TrackingScene();
|
||||
|
||||
context.Scenes.Switch(first);
|
||||
context.Scenes.Update(context.Clock);
|
||||
context.Scenes.Switch(second);
|
||||
context.Scenes.Update(context.Clock);
|
||||
|
||||
Assert.Equal(1, first.UnloadCount);
|
||||
Assert.False(first.IsLoaded);
|
||||
Assert.Same(second, context.Scenes.Current);
|
||||
Assert.Equal(1, second.LoadCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Switch_ToNull_UnloadsCurrentScene()
|
||||
{
|
||||
var context = new EngineContext();
|
||||
var scene = new TrackingScene();
|
||||
|
||||
context.Scenes.Switch(scene);
|
||||
context.Scenes.Update(context.Clock);
|
||||
context.Scenes.Switch(null);
|
||||
context.Scenes.Update(context.Clock);
|
||||
|
||||
Assert.Null(context.Scenes.Current);
|
||||
Assert.Equal(1, scene.UnloadCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Update_WithoutScene_DoesNothing()
|
||||
{
|
||||
var context = new EngineContext();
|
||||
|
||||
context.Scenes.Update(context.Clock);
|
||||
context.Scenes.Draw(context.Clock);
|
||||
|
||||
Assert.Null(context.Scenes.Current);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user