Skip to content

Commit

Permalink
Implement ISceneEntryPointLifecycleAsserter
Browse files Browse the repository at this point in the history
  • Loading branch information
mackysoft committed Nov 4, 2023
1 parent f5604f5 commit 3f6dcae
Showing 1 changed file with 62 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,27 @@

namespace MackySoft.Navigathena.SceneManagement.Tests
{

public interface ISceneEntryPointLifecycleAsserter
{
ISceneEntryPointLifecycleAsserter On (ISceneIdentifier identifier);
ISceneEntryPointLifecycleAsserter Called (SceneEntryPointCallbackFlags flags);
void SequenceEqual ();
}

public sealed class SceneEntryPointLifecycleSequenceRecorder
{

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

public void Assert (params (ISceneIdentifier identifier, SceneEntryPointCallbackFlags flags)[] expectedSequence)
public ISceneEntryPointLifecycleAsserter Create ()
{
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}.");
}
}
return new SceneEntryPointLifecycleAsserter(this);
}

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

sealed class Listener : ISceneEntryPointLifecycleListener
Expand All @@ -50,7 +39,57 @@ public Listener (SceneEntryPointLifecycleSequenceRecorder assert, ISceneIdentifi

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

sealed class SceneEntryPointLifecycleAsserter : ISceneEntryPointLifecycleAsserter
{

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

ISceneIdentifier m_Current;

public SceneEntryPointLifecycleAsserter (SceneEntryPointLifecycleSequenceRecorder recorder)
{
m_Recorder = recorder;
}

public ISceneEntryPointLifecycleAsserter On (ISceneIdentifier identifier)
{
m_Current = identifier;
return this;
}

public ISceneEntryPointLifecycleAsserter Called (SceneEntryPointCallbackFlags flags)
{
m_Sequence.Add((m_Current, flags));
return this;
}

public void SequenceEqual ()
{
if (m_Recorder.m_Sequence.Count != m_Sequence.Count)
{
throw new Exception($"Expected sequence length is {m_Sequence.Count} but actual is {m_Recorder.m_Sequence.Count}.");
}

for (int i = 0; i < m_Sequence.Count; i++)
{
var actual = m_Recorder.m_Sequence[i];
var expected = m_Sequence[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}.");
}
}
}
}
}
Expand Down

0 comments on commit 3f6dcae

Please sign in to comment.