Skip to content

Commit dbc8565

Browse files
authored
Merge pull request #79 from bazyleu/feature/attribute-tests
Add attribute tests
2 parents 4770997 + a9b836e commit dbc8565

18 files changed

Lines changed: 252 additions & 1 deletion

Assets/UniStateTests/PlayMode/GoToStateTests/Infrastructure/StateGoTo1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
namespace UniStateTests.PlayMode.GoToStateTests.Infrastructure
77
{
8-
[StateBehaviour(ProhibitReturnToState = true, InitializeOnStateTransition = true)]
98
internal class StateGoTo1: StateBase
109
{
1110
private readonly ExecutionLogger _logger;

Assets/UniStateTests/PlayMode/StateBehaviorAttributeTests.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using System.Collections;
2+
using Cysharp.Threading.Tasks;
3+
using NUnit.Framework;
4+
using UniState;
5+
using UniStateTests.Common;
6+
using UniStateTests.PlayMode.RecoveryTransitionTests.Infrastructure;
7+
using UniStateTests.PlayMode.StateBehaviorAttributeTests.Infrastructure;
8+
using UnityEngine.TestTools;
9+
using VContainer;
10+
11+
namespace UniStateTests.PlayMode.StateBehaviorAttributeTests
12+
{
13+
[TestFixture]
14+
public class BehaviorAttributeVContainerTests : VContainerTestsBase
15+
{
16+
[UnityTest]
17+
public IEnumerator RunChaneOfStateWithAttributes_ExitFromChain_ChainExecutedCorrectly() => UniTask.ToCoroutine(async () =>
18+
{
19+
await RunAndVerify<StateMachineBehaviourAttribute, FirstState>();
20+
});
21+
22+
protected override void SetupBindings(IContainerBuilder builder)
23+
{
24+
base.SetupBindings(builder);
25+
26+
builder.RegisterStateMachine<StateMachineBehaviourAttribute>();
27+
builder.RegisterState<FirstState>();
28+
builder.RegisterState<NoReturnState>();
29+
builder.RegisterState<FastInitializeState>();
30+
31+
builder.Register<BehaviourAttributeTestHelper>(Lifetime.Singleton);
32+
}
33+
}
34+
}

Assets/UniStateTests/PlayMode/StateBehaviorAttributeTests/BehaviorAttributeVContainerTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Collections;
2+
using Cysharp.Threading.Tasks;
3+
using NUnit.Framework;
4+
using UniState;
5+
using UniStateTests.Common;
6+
using UniStateTests.PlayMode.RecoveryTransitionTests.Infrastructure;
7+
using UniStateTests.PlayMode.StateBehaviorAttributeTests.Infrastructure;
8+
using UnityEngine.TestTools;
9+
using VContainer;
10+
using Zenject;
11+
12+
namespace UniStateTests.PlayMode.StateBehaviorAttributeTests
13+
{
14+
[TestFixture]
15+
public class BehaviorAttributeZenjectTests: ZenjectTestsBase
16+
{
17+
[UnityTest]
18+
public IEnumerator RunChaneOfStateWithAttributes_ExitFromChain_ChainExecutedCorrectly() => UniTask.ToCoroutine(async () =>
19+
{
20+
await RunAndVerify<StateMachineBehaviourAttribute, FirstState>();
21+
});
22+
23+
protected override void SetupBindings(DiContainer container)
24+
{
25+
base.SetupBindings(container);
26+
27+
container.BindInterfacesAndSelfTo<BehaviourAttributeTestHelper>().AsSingle();
28+
29+
container.BindStateMachine<StateMachineBehaviourAttribute>();
30+
31+
container.BindState<FirstState>();
32+
container.BindState<NoReturnState>();
33+
container.BindState<FastInitializeState>();
34+
}
35+
}
36+
}

Assets/UniStateTests/PlayMode/StateBehaviorAttributeTests/BehaviorAttributeZenjectTests.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/UniStateTests/PlayMode/StateBehaviorAttributeTests/Infrastructure.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace UniStateTests.PlayMode.StateBehaviorAttributeTests.Infrastructure
2+
{
3+
internal class BehaviourAttributeTestHelper
4+
{
5+
public bool ExecutedFirstState = false;
6+
}
7+
}

Assets/UniStateTests/PlayMode/StateBehaviorAttributeTests/Infrastructure/BehaviourAttributeTestHelper.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Threading;
2+
using Cysharp.Threading.Tasks;
3+
using UniState;
4+
using UniStateTests.Common;
5+
6+
namespace UniStateTests.PlayMode.StateBehaviorAttributeTests.Infrastructure
7+
{
8+
[StateBehaviour(InitializeOnStateTransition = true)]
9+
internal class FastInitializeState : StateBase
10+
{
11+
private readonly ExecutionLogger _logger;
12+
13+
public FastInitializeState(ExecutionLogger logger)
14+
{
15+
_logger = logger;
16+
}
17+
18+
public override async UniTask Initialize(CancellationToken token)
19+
{
20+
await UniTask.Yield(token);
21+
22+
_logger.LogStep("FastInitializeState", $"Initialize");
23+
}
24+
25+
public override async UniTask<StateTransitionInfo> Execute(CancellationToken token)
26+
{
27+
await UniTask.Yield(token);
28+
29+
_logger.LogStep("FastInitializeState", $"Execute");
30+
31+
return Transition.GoBack();
32+
}
33+
34+
public override async UniTask Exit(CancellationToken token)
35+
{
36+
await UniTask.Yield(token);
37+
38+
_logger.LogStep("FastInitializeState", $"Exit");
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)