diff --git a/Assets/MackySoft/MackySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs b/Assets/MackySoft/MackySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs index 66c68de..38688aa 100644 --- a/Assets/MackySoft/MackySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs +++ b/Assets/MackySoft/MackySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs @@ -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 @@ -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}."); + } + } } } }