-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
Major test refactoring and updates
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using UniState; | ||
|
||
namespace UniStateTests.Common | ||
{ | ||
public interface IVerifiableStateMachine : IStateMachine | ||
{ | ||
public void Verify(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System.Threading; | ||
using Cysharp.Threading.Tasks; | ||
using UniState; | ||
|
||
namespace UniStateTests.Common | ||
{ | ||
public static class StateMachineTestHelper | ||
{ | ||
public static async UniTask RunAndVerify<TStateMachine, TState>(ITypeResolver typeResolver, | ||
CancellationToken cancellationToken) | ||
where TStateMachine : class, IStateMachine, IVerifiableStateMachine | ||
where TState : class, IState<EmptyPayload> | ||
{ | ||
var stateMachine = | ||
StateMachineHelper.CreateStateMachine<TStateMachine, IVerifiableStateMachine>( | ||
typeResolver); | ||
await stateMachine.Execute<TState>(cancellationToken); | ||
|
||
stateMachine.Verify(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using NUnit.Framework; | ||
using UniState; | ||
|
||
namespace UniStateTests.Common | ||
{ | ||
public abstract class VerifiableStateMachine : StateMachine, IVerifiableStateMachine | ||
{ | ||
private readonly ExecutionLogger _logger; | ||
|
||
protected abstract string ExpectedLog { get; } | ||
|
||
protected VerifiableStateMachine(ExecutionLogger logger) | ||
{ | ||
_logger = logger; | ||
} | ||
|
||
protected override void OnError(Exception exception, StateMachineErrorType phase) | ||
{ | ||
throw new Exception($"StateMachine OnError. Current log: {_logger.FinishLogging()}", exception); | ||
} | ||
|
||
public void Verify() | ||
{ | ||
Assert.AreEqual(ExpectedLog, _logger.FinishLogging()); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
using Cysharp.Threading.Tasks; | ||
using UniState; | ||
using UnityEngine; | ||
using VContainer; | ||
using VContainer.Unity; | ||
|
||
namespace UniStateTests.Common | ||
{ | ||
public abstract class VContainerTestsBase : TestsBase | ||
{ | ||
private GameObject _containerHolder; | ||
private IObjectResolver _objectResolver; | ||
|
||
protected IObjectResolver Container => _objectResolver; | ||
|
||
public override void Setup() | ||
{ | ||
base.Setup(); | ||
|
||
_containerHolder = new GameObject("container"); | ||
var component = _containerHolder.AddComponent<TestsLifetimeScope>(); | ||
var testScope = component.CreateChild(SetupBindings); | ||
_objectResolver = testScope.Container; | ||
} | ||
|
||
public override void TearDown() | ||
{ | ||
base.TearDown(); | ||
|
||
Object.Destroy(_containerHolder); | ||
} | ||
|
||
protected async UniTask RunAndVerify<TStateMachine, TState>() | ||
where TStateMachine : class, IStateMachine, IVerifiableStateMachine | ||
where TState : class, IState<EmptyPayload> | ||
{ | ||
await StateMachineTestHelper.RunAndVerify<TStateMachine, TState>(Container.ToTypeResolver(), | ||
GetTimeoutToken()); | ||
} | ||
|
||
private class TestsLifetimeScope : LifetimeScope | ||
{ | ||
} | ||
|
||
protected virtual void SetupBindings(IContainerBuilder builder) | ||
{ | ||
builder.Register<ExecutionLogger>(Lifetime.Singleton); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using Cysharp.Threading.Tasks; | ||
using UniState; | ||
using Zenject; | ||
|
||
namespace UniStateTests.Common | ||
{ | ||
public abstract class ZenjectTestsBase : TestsBase | ||
{ | ||
private DiContainer _container; | ||
|
||
protected DiContainer Container => _container; | ||
|
||
public override void Setup() | ||
{ | ||
base.Setup(); | ||
|
||
_container = new DiContainer(StaticContext.Container); | ||
|
||
SetupBindings(Container); | ||
} | ||
|
||
public override void TearDown() | ||
{ | ||
base.TearDown(); | ||
|
||
StaticContext.Clear(); | ||
} | ||
|
||
protected async UniTask RunAndVerify<TStateMachine, TState>() | ||
where TStateMachine : class, IStateMachine, IVerifiableStateMachine | ||
where TState : class, IState<EmptyPayload> | ||
{ | ||
await StateMachineTestHelper.RunAndVerify<TStateMachine, TState>(Container.ToTypeResolver(), | ||
GetTimeoutToken()); | ||
} | ||
|
||
protected virtual void SetupBindings(DiContainer container) | ||
{ | ||
container.BindInterfacesAndSelfTo<ExecutionLogger>().AsSingle(); | ||
} | ||
} | ||
} |
This file was deleted.
This file was deleted.