Skip to content

Commit

Permalink
Add SceneEntryPointLifecycleSequenceRecorder
Browse files Browse the repository at this point in the history
  • Loading branch information
mackysoft committed Nov 4, 2023
1 parent 26fd608 commit f5604f5
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;

namespace MackySoft.Navigathena.SceneManagement.Tests
{
public sealed class SceneEntryPointLifecycleSequenceRecorder
{

readonly List<(ISceneIdentifier identifier, SceneEntryPointCallbackFlags flags)> m_Sequence = new();

public void Assert (params (ISceneIdentifier identifier, SceneEntryPointCallbackFlags flags)[] expectedSequence)
{
if (m_Sequence.Count != expectedSequence.Length)
{
throw new Exception($"Expected sequence length is {expectedSequence.Length} but actual is {m_Sequence.Count}.");
}

for (int i = 0; i < m_Sequence.Count; i++)
{
var actual = m_Sequence[i];
var expected = expectedSequence[i];

if (actual.identifier != expected.identifier)
{
throw new Exception($"Expected identifier is {expected.identifier} but actual is {actual.identifier}.");
}

if (actual.flags != expected.flags)
{
throw new Exception($"Expected flags is {expected.flags} but actual is {actual.flags}.");
}
}
}

public ISceneEntryPointLifecycleListener With (ISceneIdentifier identifier)
{
return new Listener(this,identifier);
}

sealed class Listener : ISceneEntryPointLifecycleListener
{
readonly SceneEntryPointLifecycleSequenceRecorder m_Assert;
readonly ISceneIdentifier m_Identifier;

public Listener (SceneEntryPointLifecycleSequenceRecorder assert, ISceneIdentifier identifier)
{
m_Assert = assert;
m_Identifier = identifier;
}

void ISceneEntryPointLifecycleListener.OnReceive (SceneEntryPointCallbackFlags flags)
{
m_Assert.m_Sequence.Add((m_Identifier,flags));
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f5604f5

Please sign in to comment.