Skip to content

Commit

Permalink
Merge pull request #67 from bazyleu/feature/tests-refactoring
Browse files Browse the repository at this point in the history
Rename states for tests
  • Loading branch information
bazyleu authored Nov 12, 2024
2 parents fcfdf0e + 5324b79 commit 18a0e8b
Show file tree
Hide file tree
Showing 29 changed files with 101 additions and 101 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ public class GoBackVContainerTests : VContainerTestsBase
public IEnumerator RunChaneOfState_GoBackFromTheChain_ExitFromStateMachineWithCorrectOrderOfStates() =>
UniTask.ToCoroutine(async () =>
{
await RunAndVerify<StateMachineGoBack, StateGoBack1>();
await RunAndVerify<StateMachineGoBack, StateGoBackFirst>();
});

protected override void SetupBindings(IContainerBuilder builder)
{
base.SetupBindings(builder);

builder.Register<GoBackFlagsData>(Lifetime.Singleton);
builder.Register<GoBackTestHelper>(Lifetime.Singleton);

builder.RegisterStateMachine<StateMachineGoBack>();
builder.RegisterState<StateGoBack1>();
builder.RegisterState<StateGoBack2>();
builder.RegisterState<StateGoBack3>();
builder.RegisterState<StateGoBackFirst>();
builder.RegisterState<StateGoBackSecond>();
builder.RegisterState<StateGoBackThird>();
}
}
}
10 changes: 5 additions & 5 deletions Assets/UniStateTests/PlayMode/GoBackTests/GoBackZenjectTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ internal class GoBackZenjectTests : ZenjectTestsBase
public IEnumerator RunChaneOfState_GoBackFromTheChain_ExitFromStateMachineWithCorrectOrderOfStates() =>
UniTask.ToCoroutine(async () =>
{
await RunAndVerify<StateMachineGoBack, StateGoBack1>();
await RunAndVerify<StateMachineGoBack, StateGoBackFirst>();
});

protected override void SetupBindings(DiContainer container)
{
base.SetupBindings(container);

container.Bind<GoBackFlagsData>().ToSelf().AsSingle();
container.Bind<GoBackTestHelper>().ToSelf().AsSingle();

container.BindStateMachine<StateMachineGoBack>();
container.BindState<StateGoBack1>();
container.BindState<StateGoBack2>();
container.BindState<StateGoBack3>();
container.BindState<StateGoBackFirst>();
container.BindState<StateGoBackSecond>();
container.BindState<StateGoBackThird>();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace UniStateTests.PlayMode.GoBackTests.Infrastructure
{
internal class GoBackFlagsData
internal class GoBackTestHelper
{
public bool ExecutedState1 = false;
public bool ExecutedState2 = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

namespace UniStateTests.PlayMode.GoBackTests.Infrastructure
{
internal class StateGoBack1 : StateBase
internal class StateGoBackFirst : StateBase
{
private readonly ExecutionLogger _logger;
private readonly GoBackFlagsData _goBackFlags;
private readonly GoBackTestHelper _goBackFlags;

public StateGoBack1(ExecutionLogger logger, GoBackFlagsData goBackFlags)
public StateGoBackFirst(ExecutionLogger logger, GoBackTestHelper goBackFlags)
{
_logger = logger;
_goBackFlags = goBackFlags;
}

public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
{
_logger.LogStep("StateGoBack1", "Execute");
_logger.LogStep("StateGoBackFirst", "Execute");

await UniTask.Yield();

Expand All @@ -29,7 +29,7 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok

_goBackFlags.ExecutedState1 = true;

return Transition.GoTo<StateGoBack2, int>(42);
return Transition.GoTo<StateGoBackSecond, int>(42);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

namespace UniStateTests.PlayMode.GoBackTests.Infrastructure
{
internal class StateGoBack2 : StateBase<int>
internal class StateGoBackSecond : StateBase<int>
{
private readonly ExecutionLogger _logger;
private readonly GoBackFlagsData _goBackFlags;
private readonly GoBackTestHelper _goBackFlags;

public StateGoBack2(ExecutionLogger logger, GoBackFlagsData goBackFlags)
public StateGoBackSecond(ExecutionLogger logger, GoBackTestHelper goBackFlags)
{
_logger = logger;
_goBackFlags = goBackFlags;
}

public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
{
_logger.LogStep("StateGoBack2", $"Execute:{Payload}");
_logger.LogStep("StateGoBackSecond", $"Execute:{Payload}");

await UniTask.Yield();

Expand All @@ -29,7 +29,7 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok

_goBackFlags.ExecutedState2 = true;

return Transition.GoTo<StateGoBack3>();
return Transition.GoTo<StateGoBackThird>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@

namespace UniStateTests.PlayMode.GoBackTests.Infrastructure
{
internal class StateGoBack3 : StateBase
internal class StateGoBackThird : StateBase
{
private readonly ExecutionLogger _logger;
public StateGoBack3(ExecutionLogger logger, GoBackFlagsData goBackFlags)
public StateGoBackThird(ExecutionLogger logger)
{
_logger = logger;
}

public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
{
_logger.LogStep("StateGoBack3", "Execute");
_logger.LogStep("StateGoBackThird", "Execute");

await UniTask.Yield();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace UniStateTests.PlayMode.GoBackTests.Infrastructure
internal class StateMachineGoBack : VerifiableStateMachine
{
protected override string ExpectedLog =>
"StateGoBack1 (Execute) -> StateGoBack2 (Execute:42) -> StateGoBack3 (Execute) -> " +
"StateGoBack2 (Execute:42) -> StateGoBack1 (Execute)";
"StateGoBackFirst (Execute) -> StateGoBackSecond (Execute:42) -> StateGoBackThird (Execute) -> " +
"StateGoBackSecond (Execute:42) -> StateGoBackFirst (Execute)";

public StateMachineGoBack(ExecutionLogger logger) : base(logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ protected override void SetupBindings(IContainerBuilder builder)
builder.RegisterState<StateGoTo4>();
builder.RegisterState<StateGoTo5>();
builder.RegisterState<CompositeStateGoTo6>();
builder.RegisterState<SubStateGoToX6A>();
builder.RegisterState<SubStateGoToX6B>();
builder.RegisterState<SubStateGoTo6First>();
builder.RegisterState<SubStateGoTo6Second>();
builder.RegisterState<CompositeStateGoTo7>();
builder.RegisterState<SubStateGoToX7A>();
builder.RegisterState<SubStateGoToX7B>();
builder.RegisterState<SubStateGoTo7First>();
builder.RegisterState<SubStateGoTo7Second>();
builder.RegisterState<StateGoTo8>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ protected override void SetupBindings(DiContainer container)
container.BindState<StateGoTo4>();
container.BindState<StateGoTo5>();
container.BindState<CompositeStateGoTo6>();
container.BindState<SubStateGoToX6A>();
container.BindState<SubStateGoToX6B>();
container.BindState<SubStateGoTo6First>();
container.BindState<SubStateGoTo6Second>();
container.BindState<CompositeStateGoTo7>();
container.BindState<SubStateGoToX7A>();
container.BindState<SubStateGoToX7B>();
container.BindState<SubStateGoTo7First>();
container.BindState<SubStateGoTo7Second>();
container.BindState<StateGoTo8>();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ internal class CompositeStateGoTo6 : DefaultCompositeState
}


internal class SubStateGoToX6A : SubStateBase<CompositeStateGoTo6>
internal class SubStateGoTo6First : SubStateBase<CompositeStateGoTo6>
{
private readonly ExecutionLogger _logger;

public SubStateGoToX6A(ExecutionLogger logger)
public SubStateGoTo6First(ExecutionLogger logger)
{
_logger = logger;
}

public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
{
_logger.LogStep("SubStateGoToX6A", "Execute");
_logger.LogStep("SubStateGoTo6First", "Execute");

await UniTask.Yield(token);
await UniTask.Yield(token);
Expand All @@ -31,11 +31,11 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok
}
}

internal class SubStateGoToX6B : SubStateBase<CompositeStateGoTo6>
internal class SubStateGoTo6Second : SubStateBase<CompositeStateGoTo6>
{
private readonly ExecutionLogger _logger;

public SubStateGoToX6B(ExecutionLogger logger)
public SubStateGoTo6Second(ExecutionLogger logger)
{
_logger = logger;
}
Expand All @@ -44,7 +44,7 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok
{
await UniTask.Yield(token);

_logger.LogStep("SubStateGoToX6B", "Execute");
_logger.LogStep("SubStateGoTo6Second", "Execute");

await UniTask.Yield(token);
await UniTask.Yield(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@ internal class CompositeStateGoTo7: DefaultCompositeState<CompositeStatePayload>

}

internal class SubStateGoToX7A : SubStateBase<CompositeStateGoTo7, CompositeStatePayload>
internal class SubStateGoTo7First : SubStateBase<CompositeStateGoTo7, CompositeStatePayload>
{
private readonly ExecutionLogger _logger;

public SubStateGoToX7A(ExecutionLogger logger)
public SubStateGoTo7First(ExecutionLogger logger)
{
_logger = logger;
}

public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
{
_logger.LogStep("SubStateGoToX7A", $"Execute:{Payload.DelayFirstSubState}");
_logger.LogStep("SubStateGoTo7First", $"Execute:{Payload.DelayFirstSubState}");

if (Payload.DelayFirstSubState)
{
Expand All @@ -34,16 +34,16 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok

await UniTask.Yield(token);
await UniTask.Yield(token);

return Transition.GoTo<IStateGoTo8, bool>(true);
}
}

internal class SubStateGoToX7B : SubStateBase<CompositeStateGoTo7, CompositeStatePayload>
internal class SubStateGoTo7Second : SubStateBase<CompositeStateGoTo7, CompositeStatePayload>
{
private readonly ExecutionLogger _logger;

public SubStateGoToX7B(ExecutionLogger logger)
public SubStateGoTo7Second(ExecutionLogger logger)
{
_logger = logger;
}
Expand All @@ -52,7 +52,7 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok
{
await UniTask.Yield(token);

_logger.LogStep("SubStateGoToX7B", $"Execute:{Payload.DelayFirstSubState}");
_logger.LogStep("SubStateGoTo7Second", $"Execute:{Payload.DelayFirstSubState}");

await UniTask.Yield(token);
await UniTask.Yield(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ internal class StateMachineGoToState : VerifiableStateMachine
{
protected override string ExpectedLog =>
"StateGoTo1 (Execute) -> StateGoTo2 (Execute) -> StateGoTo3 (Execute) -> " +
"StateGoTo4 (Execute) -> StateGoTo5 (Execute:42) -> SubStateGoToX6A (Execute) -> SubStateGoToX6B (Execute) -> " +
"SubStateGoToX7A (Execute:True) -> SubStateGoToX7B (Execute:True) -> StateGoTo8 (Execute:False) -> " +
"SubStateGoToX7A (Execute:False) -> SubStateGoToX7B (Execute:False) -> StateGoTo8 (Execute:True)";
"StateGoTo4 (Execute) -> StateGoTo5 (Execute:42) -> SubStateGoTo6First (Execute) -> SubStateGoTo6Second (Execute) -> " +
"SubStateGoTo7First (Execute:True) -> SubStateGoTo7Second (Execute:True) -> StateGoTo8 (Execute:False) -> " +
"SubStateGoTo7First (Execute:False) -> SubStateGoTo7Second (Execute:False) -> StateGoTo8 (Execute:True)";

public StateMachineGoToState(ExecutionLogger logger) : base(logger)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace UniStateTests.PlayMode.RecoveryTransitionTests.Infrastructure
{
internal class StateInitRecovery : StateBase
internal class StateInitial : StateBase
{
private readonly ExecutionLogger _logger;

public StateInitRecovery(ExecutionLogger logger)
public StateInitial(ExecutionLogger logger)
{
_logger = logger;
}
Expand All @@ -18,9 +18,9 @@ public override async UniTask<StateTransitionInfo> Execute(CancellationToken tok
{
await UniTask.Yield(token);

_logger.LogStep("StateInitRecovery", $"Execute");
_logger.LogStep("StateInitial", $"Execute");

return Transition.GoTo<StateThrowTwoExceptionRecovery>();
return Transition.GoTo<StateThrowTwoException>();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ protected override void HandleError(StateMachineErrorData errorData)
}

protected override string ExpectedLog =>
"StateInitRecovery (Execute) -> " +
"StateThrowTwoExceptionRecovery (Initialize) -> StateMachineDefaultRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoExceptionRecovery (Execute, Exit) -> StateMachineDefaultRecovery (HandleError (Exit exception)) -> " +
"StateFailExecutionRecovery (Execute) -> StateMachineDefaultRecovery (HandleError (Execution exception)) -> " +
"StateFailExecutionRecovery (Exit, Disposables) -> " +
"StateThrowTwoExceptionRecovery (Initialize) -> StateMachineDefaultRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoExceptionRecovery (Execute, Exit) -> StateMachineDefaultRecovery (HandleError (Exit exception)) -> " +
"StateFailExecutionRecovery (Execute, Exit, Disposables)";
"StateInitial (Execute) -> " +
"StateThrowTwoException (Initialize) -> StateMachineDefaultRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoException (Execute, Exit) -> StateMachineDefaultRecovery (HandleError (Exit exception)) -> " +
"StateWithFailExecution (Execute) -> StateMachineDefaultRecovery (HandleError (Execution exception)) -> " +
"StateWithFailExecution (Exit, Disposables) -> " +
"StateThrowTwoException (Initialize) -> StateMachineDefaultRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoException (Execute, Exit) -> StateMachineDefaultRecovery (HandleError (Exit exception)) -> " +
"StateWithFailExecution (Execute, Exit, Disposables)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ protected override StateTransitionInfo BuildRecoveryTransition(IStateTransitionF
=> transitionFactory.CreateExitTransition();

protected override string ExpectedLog =>
"StateInitRecovery (Execute) -> " +
"StateThrowTwoExceptionRecovery (Initialize) -> StateMachineExitRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoExceptionRecovery (Execute, Exit) -> StateMachineExitRecovery (HandleError (Exit exception)) -> " +
"StateFailExecutionRecovery (Execute) -> StateMachineExitRecovery (HandleError (Execution exception)) -> " +
"StateFailExecutionRecovery (Exit, Disposables)";
"StateInitial (Execute) -> " +
"StateThrowTwoException (Initialize) -> StateMachineExitRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoException (Execute, Exit) -> StateMachineExitRecovery (HandleError (Exit exception)) -> " +
"StateWithFailExecution (Execute) -> StateMachineExitRecovery (HandleError (Execution exception)) -> " +
"StateWithFailExecution (Exit, Disposables)";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ protected override void HandleError(StateMachineErrorData errorData)
}

protected override StateTransitionInfo BuildRecoveryTransition(IStateTransitionFactory transitionFactory)
=> transitionFactory.CreateStateTransition<StateMagicRecovery>();
=> transitionFactory.CreateStateTransition<StateStartedAfterException>();

protected override string ExpectedLog =>
"StateInitRecovery (Execute) -> " +
"StateThrowTwoExceptionRecovery (Initialize) -> StateMachineGoToStateRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoExceptionRecovery (Execute, Exit) -> StateMachineGoToStateRecovery (HandleError (Exit exception)) -> " +
"StateFailExecutionRecovery (Execute) -> StateMachineGoToStateRecovery (HandleError (Execution exception)) -> " +
"StateFailExecutionRecovery (Exit, Disposables) -> StateMagicRecovery (Execute)";
"StateInitial (Execute) -> " +
"StateThrowTwoException (Initialize) -> StateMachineGoToStateRecovery (HandleError (Initialize exception)) -> " +
"StateThrowTwoException (Execute, Exit) -> StateMachineGoToStateRecovery (HandleError (Exit exception)) -> " +
"StateWithFailExecution (Execute) -> StateMachineGoToStateRecovery (HandleError (Execution exception)) -> " +
"StateWithFailExecution (Exit, Disposables) -> StateStartedAfterException (Execute)";
}
}
Loading

0 comments on commit 18a0e8b

Please sign in to comment.