Initial Commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3f01a7aab70acf449c179f9d22e6ff5
|
||||
folderAsset: yes
|
||||
timeCreated: 1527865953
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
|
||||
using System.Collections;
|
||||
using ModestTree;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Zenject.Tests.TestAnimationStateBehaviourInject
|
||||
{
|
||||
public class TestAnimationStateBehaviourInject : ZenjectIntegrationTestFixture
|
||||
{
|
||||
const string ResourcePrefix = "TestAnimationStateBehaviourInject/";
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator Test1()
|
||||
{
|
||||
PreInstall();
|
||||
var prefab = FixtureUtil.GetPrefab(ResourcePrefix + "Foo");
|
||||
|
||||
StateBehaviour1.OnStateEnterCalls = 0;
|
||||
|
||||
Container.InstantiatePrefab(prefab);
|
||||
Container.BindInterfacesAndSelfTo<Foo>().AsSingle();
|
||||
PostInstall();
|
||||
|
||||
yield return null;
|
||||
|
||||
Assert.IsEqual(StateBehaviour1.OnStateEnterCalls, 1);
|
||||
}
|
||||
|
||||
public class Foo : IInitializable
|
||||
{
|
||||
public bool HasInitialized
|
||||
{
|
||||
get; private set;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
HasInitialized = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f80ffddc2b920e54f85483d37863d1ba
|
||||
timeCreated: 1527866041
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 503a300139444eda80c6549ec29b3b20
|
||||
timeCreated: 1587924687
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using System.Threading.Tasks;
|
||||
using Zenject;
|
||||
|
||||
namespace Zenject.Tests.TestAnimationStateBehaviourInject
|
||||
{
|
||||
public class DelayedInitializeKernel : BaseMonoKernelDecorator
|
||||
{
|
||||
public async override void Initialize()
|
||||
{
|
||||
await Task.Delay(5000);
|
||||
DecoratedMonoKernel.Initialize();
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 983f0bc44f6541bfab062ceec72231d3
|
||||
timeCreated: 1587867811
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
using Zenject;
|
||||
|
||||
namespace Zenject.Tests.TestAnimationStateBehaviourInject
|
||||
{
|
||||
public class KernelDecoratorInstaller : Installer<KernelDecoratorInstaller>
|
||||
{
|
||||
public override void InstallBindings()
|
||||
{
|
||||
Container.BindInterfacesTo<DecoratableMonoKernel>().AsCached();
|
||||
Container.Decorate<IDecoratableMonoKernel>().With<DelayedInitializeKernel>();
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 71d4a84946422ad49ae352537c257aed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+47
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using ModestTree.Util;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
using Zenject;
|
||||
using Zenject.Tests.TestAnimationStateBehaviourInject;
|
||||
|
||||
namespace Zenject.Tests.Misc.TestMonoKernelDecoration
|
||||
{
|
||||
public class TestMonoKernelDecoration : ZenjectIntegrationTestFixture
|
||||
{
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestDelayedMonoKernelDecorator()
|
||||
{
|
||||
PreInstall();
|
||||
|
||||
Container.Rebind<InitializableManager>().To<InitializableManagerSpy>().AsCached();
|
||||
KernelDecoratorInstaller.Install(Container);
|
||||
PostInstall();
|
||||
|
||||
yield return new WaitForSeconds(1.0f);
|
||||
|
||||
InitializableManagerSpy initializableManager = SceneContext.Container.Resolve<InitializableManager>() as InitializableManagerSpy;
|
||||
var initializedBeforeDelay = initializableManager.IsInitialized;
|
||||
|
||||
yield return new WaitForSeconds(6.0f);
|
||||
var initializedAfterDelay = initializableManager.IsInitialized;
|
||||
|
||||
Assert.IsFalse(initializedBeforeDelay);
|
||||
Assert.IsTrue(initializedAfterDelay);
|
||||
}
|
||||
|
||||
private class InitializableManagerSpy : InitializableManager
|
||||
{
|
||||
|
||||
public InitializableManagerSpy(List<IInitializable> initializables, List<ValuePair<Type, int>> priorities) : base(initializables, priorities){}
|
||||
|
||||
public bool IsInitialized => _hasInitialized;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 166ad9cc65d872b48badf6da39e4a31c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e6a5ac4ad92f5574e8f348463d68fa13
|
||||
folderAsset: yes
|
||||
timeCreated: 1528396585
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using ModestTree;
|
||||
using UnityEngine;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Zenject.Tests.AutoInjecter
|
||||
{
|
||||
public class TestZenAutoInjecter : ZenjectIntegrationTestFixture
|
||||
{
|
||||
GameObject GetPrefab(string name)
|
||||
{
|
||||
return FixtureUtil.GetPrefab("TestZenAutoInjecter/{0}".Fmt(name));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestAddComponent()
|
||||
{
|
||||
PreInstall();
|
||||
|
||||
Container.Bind<Foo>().AsSingle();
|
||||
|
||||
PostInstall();
|
||||
|
||||
var bar = new GameObject("bar").AddComponent<Bar>();
|
||||
|
||||
Assert.That(!bar.ConstructCalled);
|
||||
Assert.IsNull(bar.Foo);
|
||||
|
||||
bar.gameObject.AddComponent<ZenAutoInjecter>();
|
||||
|
||||
Assert.IsEqual(bar.Foo, Container.Resolve<Foo>());
|
||||
yield break;
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefab()
|
||||
{
|
||||
PreInstall();
|
||||
|
||||
Container.Bind<Foo>().AsSingle();
|
||||
|
||||
PostInstall();
|
||||
yield return null;
|
||||
|
||||
var barGameObject = GameObject.Instantiate(GetPrefab("Bar"));
|
||||
var bar = barGameObject.GetComponentInChildren<Bar>();
|
||||
|
||||
Assert.IsEqual(bar.Foo, Container.Resolve<Foo>());
|
||||
Assert.That(bar.ConstructCalled);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithSearchContainerSourceInGameObjectContext()
|
||||
{
|
||||
PreInstall();
|
||||
Container.Bind<Gorp>().FromSubContainerResolve().ByNewContextPrefab(GetPrefab("GorpContext")).AsSingle();
|
||||
PostInstall();
|
||||
yield return null;
|
||||
|
||||
var gorp = Container.Resolve<Gorp>();
|
||||
|
||||
var qux = GameObject.Instantiate(
|
||||
GetPrefab("QuxSearch"), Vector3.zero, Quaternion.identity, gorp.transform)
|
||||
.GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, gorp.Container);
|
||||
Assert.IsEqual(qux.Container.ParentContainers.Single(), Container);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithSearchContainerSourceInScene()
|
||||
{
|
||||
SkipInstall();
|
||||
yield return null;
|
||||
|
||||
var qux = GameObject.Instantiate(GetPrefab("QuxSearch")).GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, Container);
|
||||
Assert.IsEqual(qux.Container, Container.Resolve<SceneContext>().Container);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithSearchContainerSourceInDontDestroyOnLoad()
|
||||
{
|
||||
SkipInstall();
|
||||
yield return null;
|
||||
|
||||
var qux = GameObject.Instantiate(
|
||||
GetPrefab("QuxSearch"), Vector3.zero, Quaternion.identity, ProjectContext.Instance.transform)
|
||||
.GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, ProjectContext.Instance.Container);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithProjectContainerSourceInScene()
|
||||
{
|
||||
SkipInstall();
|
||||
yield return null;
|
||||
|
||||
var qux = GameObject.Instantiate(GetPrefab("QuxProject")).GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, ProjectContext.Instance.Container);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithSceneContainerSourceInScene()
|
||||
{
|
||||
SkipInstall();
|
||||
yield return null;
|
||||
|
||||
var qux = GameObject.Instantiate(GetPrefab("QuxScene")).GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, Container);
|
||||
Assert.IsEqual(qux.Container, Container.Resolve<SceneContext>().Container);
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
public IEnumerator TestInstantiatePrefabWithSceneContainerSourceInProject()
|
||||
{
|
||||
SkipInstall();
|
||||
yield return null;
|
||||
|
||||
var qux = GameObject.Instantiate(
|
||||
GetPrefab("QuxScene"), Vector3.zero, Quaternion.identity,
|
||||
ProjectContext.Instance.transform).GetComponentInChildren<Qux>();
|
||||
|
||||
Assert.IsEqual(qux.Container, ProjectContext.Instance.Container);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a70553092a2adf41a33f6f3fc9019b8
|
||||
timeCreated: 1528431963
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user