-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from mackysoft/feature/lifecycle-sequence-test
Implement `ISceneEntryPoint` lifecycle sequence test
- Loading branch information
Showing
9 changed files
with
479 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
12 changes: 12 additions & 0 deletions
12
.../MackySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointCallbackFlagsStore.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
namespace MackySoft.Navigathena.SceneManagement.Tests | ||
{ | ||
public sealed class SceneEntryPointCallbackFlagsStore : ISceneEntryPointLifecycleListener | ||
{ | ||
public SceneEntryPointCallbackFlags Value { get; private set; } | ||
|
||
void ISceneEntryPointLifecycleListener.OnReceive (SceneEntryPointCallbackFlags flags) | ||
{ | ||
Value |= flags; | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...ySoft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointCallbackFlagsStore.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
...oft.Navigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
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 ISceneEntryPointLifecycleAsserter CreateSequenceAsserter () | ||
{ | ||
return new SceneEntryPointLifecycleAsserter(this); | ||
} | ||
|
||
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)); | ||
} | ||
} | ||
|
||
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}.\n{EnumerateActualSequence()}"); | ||
} | ||
|
||
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}.\n{EnumerateActualSequence()}"); | ||
} | ||
|
||
if (actual.flags != expected.flags) | ||
{ | ||
throw new Exception($"Expected flags is {expected.flags} but actual is {actual.flags}.\n{EnumerateActualSequence()}"); | ||
} | ||
} | ||
} | ||
|
||
string EnumerateActualSequence () | ||
{ | ||
return string.Join("\n", m_Recorder.m_Sequence.Select(x => $"{x.identifier}: {x.flags}")); | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...avigathena/Tests/Runtime/SceneManagement/SceneEntryPointLifecycleSequenceRecorder.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.