Initial Commit

This commit is contained in:
2026-03-16 14:38:46 +02:00
commit b8f7327a21
2327 changed files with 253610 additions and 0 deletions
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 712f29884b0173a4193cd48315786df9
folderAsset: yes
timeCreated: 1533537390
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: bcfe42301470d994596ab617acdc6545
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,314 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.DiContainerMethods;
namespace Zenject.Tests.Bindings
{
public class TestDiContainerMethods : ZenjectIntegrationTestFixture
{
const string ResourcePrefix = "TestDiContainerMethods/";
GameObject FooPrefab
{
get { return GetPrefab("Foo"); }
}
GameObject GorpPrefab
{
get { return GetPrefab("Gorp"); }
}
GameObject CameraPrefab
{
get { return GetPrefab("Camera"); }
}
[UnityTest]
public IEnumerator TestInstantiateComponent()
{
SkipInstall();
var gameObject = new GameObject();
var foo = Container.InstantiateComponent<Foo>(gameObject);
Assert.That(foo.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiateComponentArgs()
{
SkipInstall();
var gameObject = new GameObject();
Assert.Throws(() => Container.InstantiateComponent<Gorp>(gameObject));
var gorp = Container.InstantiateComponent<Gorp>(gameObject, new object[] { "zxcv" });
Assert.IsEqual(gorp.Arg, "zxcv");
yield break;
}
[UnityTest]
public IEnumerator TestInstantiateComponentOnNewGameObject()
{
SkipInstall();
var foo = Container.InstantiateComponentOnNewGameObject<Foo>();
Assert.That(foo.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiateComponentOnNewGameObjectArgs()
{
SkipInstall();
Assert.Throws(() => Container.InstantiateComponentOnNewGameObject<Gorp>());
var gorp = Container.InstantiateComponentOnNewGameObject<Gorp>("sdf", new object[] { "zxcv" });
Assert.IsEqual(gorp.Arg, "zxcv");
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefab()
{
SkipInstall();
var go = Container.InstantiatePrefab(FooPrefab);
var foo = go.GetComponentInChildren<Foo>();
Assert.That(foo.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabForMonoBehaviour()
{
SkipInstall();
Assert.Throws(() => Container.InstantiatePrefab(GorpPrefab));
var gorp = Container.InstantiatePrefabForComponent<Gorp>(GorpPrefab, new object[] { "asdf" });
Assert.IsEqual(gorp.Arg, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabResource()
{
SkipInstall();
Assert.Throws(() => Container.InstantiatePrefabResource(ResourcePrefix + "Gorp"));
var gorp = Container.InstantiatePrefabResourceForComponent<Gorp>(ResourcePrefix + "Gorp", new object[] { "asdf" });
Assert.IsEqual(gorp.Arg, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabForComponent()
{
SkipInstall();
var camera = Container.InstantiatePrefabForComponent<Camera>(CameraPrefab, new object[0]);
Assert.IsNotNull(camera);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabForComponentMistake()
{
SkipInstall();
Assert.Throws(() => Container.InstantiatePrefabForComponent<Camera>(CameraPrefab, new object[] { "sdf" }));
yield break;
}
[UnityTest]
public IEnumerator TestInstantiateScriptableObjectResource()
{
SkipInstall();
var foo = Container.InstantiateScriptableObjectResource<Foo2>(ResourcePrefix + "Foo2");
Assert.That(foo.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiateScriptableObjectResourceArgs()
{
SkipInstall();
Assert.Throws(() => Container.InstantiateScriptableObjectResource<Gorp2>(ResourcePrefix + "Gorp2"));
var gorp = Container.InstantiateScriptableObjectResource<Gorp2>(ResourcePrefix + "Gorp2", new object[] { "asdf" });
Assert.IsEqual(gorp.Arg, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestInjectGameObject()
{
SkipInstall();
var go = GameObject.Instantiate(FooPrefab);
var foo = go.GetComponentInChildren<Foo>();
Assert.That(!foo.WasInjected);
Container.InjectGameObject(go);
Assert.That(foo.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInjectGameObjectForMonoBehaviour()
{
SkipInstall();
var go = GameObject.Instantiate(GorpPrefab);
Assert.Throws(() => Container.InjectGameObject(go));
var gorp = Container.InjectGameObjectForComponent<Gorp>(go, new object[] { "asdf" });
Assert.IsEqual(gorp.Arg, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestInjectGameObjectForComponent()
{
SkipInstall();
var go = GameObject.Instantiate(CameraPrefab);
Container.InjectGameObjectForComponent<Camera>(go, new object[0]);
yield break;
}
[UnityTest]
public IEnumerator TestInjectGameObjectForComponentMistake()
{
SkipInstall();
var go = GameObject.Instantiate(CameraPrefab);
Assert.Throws(() => Container.InjectGameObjectForComponent<Camera>(go, new object[] { "sdf" }));
yield break;
}
[UnityTest]
public IEnumerator TestLazyInstanceInjectorFail()
{
PreInstall();
Qux.WasInjected = false;
var qux = new Qux();
Container.BindInstance(qux);
Assert.That(!Qux.WasInjected);
PostInstall();
Assert.That(!Qux.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestLazyInstanceInjectorSuccess()
{
PreInstall();
Qux.WasInjected = false;
var qux = new Qux();
Container.BindInstance(qux);
Container.QueueForInject(qux);
Assert.That(!Qux.WasInjected);
PostInstall();
Assert.That(Qux.WasInjected);
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabForComponentExplicit()
{
SkipInstall();
var parentGameObject = new GameObject();
parentGameObject.transform.position = new Vector3(100, 100, 100);
var parentTransform = parentGameObject.transform;
var go = (Foo)Container.InstantiatePrefabForComponentExplicit(typeof(Foo), FooPrefab, new List<TypeValuePair>(), new GameObjectCreationParameters { ParentTransform = parentTransform });
var foo = go.GetComponentInChildren<Foo>();
Assert.IsEqual(foo.transform.position, new Vector3(100, 100, 100));
yield break;
}
[UnityTest]
public IEnumerator TestInstantiatePrefabForComponentWithPositionExplicit()
{
SkipInstall();
var parentGameObject = new GameObject();
parentGameObject.transform.position = new Vector3(100, 100, 100);
parentGameObject.transform.rotation = Quaternion.Euler(10, 10, 10);
var parentTransform = parentGameObject.transform;
var go = (Foo)Container.InstantiatePrefabForComponentExplicit(typeof(Foo), FooPrefab, new List<TypeValuePair>(), new GameObjectCreationParameters
{
ParentTransform = parentTransform,
Position = new Vector3(50, 50, 50),
Rotation = Quaternion.Euler(20, 20, 20)
});
var foo = go.GetComponentInChildren<Foo>();
Assert.That(Approximately(foo.transform.position, new Vector3(50, 50, 50)));
Assert.That(Approximately(foo.transform.rotation.eulerAngles, new Vector3(20, 20, 20)));
yield break;
}
static bool Approximately(Vector3 left, Vector3 right)
{
return Mathf.Approximately(left.x, right.x)
&& Mathf.Approximately(left.y, right.y)
&& Mathf.Approximately(left.z, right.z);
}
public class Qux
{
public static bool WasInjected
{
get;
set;
}
[Inject]
public void Construct()
{
WasInjected = true;
}
}
GameObject GetPrefab(string name)
{
return FixtureUtil.GetPrefab(ResourcePrefix + name);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 03827fc575424954ba63c60d88fdd289
timeCreated: 1506426682
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 3da0ff226e0beea4d91bdef5be3cc543
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,138 @@
using System;
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromComponentOn : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestBasic()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
Container.Bind<Foo>().FromComponentOn(gameObject).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(Container.Resolve<Foo>());
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestBasicMultiple()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
gameObject.AddComponent<Foo>();
Container.Bind<Foo>().FromComponentsOn(gameObject).AsCached().NonLazy();
PostInstall();
Assert.IsEqual(Container.ResolveAll<Foo>().Count, 2);
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestBasicByMethod()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
Container.Bind<Foo>().FromComponentOn(context => gameObject).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(Container.Resolve<Foo>());
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestBasicByMethodMultiple()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
gameObject.AddComponent<Foo>();
Container.Bind<Foo>().FromComponentsOn(context => gameObject).AsCached().NonLazy();
PostInstall();
Assert.IsEqual(Container.ResolveAll<Foo>().Count, 2);
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>().FromComponentOn(gameObject).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(Container.Resolve<Foo>());
Assert.IsNotNull(Container.Resolve<IFoo>());
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestCachedMultipleConcrete()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
gameObject.AddComponent<Foo>();
gameObject.AddComponent<Bar>();
Container.Bind(typeof(IFoo), typeof(IBar))
.To(new List<Type> { typeof(Foo), typeof(Bar) })
.FromComponentOn(gameObject).AsCached().NonLazy();
PostInstall();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count, 2);
Assert.IsEqual(Container.ResolveAll<IBar>().Count, 2);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
public interface IBar
{
}
public interface IFoo2
{
}
public interface IFoo
{
}
public class Foo : MonoBehaviour, IFoo, IBar, IFoo2
{
}
public class Bar : MonoBehaviour, IFoo, IBar, IFoo2
{
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 69fc44fa2e9354d409863d794494198f
timeCreated: 1529229722
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,152 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromNewComponentOn : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestBasic()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind<Foo>().FromNewComponentOn(gameObject).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestBasicByMethod()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind<Foo>().FromNewComponentOn(context => gameObject).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind<Foo>().FromNewComponentOn(gameObject).AsTransient().NonLazy();
Container.Bind<IFoo>().To<Foo>().FromNewComponentOn(gameObject).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>().FromNewComponentOn(gameObject).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestCached1()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind<Foo>().FromNewComponentOn(gameObject).AsCached().NonLazy();
Container.Bind<IFoo>().To<Foo>().FromNewComponentOn(gameObject).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestCached2()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>()
.FromNewComponentOn(gameObject).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestCachedMultipleConcrete()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Foo");
Container.BindInstance(gameObject).WithId("Foo");
Container.Bind(typeof(IFoo), typeof(IBar))
.To(new List<Type> { typeof(Foo), typeof(Bar) })
.FromNewComponentOn(gameObject).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
public interface IBar
{
}
public interface IFoo2
{
}
public interface IFoo
{
}
public class Foo : MonoBehaviour, IFoo, IBar, IFoo2
{
}
public class Bar : MonoBehaviour, IFoo, IBar, IFoo2
{
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 4d448c0958b131e4487e3e814771e282
timeCreated: 1529229722
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b28f74c42a00cce4c966429fc9bf3304
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,229 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromComponentInChildren : ZenjectIntegrationTestFixture
{
Root _root;
Child _child1;
Child _child2;
Grandchild _grandchild;
public void Setup1()
{
_root = new GameObject("root").AddComponent<Root>();
_child1 = new GameObject("child1").AddComponent<Child>();
_child1.transform.SetParent(_root.transform);
_child2 = new GameObject("child2").AddComponent<Child>();
_child2.transform.SetParent(_root.transform);
_grandchild = new GameObject("grandchild").AddComponent<Grandchild>();
_grandchild.transform.SetParent(_child1.transform);
}
[UnityTest]
public IEnumerator RunMatchSingleChild()
{
Setup1();
PreInstall();
Container.Bind<Grandchild>().FromComponentInChildren();
Container.Bind<Child>().FromComponentInChildren();
PostInstall();
Assert.IsEqual(_root.Grandchild, _grandchild);
Assert.IsEqual(_root.Childs.Count, 1);
Assert.IsEqual(_root.Childs[0], _child1);
yield break;
}
[UnityTest]
public IEnumerator RunMatchAllChildren()
{
Setup1();
PreInstall();
Container.Bind<Grandchild>().FromComponentInChildren();
Container.Bind<Child>().FromComponentsInChildren();
PostInstall();
Assert.IsEqual(_root.Grandchild, _grandchild);
Assert.IsEqual(_root.Childs.Count, 2);
Assert.IsEqual(_root.Childs[0], _child1);
Assert.IsEqual(_root.Childs[1], _child2);
yield break;
}
[UnityTest]
public IEnumerator RunMissingChildrenFailure()
{
new GameObject("root").AddComponent<Root>();
PreInstall();
Container.Bind<Grandchild>().FromComponentInChildren();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMissingChildrenSuccess()
{
var root = new GameObject("root").AddComponent<Root>();
var grandchild = new GameObject("grandchild").AddComponent<Grandchild>();
grandchild.transform.SetParent(root.transform);
PreInstall();
Container.Bind<Grandchild>().FromComponentInChildren();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestOptional()
{
var root = new GameObject("root").AddComponent<RootWithOptional>();
PreInstall();
Container.Bind<Child>().FromComponentInChildren();
PostInstall();
Assert.IsNull(root.Child);
yield break;
}
[UnityTest]
public IEnumerator TestOptional2()
{
var root = new GameObject("root").AddComponent<Root>();
var grandChild = new GameObject("grandchild").AddComponent<Grandchild>();
grandChild.transform.SetParent(root.transform, false);
PreInstall();
Container.Bind<Grandchild>().FromComponentsInChildren();
Container.Bind<Child>().FromComponentInChildren();
PostInstall();
// The FromComponentInChildren call should match nothing when optional like in
// list bindings
Assert.That(root.Childs.IsEmpty());
yield break;
}
[UnityTest]
public IEnumerator RunMatchSingleChildNonGeneric()
{
Setup1();
PreInstall();
Container.Bind(typeof(Grandchild)).FromComponentInChildren();
Container.Bind(typeof(Child)).FromComponentInChildren();
PostInstall();
Assert.IsEqual(_root.Grandchild, _grandchild);
Assert.IsEqual(_root.Childs.Count, 1);
Assert.IsEqual(_root.Childs[0], _child1);
yield break;
}
[UnityTest]
public IEnumerator RunMatchAllChildrenNonGeneric()
{
Setup1();
PreInstall();
Container.Bind(typeof(Grandchild)).FromComponentInChildren();
Container.Bind<Child>().FromComponentsInChildren();
PostInstall();
Assert.IsEqual(_root.Grandchild, _grandchild);
Assert.IsEqual(_root.Childs.Count, 2);
Assert.IsEqual(_root.Childs[0], _child1);
Assert.IsEqual(_root.Childs[1], _child2);
yield break;
}
[UnityTest]
public IEnumerator RunMissingChildrenFailureNonGeneric()
{
new GameObject("root").AddComponent<Root>();
PreInstall();
Container.Bind(typeof(Grandchild)).FromComponentInChildren();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMissingChildrenSuccessNonGeneric()
{
var root = new GameObject("root").AddComponent<Root>();
var grandchild = new GameObject("grandchild").AddComponent<Grandchild>();
grandchild.transform.SetParent(root.transform);
PreInstall();
Container.Bind(typeof(Grandchild)).FromComponentInChildren();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestOptionalNonGeneric()
{
var root = new GameObject("root").AddComponent<RootWithOptional>();
PreInstall();
Container.Bind(typeof(Child)).FromComponentInChildren();
PostInstall();
Assert.IsNull(root.Child);
yield break;
}
public class Root : MonoBehaviour
{
[Inject]
public Grandchild Grandchild;
[Inject]
public List<Child> Childs;
}
public class Child : MonoBehaviour
{
}
public class Grandchild : MonoBehaviour
{
}
public class RootWithOptional : MonoBehaviour
{
[InjectOptional]
public Child Child;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 60e4db58b41116646b1675963b1c75a1
timeCreated: 1485741160
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 703bae5899505584ea4bd2f89e7c5686
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,213 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromComponentInHierarchy : ZenjectIntegrationTestFixture
{
Foo _foo1;
Foo _foo2;
public void Setup1()
{
var root = new GameObject();
_foo1 = root.AddComponent<Foo>();
var child1 = new GameObject();
child1.transform.SetParent(root.transform);
var child2 = new GameObject();
child2.transform.SetParent(root.transform);
_foo2 = child2.AddComponent<Foo>();
}
public void Setup2()
{
var root = new GameObject();
var child1 = new GameObject();
child1.transform.SetParent(root.transform);
}
[UnityTest]
public IEnumerator RunMatchSingle()
{
Setup1();
PreInstall();
Container.Bind<Qux>().AsSingle();
Container.Bind<Foo>().FromComponentInHierarchy().AsSingle();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 1);
Assert.IsEqual(qux.Foos[0], _foo1);
yield break;
}
[UnityTest]
public IEnumerator RunMatchMultiple()
{
Setup1();
PreInstall();
Container.Bind<Qux>().AsSingle();
Container.Bind<Foo>().FromComponentsInHierarchy().AsCached();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 2);
Assert.IsEqual(qux.Foos[0], _foo1);
Assert.IsEqual(qux.Foos[1], _foo2);
yield break;
}
[UnityTest]
public IEnumerator RunMatchNotFoundFailure()
{
Setup2();
PreInstall();
Container.Bind<Bar>().AsSingle().NonLazy();
Container.Bind<Foo>().FromComponentInHierarchy().AsSingle();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMatchNotFoundSuccess()
{
Setup2();
PreInstall();
Container.Bind<Qux>().AsSingle().NonLazy();
Container.Bind<Foo>().FromComponentsInHierarchy().AsCached();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 0);
yield break;
}
[UnityTest]
public IEnumerator TestOptional()
{
PreInstall();
Container.Bind<Qiv>().AsSingle().NonLazy();
Container.Bind<Foo>().FromComponentInHierarchy().AsSingle();
PostInstall();
var qiv = Container.Resolve<Qiv>();
Assert.IsNull(qiv.Foo);
yield break;
}
[UnityTest]
public IEnumerator RunMatchSingleNonGeneric()
{
Setup1();
PreInstall();
Container.Bind<Qux>().AsSingle();
Container.Bind(typeof(Foo)).FromComponentInHierarchy().AsSingle();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 1);
Assert.IsEqual(qux.Foos[0], _foo1);
yield break;
}
[UnityTest]
public IEnumerator RunMatchMultipleNonGeneric()
{
Setup1();
PreInstall();
Container.Bind<Qux>().AsSingle();
Container.Bind(typeof(Foo)).FromComponentsInHierarchy().AsCached();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 2);
Assert.IsEqual(qux.Foos[0], _foo1);
Assert.IsEqual(qux.Foos[1], _foo2);
yield break;
}
[UnityTest]
public IEnumerator RunMatchNotFoundFailureNonGeneric()
{
Setup2();
PreInstall();
Container.Bind<Bar>().AsSingle().NonLazy();
Container.Bind(typeof(Foo)).FromComponentInHierarchy().AsSingle();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMatchNotFoundSuccessNonGeneric()
{
Setup2();
PreInstall();
Container.Bind<Qux>().AsSingle().NonLazy();
Container.Bind(typeof(Foo)).FromComponentsInHierarchy().AsCached();
PostInstall();
var qux = Container.Resolve<Qux>();
Assert.IsEqual(qux.Foos.Count, 0);
yield break;
}
[UnityTest]
public IEnumerator TestOptionalNonGeneric()
{
PreInstall();
Container.Bind<Qiv>().AsSingle().NonLazy();
Container.Bind(typeof(Foo)).FromComponentInHierarchy().AsSingle();
PostInstall();
var qiv = Container.Resolve<Qiv>();
Assert.IsNull(qiv.Foo);
yield break;
}
public class Foo : MonoBehaviour
{
}
public class Qux
{
[Inject]
public List<Foo> Foos;
}
public class Bar
{
[Inject]
public Foo Foo;
}
public class Qiv
{
[InjectOptional]
public Foo Foo;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 33f32e2013960314f841932f66d9b92c
timeCreated: 1485743323
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b4dba59ca52fc08499490254c3940f59
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,46 @@
using System.Collections;
using System.Linq;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Bindings.FromComponentInHierarchyGameObjectContext
{
public class TestFromComponentInHierarchyGameObjectContext : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get
{
return FixtureUtil.GetPrefab("TestFromComponentInHierarchyGameObjectContext/Foo");
}
}
[SetUp]
public void SetUp()
{
new GameObject().AddComponent<Gorp>();
new GameObject().AddComponent<Gorp>();
}
[UnityTest]
public IEnumerator TestCorrectHierarchy()
{
PreInstall();
Container.Bind<Foo>().FromSubContainerResolve()
.ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsNotNull(foo.Gorp);
Assert.IsEqual(foo.gameObject.GetComponentsInChildren<Gorp>().Single(), foo.Gorp);
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e4a3a41ae23a4bb44b068790d065e7e4
timeCreated: 1485743325
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b12b2bde79e96504980df2b05b948e89
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,237 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromComponentInParents : ZenjectIntegrationTestFixture
{
Root _root;
Child _child1;
Child _child2;
Child _child3;
Grandchild _grandchild;
public void Setup1()
{
_root = new GameObject().AddComponent<Root>();
_child1 = new GameObject().AddComponent<Child>();
_child1.transform.SetParent(_root.transform);
_child2 = new GameObject().AddComponent<Child>();
_child2.transform.SetParent(_child1.transform);
_child3 = _child2.gameObject.AddComponent<Child>();
_grandchild = new GameObject().AddComponent<Grandchild>();
_grandchild.transform.SetParent(_child2.transform);
}
public void Setup2()
{
_root = new GameObject().AddComponent<Root>();
_grandchild = new GameObject().AddComponent<Grandchild>();
_grandchild.transform.SetParent(_root.transform);
}
[UnityTest]
public IEnumerator RunMatchSingleParent()
{
Setup1();
PreInstall();
Container.Bind<Root>().FromComponentInParents();
Container.Bind<Child>().FromComponentInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 1);
Assert.IsEqual(_grandchild.Childs[0], _child2);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator RunMatchMultipleParents()
{
Setup1();
PreInstall();
Container.Bind<Root>().FromComponentInParents();
Container.Bind<Child>().FromComponentsInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 3);
Assert.IsEqual(_grandchild.Childs[0], _child2);
Assert.IsEqual(_grandchild.Childs[1], _child3);
Assert.IsEqual(_grandchild.Childs[2], _child1);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator RunMissingParentFailure()
{
var root = new GameObject().AddComponent<Root>();
var grandchild = new GameObject().AddComponent<Grandchild2>();
grandchild.transform.SetParent(root.transform);
PreInstall();
Container.Bind<Root>().FromComponentInParents();
Container.Bind<Child>().FromComponentInParents();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMissingParentSuccess()
{
Setup2();
PreInstall();
Container.Bind<Root>().FromComponentInParents();
Container.Bind<Child>().FromComponentsInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 0);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator TestOptional()
{
new GameObject();
var child = new GameObject().AddComponent<ChildWithOptional>();
PreInstall();
Container.Bind<Root>().FromComponentInParents();
PostInstall();
Assert.IsNull(child.Root);
yield break;
}
[UnityTest]
public IEnumerator RunMatchSingleParentNonGeneric()
{
Setup1();
PreInstall();
Container.Bind(typeof(Root)).FromComponentInParents();
Container.Bind(typeof(Child)).FromComponentInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 1);
Assert.IsEqual(_grandchild.Childs[0], _child2);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator RunMatchMultipleParentsNonGeneric()
{
Setup1();
PreInstall();
Container.Bind(typeof(Root)).FromComponentInParents();
Container.Bind(typeof(Child)).FromComponentsInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 3);
Assert.IsEqual(_grandchild.Childs[0], _child2);
Assert.IsEqual(_grandchild.Childs[1], _child3);
Assert.IsEqual(_grandchild.Childs[2], _child1);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator RunMissingParentFailureNonGeneric()
{
var root = new GameObject().AddComponent<Root>();
var grandchild = new GameObject().AddComponent<Grandchild2>();
grandchild.transform.SetParent(root.transform);
PreInstall();
Container.Bind(typeof(Root)).FromComponentInParents();
Container.Bind(typeof(Child)).FromComponentInParents();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunMissingParentSuccessNonGeneric()
{
Setup2();
PreInstall();
Container.Bind(typeof(Root)).FromComponentInParents();
Container.Bind(typeof(Child)).FromComponentsInParents();
PostInstall();
Assert.IsEqual(_grandchild.Childs.Count, 0);
Assert.IsEqual(_grandchild.Root, _root);
yield break;
}
[UnityTest]
public IEnumerator TestOptionalNonGeneric()
{
new GameObject();
var child = new GameObject().AddComponent<ChildWithOptional>();
PreInstall();
Container.Bind(typeof(Root)).FromComponentInParents();
PostInstall();
Assert.IsNull(child.Root);
yield break;
}
public class Root : MonoBehaviour
{
}
public class Child : MonoBehaviour
{
}
public class Grandchild : MonoBehaviour
{
[Inject]
public Root Root;
[Inject]
public List<Child> Childs;
}
public class Grandchild2 : MonoBehaviour
{
[Inject]
public Root Root;
[Inject]
public Child Child;
}
public class ChildWithOptional : MonoBehaviour
{
[InjectOptional]
public Root Root;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9df118a8d9c898344bed28c6913a6d7e
timeCreated: 1485741161
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1f10443fc834f9f4cbd6ce1fd5bce4a3
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,244 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromComponentSibling : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator RunTestSingleMatch()
{
var foo = new GameObject().AddComponent<Foo>();
var bar = foo.gameObject.AddComponent<Bar>();
var qux1 = foo.gameObject.AddComponent<Qux>();
foo.gameObject.AddComponent<Qux>();
PreInstall();
Container.Bind<Qux>().FromComponentSibling();
Container.Bind<Bar>().FromComponentSibling();
Container.Bind<IBar>().FromComponentSibling();
PostInstall();
Assert.IsEqual(foo.Bar, bar);
Assert.IsEqual(foo.IBar, bar);
Assert.IsEqual(foo.Qux.Count, 1);
Assert.IsEqual(foo.Qux[0], qux1);
Assert.IsEqual(qux1.OtherQux, qux1);
yield break;
}
[UnityTest]
public IEnumerator RunTestSingleMatchOptional1()
{
var foo = new GameObject().AddComponent<FooOptional>();
PreInstall();
Container.Bind<Bar>().FromComponentSibling();
PostInstall();
Assert.IsNull(foo.Bar);
yield break;
}
[UnityTest]
public IEnumerator RunTestSingleMatchOptional2()
{
var foo = new GameObject().AddComponent<FooOptional>();
var bar = foo.gameObject.AddComponent<Bar>();
PreInstall();
Container.Bind<Bar>().FromComponentSibling();
PostInstall();
Assert.IsEqual(foo.Bar, bar);
yield break;
}
[UnityTest]
public IEnumerator RunTestSingleMatchOptional3()
{
new GameObject().AddComponent<FooOptional2>();
PreInstall();
Container.Bind<Bar>().FromComponentSibling();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunTestMultiple()
{
var foo = new GameObject().AddComponent<Foo>();
var bar = foo.gameObject.AddComponent<Bar>();
var qux1 = foo.gameObject.AddComponent<Qux>();
var qux2 = foo.gameObject.AddComponent<Qux>();
PreInstall();
Container.Bind<Qux>().FromComponentsSibling();
Container.Bind<Bar>().FromComponentSibling();
Container.Bind<IBar>().FromComponentSibling();
PostInstall();
Assert.IsEqual(foo.Bar, bar);
Assert.IsEqual(foo.IBar, bar);
Assert.IsEqual(foo.Qux[0], qux1);
Assert.IsEqual(foo.Qux[1], qux2);
// Should skip self
Assert.IsEqual(foo.Qux[0].OtherQux, foo.Qux[1]);
Assert.IsEqual(foo.Qux[1].OtherQux, foo.Qux[0]);
yield break;
}
[UnityTest]
public IEnumerator RunTestMissingFailure()
{
new GameObject().AddComponent<Gorp>();
PreInstall();
Container.Bind<Bar>().FromComponentSibling();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunTestMissingSuccess()
{
var foo = new GameObject().AddComponent<Foo>();
foo.gameObject.AddComponent<Bar>();
PreInstall();
Container.Bind<Qux>().FromComponentsSibling();
Container.Bind<Bar>().FromComponentSibling();
Container.Bind<IBar>().FromComponentSibling();
PostInstall();
Assert.That(foo.Qux.IsEmpty());
yield break;
}
[UnityTest]
public IEnumerator RunTestMultipleNonGeneric()
{
var foo = new GameObject().AddComponent<Foo>();
var bar = foo.gameObject.AddComponent<Bar>();
var qux1 = foo.gameObject.AddComponent<Qux>();
var qux2 = foo.gameObject.AddComponent<Qux>();
PreInstall();
Container.Bind(typeof(Qux)).FromComponentsSibling();
Container.Bind(typeof(Bar)).FromComponentSibling();
Container.Bind(typeof(IBar)).FromComponentSibling();
PostInstall();
Assert.IsEqual(foo.Bar, bar);
Assert.IsEqual(foo.IBar, bar);
Assert.IsEqual(foo.Qux[0], qux1);
Assert.IsEqual(foo.Qux[1], qux2);
// Should skip self
Assert.IsEqual(foo.Qux[0].OtherQux, foo.Qux[1]);
Assert.IsEqual(foo.Qux[1].OtherQux, foo.Qux[0]);
yield break;
}
[UnityTest]
public IEnumerator RunTestMissingFailureNonGeneric()
{
new GameObject().AddComponent<Gorp>();
PreInstall();
Container.Bind(typeof(Bar)).FromComponentSibling();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator RunTestMissingSuccessNonGeneric()
{
var foo = new GameObject().AddComponent<Foo>();
foo.gameObject.AddComponent<Bar>();
PreInstall();
Container.Bind(typeof(Qux)).FromComponentsSibling();
Container.Bind(typeof(Bar)).FromComponentSibling();
Container.Bind(typeof(IBar)).FromComponentSibling();
PostInstall();
Assert.That(foo.Qux.IsEmpty());
yield break;
}
public class Qux : MonoBehaviour
{
[Inject]
public Qux OtherQux;
}
public interface IBar
{
}
public class Bar : MonoBehaviour, IBar
{
}
public class FooOptional : MonoBehaviour
{
[InjectOptional]
public Bar Bar;
}
public class FooOptional2 : MonoBehaviour
{
[Inject]
public Bar Bar;
}
public class Foo : MonoBehaviour
{
[Inject]
public Bar Bar;
[Inject]
public IBar IBar;
[Inject]
public List<Qux> Qux;
}
public class Gorp : MonoBehaviour
{
[Inject]
public Bar Bar;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b0d37dd020d97b3459f64a7f3434ff96
timeCreated: 1485741161
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9116904793056a445abaca59d9fd9c91
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,207 @@
using System;
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromGameObject : ZenjectIntegrationTestFixture
{
const string GameObjName = "TestObj";
[UnityTest]
public IEnumerator TestBasic()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>().FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsTransient().NonLazy();
Container.Bind<IFoo>().To<Foo>().FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestCached1()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsCached().NonLazy();
Container.Bind<IFoo>().To<Foo>().FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestCached2()
{
PreInstall();
Container.Bind(typeof(Foo), typeof(IFoo)).To<Foo>()
.FromNewComponentOnNewGameObject().WithGameObjectName(GameObjName).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleConcreteTransient1()
{
PreInstall();
Container.Bind<IFoo>().To(typeof(Foo), typeof(Bar)).FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleConcreteTransient2()
{
PreInstall();
Container.Bind(typeof(IFoo), typeof(IBar)).To(new List<Type> {typeof(Foo), typeof(Bar)}).FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(4);
FixtureUtil.AssertComponentCount<Foo>(2);
FixtureUtil.AssertComponentCount<Bar>(2);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleConcreteCached()
{
PreInstall();
Container.Bind(typeof(IFoo), typeof(IBar)).To(new List<Type> {typeof(Foo), typeof(Bar)}).FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleConcreteSingle()
{
PreInstall();
Container.Bind(typeof(IFoo), typeof(IBar)).To(new List<Type> {typeof(Foo), typeof(Bar)}).FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransformGroup()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName).UnderTransformGroup("Foo").AsSingle().NonLazy();
PostInstall();
var foo = GameObject.Find("Foo").transform.GetChild(0);
Assert.IsNotNull(foo.GetComponent<Foo>());
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransform()
{
PreInstall();
var tempGameObject = new GameObject("Foo");
Container.Bind<Foo>().FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName)
.UnderTransform(tempGameObject.transform).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(tempGameObject.transform.GetChild(0).GetComponent<Foo>());
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransformGetter()
{
PreInstall();
var tempGameObject = new GameObject("Foo");
Container.Bind<Foo>().FromNewComponentOnNewGameObject()
.WithGameObjectName(GameObjName)
.UnderTransform(context => tempGameObject.transform).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(tempGameObject.transform.GetChild(0).GetComponent<Foo>());
yield break;
}
public interface IBar
{
}
public interface IFoo
{
}
public class Foo : MonoBehaviour, IFoo, IBar
{
}
public class Bar : MonoBehaviour, IFoo, IBar
{
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e879b4e0ab309f247a1efc11a7a71bba
timeCreated: 1476623361
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 7bad27777f963f244b6475fdd2f56155
folderAsset: yes
timeCreated: 1538468409
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,59 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings.FromGameObjectInstaller
{
public class TestFromGameObjectInstaller : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestInstaller()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewGameObjectInstaller<FooInstaller>().AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestMethod()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewGameObjectMethod(InstallFoo).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
void InstallFoo(DiContainer subContainer)
{
subContainer.Bind<Qux>().AsSingle().WithArguments("asdf");
}
public class Qux
{
[Inject]
public string Data;
}
public class FooInstaller : Installer<FooInstaller>
{
public override void InstallBindings()
{
Container.Bind<Qux>().AsSingle().WithArguments("asdf");
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: c0dfdf55fcc548d47b0b804800f9c7e5
timeCreated: 1538468409
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 1584905eb3a75484099619f9e66362b1
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,101 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.FromNewScriptableObjectResource;
namespace Zenject.Tests.Bindings
{
public class TestFromNewScriptableObjectResource : ZenjectIntegrationTestFixture
{
const string PathPrefix = "TestFromNewScriptableObjectResource/";
[UnityTest]
public IEnumerator TestTransientError()
{
PreInstall();
// Validation should detect that it doesn't exist
Container.Bind<Foo>().FromNewScriptableObjectResource(PathPrefix + "asdfasdfas").AsTransient().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
Foo.InstanceCount = 0;
Container.Bind<Foo>().FromNewScriptableObjectResource(PathPrefix + "Foo").AsTransient();
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.That(foo.WasInjected);
Assert.IsEqual(Foo.InstanceCount, 1);
var foo2 = Container.Resolve<Foo>();
Assert.IsNotEqual(foo, foo2);
Assert.IsEqual(Foo.InstanceCount, 2);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
Foo.InstanceCount = 0;
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>().FromNewScriptableObjectResource(PathPrefix + "Foo").AsSingle();
PostInstall();
Container.Resolve<IFoo>();
Assert.IsEqual(Foo.InstanceCount, 1);
yield break;
}
[UnityTest]
public IEnumerator TestAbstractBinding()
{
PreInstall();
Foo.InstanceCount = 0;
Container.Bind<IFoo>().To<Foo>()
.FromNewScriptableObjectResource(PathPrefix + "Foo").AsSingle().NonLazy();
PostInstall();
Container.Resolve<IFoo>();
Assert.IsEqual(Foo.InstanceCount, 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithArgumentsFail()
{
PreInstall();
Container.Bind<Bob>()
.FromNewScriptableObjectResource(PathPrefix + "Bob").AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestWithArguments()
{
PreInstall();
Container.Bind<Bob>()
.FromNewScriptableObjectResource(PathPrefix + "Bob").AsSingle()
.WithArguments("test1").NonLazy();
PostInstall();
Assert.IsEqual(Container.Resolve<Bob>().Arg, "test1");
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 524c1ea1726f5b24e99d297bf3bab1b3
timeCreated: 1487537569
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d3728543fde13364396f833fea981d45
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,222 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.FromPrefab;
namespace Zenject.Tests.Bindings
{
public class TestFromPrefab : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get { return GetPrefab("Foo"); }
}
GameObject GorpPrefab
{
get { return GetPrefab("Gorp"); }
}
GameObject GorpAndQuxPrefab
{
get { return GetPrefab("GorpAndQux"); }
}
GameObject NorfPrefab
{
get { return GetPrefab("Norf"); }
}
GameObject JimAndBobPrefab
{
get { return GetPrefab("JimAndBob"); }
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
Container.Bind<Foo>().FromComponentInNewPrefab(FooPrefab).AsTransient().NonLazy();
Container.Bind<Foo>().FromComponentInNewPrefab(FooPrefab).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
Container.Bind(typeof(IFoo), typeof(Foo)).To<Foo>().FromComponentInNewPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
Assert.IsNotNull(Container.Resolve<IFoo>());
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestCached1()
{
PreInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromComponentInNewPrefab(FooPrefab)
.WithGameObjectName("Foo").AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
FixtureUtil.AssertNumGameObjectsWithName("Foo", 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithArgumentsFail()
{
PreInstall();
// They have required arguments
Container.Bind(typeof(Gorp), typeof(Qux)).FromComponentInNewPrefab(GorpAndQuxPrefab).AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestWithArgumentsFail2()
{
PreInstall();
Container.Bind<Gorp>()
.FromComponentInNewPrefab(GorpAndQuxPrefab).WithGameObjectName("Gorp").AsSingle()
.WithArguments(5, "test1").NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestWithArgumentsSuccess()
{
PreInstall();
Container.Bind<Gorp>().FromComponentInNewPrefab(GorpPrefab)
.WithGameObjectName("Gorp").AsSingle()
.WithArguments("test1").NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Gorp>(1);
FixtureUtil.AssertNumGameObjectsWithName("Gorp", 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithAbstractSearchSingleMatch()
{
PreInstall();
// There are three components that implement INorf on this prefab
Container.Bind<INorf>().FromComponentInNewPrefab(NorfPrefab).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<INorf>(3);
FixtureUtil.AssertResolveCount<INorf>(Container, 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithAbstractSearchMultipleMatch()
{
PreInstall();
// There are three components that implement INorf on this prefab
Container.Bind<INorf>().FromComponentsInNewPrefab(NorfPrefab).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<INorf>(3);
FixtureUtil.AssertResolveCount<INorf>(Container, 3);
yield break;
}
[UnityTest]
public IEnumerator TestAbstractBindingConcreteSearch()
{
PreInstall();
// Should ignore the Norf2 component on it
Container.Bind<INorf>().To<Norf>().FromComponentsInNewPrefab(NorfPrefab).AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertResolveCount<INorf>(Container, 2);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleMatchFailure()
{
PreInstall();
Container.Bind<INorf>().FromComponentsInNewPrefab(FooPrefab).AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestMultipleMatchTransform()
{
PreInstall();
Container.Bind<Transform>().FromComponentInNewPrefab(FooPrefab).AsCached();
PostInstall();
var transform = Container.Resolve<Transform>();
Assert.IsNotNull(transform);
Assert.IsNull(transform.parent);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestCircularDependencies()
{
PreInstall();
// Jim and Bob both depend on each other
Container.Bind(typeof(Jim), typeof(Bob)).FromComponentInNewPrefab(JimAndBobPrefab).AsSingle().NonLazy();
Container.BindInterfacesTo<JimAndBobRunner>().AsSingle().NonLazy();
PostInstall();
yield break;
}
GameObject GetPrefab(string name)
{
return FixtureUtil.GetPrefab("TestFromPrefab/{0}".Fmt(name));
}
public class JimAndBobRunner : IInitializable
{
readonly Bob _bob;
readonly Jim _jim;
public JimAndBobRunner(Jim jim, Bob bob)
{
_bob = bob;
_jim = jim;
}
public void Initialize()
{
Assert.IsNotNull(_jim.Bob);
Assert.IsNotNull(_bob.Jim);
Log.Info("Jim and bob successfully got the other reference");
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9a11ff4a9421f2949993c4dc34f50335
timeCreated: 1454819941
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 004fb639c2306474c8f8825720e5a9d2
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,128 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings.FromPrefabInstaller
{
public class TestFromPrefabInstaller : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get { return FixtureUtil.GetPrefab(FooPrefabResourcePath); }
}
string FooPrefabResourcePath
{
get { return "TestFromPrefabInstaller/Foo"; }
}
[UnityTest]
public IEnumerator TestInstaller()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabInstaller<FooInstaller>(FooPrefab).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestInstallerGetter()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabInstaller<FooInstaller>(_ => FooPrefab).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestMethod()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabMethod(FooPrefab, InstallFoo).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestMethodGetter()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabMethod((context) => FooPrefab, InstallFoo).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestResourceInstaller()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabResourceInstaller<FooInstaller>(FooPrefabResourcePath).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestResourceMethod()
{
PreInstall();
Container.Bind<Qux>().FromSubContainerResolve()
.ByNewPrefabResourceMethod(FooPrefabResourcePath, InstallFoo).AsCached();
PostInstall();
Assert.IsEqual(Container.Resolve<Qux>().Data, "asdf");
yield break;
}
void InstallFoo(DiContainer subContainer)
{
subContainer.Bind<Qux>().AsSingle().WithArguments("asdf");
}
public class Qux
{
[Inject]
public string Data;
[Inject]
public Foo Foo;
}
public class FooInstaller : Installer<FooInstaller>
{
public override void InstallBindings()
{
Container.Bind<Qux>().AsSingle().WithArguments("asdf");
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 6591427867291174ba958928b193a190
timeCreated: 1528215846
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ab61730ee27e0954db743cf10ae967bd
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,179 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.FromPrefabResource;
namespace Zenject.Tests.Bindings
{
public class TestFromPrefabResource : ZenjectIntegrationTestFixture
{
const string PathPrefix = "TestFromPrefabResource/";
[UnityTest]
public IEnumerator TestTransientError()
{
PreInstall();
// Validation should detect that it doesn't exist
Container.Bind<Foo>().FromComponentInNewPrefabResource(PathPrefix + "asdfasdfas").AsTransient().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
Container.Bind<Foo>().FromComponentInNewPrefabResource(PathPrefix + "Foo").AsTransient().NonLazy();
Container.Bind<Foo>().FromComponentInNewPrefabResource(PathPrefix + "Foo").AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(2);
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
Container.Bind(typeof(Foo), typeof(IFoo)).To<Foo>().FromComponentInNewPrefabResource(PathPrefix + "Foo").AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestCached1()
{
PreInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromComponentInNewPrefabResource(PathPrefix + "Foo")
.WithGameObjectName("Foo").AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
FixtureUtil.AssertNumGameObjectsWithName("Foo", 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithArgumentsFail()
{
PreInstall();
// They have required arguments
Container.Bind(typeof(Gorp), typeof(Qux)).FromComponentInNewPrefabResource(PathPrefix + "GorpAndQux").AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestWithArguments()
{
PreInstall();
Container.Bind(typeof(Gorp))
.FromComponentInNewPrefabResource(PathPrefix + "Gorp").WithGameObjectName("Gorp").AsSingle()
.WithArguments("test1").NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Gorp>(1);
FixtureUtil.AssertNumGameObjectsWithName("Gorp", 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithAbstractSearchSingleMatch()
{
PreInstall();
// There are three components that implement INorf on this prefab
Container.Bind<INorf>().FromComponentInNewPrefabResource(PathPrefix + "Norf").AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<INorf>(3);
FixtureUtil.AssertResolveCount<INorf>(Container, 1);
yield break;
}
[UnityTest]
public IEnumerator TestWithAbstractSearchMultipleMatch()
{
PreInstall();
// There are three components that implement INorf on this prefab
Container.Bind<INorf>().FromComponentsInNewPrefabResource(PathPrefix + "Norf").AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<INorf>(3);
FixtureUtil.AssertResolveCount<INorf>(Container, 3);
yield break;
}
[UnityTest]
public IEnumerator TestAbstractBindingConcreteSearch()
{
PreInstall();
// Should ignore the Norf2 component on it
Container.Bind<INorf>().To<Norf>().FromComponentsInNewPrefabResource(PathPrefix + "Norf").AsCached().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertResolveCount<INorf>(Container, 2);
yield break;
}
[UnityTest]
public IEnumerator TestMultipleMatchFailure()
{
PreInstall();
Container.Bind<INorf>().FromComponentsInNewPrefabResource(PathPrefix + "Foo").AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestCircularDependencies()
{
PreInstall();
// Jim and Bob both depend on each other
Container.Bind(typeof(Jim), typeof(Bob)).FromComponentInNewPrefabResource(PathPrefix + "JimAndBob").AsSingle().NonLazy();
Container.BindInterfacesTo<JimAndBobRunner>().AsSingle().NonLazy();
PostInstall();
yield break;
}
public class JimAndBobRunner : IInitializable
{
readonly Bob _bob;
readonly Jim _jim;
public JimAndBobRunner(Jim jim, Bob bob)
{
_bob = bob;
_jim = jim;
}
public void Initialize()
{
Assert.IsNotNull(_jim.Bob);
Assert.IsNotNull(_bob.Jim);
Log.Info("Jim and bob successfully got the other reference");
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 100b8c53531c9e049bd6ac742c979248
timeCreated: 1476625195
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 77895b2c18397dd4eb7b086f557cfaa1
folderAsset: yes
timeCreated: 1533537470
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,106 @@
using System.Collections;
using System.Collections.Generic;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromResource : ZenjectIntegrationTestFixture
{
const string ResourcePath = "TestFromResource/TestTexture";
const string ResourcePath2 = "TestFromResource/TestTexture2";
[UnityTest]
public IEnumerator TestBasic()
{
PreInstall();
Container.Bind<Texture>().FromResource(ResourcePath);
Container.Bind<Runner>().FromNewComponentOnNewGameObject().AsSingle().WithArguments(1).NonLazy();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestTransient()
{
PreInstall();
Container.Bind<Texture>().FromResource(ResourcePath).AsTransient();
Container.Bind<Texture>().FromResource(ResourcePath);
Container.Bind<Texture>().To<Texture>().FromResource(ResourcePath);
Container.Bind<Runner>().FromNewComponentOnNewGameObject().AsSingle().WithArguments(3).NonLazy();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestCached()
{
PreInstall();
Container.Bind<Texture>().FromResource(ResourcePath).AsSingle();
Container.Bind<Runner>().FromNewComponentOnNewGameObject().AsSingle().WithArguments(1).NonLazy();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestSingle()
{
PreInstall();
Container.Bind(typeof(Texture), typeof(Texture)).To<Texture>().FromResource(ResourcePath).AsSingle();
Container.Bind<Runner>().FromNewComponentOnNewGameObject().AsSingle().WithArguments(2).NonLazy();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestSingleWithError()
{
PreInstall();
Container.Bind<Texture>().FromResource(ResourcePath).AsSingle();
Container.Bind<Texture>().FromResource(ResourcePath2).AsSingle();
Assert.Throws(() => Container.FlushBindings());
PostInstall();
yield break;
}
public class Runner : MonoBehaviour
{
List<Texture> _textures;
[Inject]
public void Construct(List<Texture> textures, int expectedAmount)
{
_textures = textures;
Assert.IsEqual(textures.Count, expectedAmount);
}
void OnGUI()
{
int top = 0;
foreach (var tex in _textures)
{
var rect = new Rect(0, top, Screen.width * 0.5f, Screen.height * 0.5f);
GUI.DrawTexture(rect, tex);
top += 200;
}
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dea2fb7319188134c9049c249f465009
timeCreated: 1476625641
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ac3824324711c3f489d292e1b03858b9
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,103 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestFromSiblingComponent : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestBasic()
{
PreInstall();
Container.Bind<Bar>().FromNewComponentOnNewGameObject().AsSingle().NonLazy();
Container.Bind<Foo>().FromNewComponentSibling();
PostInstall();
Assert.IsEqual(Container.Resolve<Bar>().gameObject.GetComponents<Foo>().Length, 1);
yield break;
}
[UnityTest]
public IEnumerator TestInvalidUse()
{
PreInstall();
Container.Bind<Qux>().AsSingle().NonLazy();
Container.Bind<Foo>().FromNewComponentSibling();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestBasic2()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("Test");
Container.Bind<Gorp>().FromNewComponentOn(gameObject).AsSingle().NonLazy();
Container.Bind<Bar>().FromNewComponentOn(gameObject).AsSingle().NonLazy();
Container.Bind<Foo>().FromNewComponentSibling();
PostInstall();
var bar = Container.Resolve<Bar>();
var gorp = Container.Resolve<Gorp>();
Assert.IsEqual(bar.gameObject.GetComponents<Foo>().Length, 1);
Assert.IsEqual(bar.Foo, gorp.Foo);
yield break;
}
[UnityTest]
public IEnumerator TestOptional()
{
var gameObject = new GameObject("Test");
PreInstall();
Container.Bind<Qiv>().FromNewComponentOn(gameObject).AsSingle().NonLazy();
Container.Bind<Foo>().FromComponentSibling();
PostInstall();
var qiv = Container.Resolve<Qiv>();
Assert.IsNull(qiv.Foo);
yield break;
}
public class Qux
{
public Qux(Foo foo)
{
}
}
public class Foo : MonoBehaviour
{
}
public class Bar : MonoBehaviour
{
[Inject]
public Foo Foo;
}
public class Gorp : MonoBehaviour
{
[Inject]
public Foo Foo;
}
public class Qiv : MonoBehaviour
{
[InjectOptional]
public Foo Foo;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: eb7b9080f4910bd4bae9f726194b1c50
timeCreated: 1476625795
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 9ab8e28ca08241e41982482e00de08f0
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,281 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.FromSubContainerPrefab;
#pragma warning disable 649
namespace Zenject.Tests.Bindings
{
public class TestFromSubContainerPrefab : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get { return FixtureUtil.GetPrefab("TestFromSubContainerPrefab/Foo"); }
}
GameObject CircFooPrefab
{
get { return FixtureUtil.GetPrefab("TestFromSubContainerPrefab/CircFoo"); }
}
GameObject FooPrefab2
{
get { return FixtureUtil.GetPrefab("TestFromSubContainerPrefab/Foo2"); }
}
void CommonInstall()
{
Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
}
[UnityTest]
public IEnumerator TestSelfSingle()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve()
.ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
[ValidateOnly]
public IEnumerator TestSelfSingleValidate()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve()
.ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
yield break;
}
[UnityTest]
[ValidateOnly]
public IEnumerator TestSelfSingleValidateFails()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve()
.ByNewContextPrefab(FooPrefab2).AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestSelfTransient()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfCached()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfSingleMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfCachedMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfTransientMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(2);
FixtureUtil.AssertComponentCount<Bar>(2);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteSingle()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteTransient()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve()
.ByNewContextPrefab(FooPrefab).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteCached()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteSingleMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Bar), typeof(IFoo)).To(typeof(Foo), typeof(Bar))
.FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteCachedMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(IFoo)).To<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfIdentifiersFails()
{
PreInstall();
CommonInstall();
Container.Bind<Gorp>().FromSubContainerResolve().ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestSelfIdentifiers()
{
PreInstall();
CommonInstall();
Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
Container.Bind<Gorp>().FromSubContainerResolve("gorp").ByNewContextPrefab(FooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestCircularDependency()
{
PreInstall();
CommonInstall();
Container.Bind<CircBar>().FromNewComponentOnNewGameObject().AsSingle();
Container.Bind<CircFoo>().FromSubContainerResolve()
.ByNewContextPrefab(CircFooPrefab).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<CircFoo>(1);
FixtureUtil.AssertComponentCount<CircBar>(1);
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bdaee535959c3024c889b3b486fa661a
timeCreated: 1476626071
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ecae311eb84afdb4e812a5c20367cb1e
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,230 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Bindings.FromSubContainerPrefabResource;
namespace Zenject.Tests.Bindings
{
public class TestFromSubContainerPrefabResource : ZenjectIntegrationTestFixture
{
const string PathPrefix = "TestFromSubContainerPrefabResource/";
const string FooResourcePath = PathPrefix + "FooSubContainer";
void CommonInstall()
{
Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
}
[UnityTest]
public IEnumerator TestTransientError()
{
PreInstall();
CommonInstall();
// Validation should detect that it doesn't exist
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(PathPrefix + "asdfasdfas").AsTransient().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestSelfSingle()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfTransient()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfCached()
{
PreInstall();
CommonInstall();
Container.Bind<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfSingleMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfCachedMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfTransientMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(Bar)).FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(2);
FixtureUtil.AssertComponentCount<Foo>(2);
FixtureUtil.AssertComponentCount<Bar>(2);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteSingle()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteTransient()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve()
.ByNewContextPrefabResource(FooResourcePath).AsTransient().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteCached()
{
PreInstall();
CommonInstall();
Container.Bind<IFoo>().To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteSingleMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(IFoo), typeof(Bar)).To(typeof(Foo), typeof(Bar))
.FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertComponentCount<Bar>(1);
yield break;
}
[UnityTest]
public IEnumerator TestConcreteCachedMultipleContracts()
{
PreInstall();
CommonInstall();
Container.Bind(typeof(Foo), typeof(IFoo)).To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertComponentCount<Foo>(1);
yield break;
}
[UnityTest]
public IEnumerator TestSelfIdentifiersFails()
{
PreInstall();
CommonInstall();
Container.Bind<Gorp>().FromSubContainerResolve().ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
public IEnumerator TestSelfIdentifiers()
{
PreInstall();
CommonInstall();
Container.Bind<Gorp>().FromSubContainerResolve("gorp").ByNewContextPrefabResource(FooResourcePath).AsSingle().NonLazy();
PostInstall();
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 334541748134b72468ffe34ea80cf8f0
timeCreated: 1476626323
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0f115948ffad7e54f8a47ea450e67581
folderAsset: yes
timeCreated: 1535264071
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,224 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings.InstantiateCallback
{
public class TestInstantiateCallback : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get { return GetPrefab("Foo"); }
}
GameObject EmptyPrefab
{
get { return GetPrefab("Empty"); }
}
GameObject GetPrefab(string name)
{
return FixtureUtil.GetPrefab(GetPrefabPath(name));
}
string GetPrefabPath(string name)
{
return "TestInstantiateCallback/{0}".Fmt(name);
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObject()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewGameObject()
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOn()
{
PreInstall();
var gameObject = new GameObject();
Container.Bind<Foo>().FromNewComponentOn(gameObject)
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOn2()
{
PreInstall();
var gameObject = new GameObject();
Container.Bind<Foo>().FromNewComponentOn(ctx => gameObject)
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewPrefab()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewPrefab(EmptyPrefab)
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewPrefabResource()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnNewPrefabResource(GetPrefabPath("Empty"))
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnRoot()
{
PreInstall();
Container.Bind<Foo>().FromNewComponentOnRoot()
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
public class Bar : MonoBehaviour
{
[Inject]
public Foo Foo;
}
[UnityTest]
public IEnumerator TestFromNewComponentSibling()
{
PreInstall();
var bar = new GameObject().AddComponent<Bar>();
Container.QueueForInject(bar);
Container.Bind<Foo>().FromNewComponentSibling()
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
Assert.IsEqual(bar.Foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefab()
{
PreInstall();
Container.Bind<Foo>().FromComponentInNewPrefab(FooPrefab)
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefabResource()
{
PreInstall();
Container.Bind<Foo>().FromComponentInNewPrefabResource(GetPrefabPath("Foo"))
.AsSingle().OnInstantiated<Foo>((ctx, obj) =>
{
Assert.That(obj.WasInjected);
obj.Value = "asdf";
});
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, "asdf");
yield break;
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: fe1c39f4b0d91954a937f1277fad2453
timeCreated: 1535264071
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: f49bebb41c308914d80eebda326f1e17
folderAsset: yes
timeCreated: 1533537471
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,145 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
namespace Zenject.Tests.Bindings
{
public class TestLazy : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator Test1()
{
PreInstall();
Bar.InstanceCount = 0;
Container.Bind<Bar>().AsSingle();
Container.Bind<Foo>().AsSingle();
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.IsEqual(Bar.InstanceCount, 0);
foo.DoIt();
Assert.IsEqual(Bar.InstanceCount, 1);
yield break;
}
[UnityTest]
public IEnumerator Test2()
{
PreInstall();
Container.Bind<Foo>().AsSingle().NonLazy();
PostInstall();
var foo = Container.Resolve<Foo>();
Assert.Throws(() => foo.DoIt());
yield break;
}
[UnityTest]
[ValidateOnly]
public IEnumerator Test3()
{
PreInstall();
Container.Settings = new ZenjectSettings(ValidationErrorResponses.Throw);
Container.Bind<Foo>().AsSingle().NonLazy();
Assert.Throws(() => PostInstall());
yield break;
}
[UnityTest]
[ValidateOnly]
public IEnumerator Test4()
{
PreInstall();
Container.Bind<Foo>().AsSingle().NonLazy();
Container.Bind<Bar>().AsSingle();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestOptional1()
{
PreInstall();
Container.Bind<Bar>().AsSingle();
Container.Bind<Qux>().AsSingle();
PostInstall();
Assert.IsNotNull(Container.Resolve<Qux>().Bar.Value);
yield break;
}
[UnityTest]
public IEnumerator TestOptional2()
{
PreInstall();
Container.Bind<Qux>().AsSingle();
PostInstall();
Assert.IsNull(Container.Resolve<Qux>().Bar.Value);
yield break;
}
[UnityTest]
public IEnumerator TestOptional3()
{
PreInstall();
Container.Bind<Gorp>().AsSingle();
PostInstall();
var gorp = Container.Resolve<Gorp>();
object temp;
Assert.Throws(() => temp = gorp.Bar.Value);
yield break;
}
public class Bar
{
public static int InstanceCount;
public Bar()
{
InstanceCount++;
}
public void DoIt()
{
}
}
public class Foo
{
readonly LazyInject<Bar> _bar;
public Foo(LazyInject<Bar> bar)
{
_bar = bar;
}
public void DoIt()
{
_bar.Value.DoIt();
}
}
public class Qux
{
[Inject(Optional = true)]
public LazyInject<Bar> Bar;
}
public class Gorp
{
public LazyInject<Bar> Bar;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1ce0b6eda7a924b40a99633734931bb9
timeCreated: 1485556448
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: e5e30fa1ac6a1d1408340b6fb61c9693
folderAsset: yes
timeCreated: 1533537394
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: af8b779557d36924d820d239ab6ee944
folderAsset: yes
timeCreated: 1476627232
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,162 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Factories.PrefabFactory;
namespace Zenject.Tests.Factories
{
public class TestPrefabFactory : ZenjectIntegrationTestFixture
{
string FooPrefabResourcePath
{
get { return "TestPrefabFactory/Foo"; }
}
GameObject FooPrefab
{
get { return FixtureUtil.GetPrefab(FooPrefabResourcePath); }
}
string Foo2PrefabResourcePath
{
get { return "TestPrefabFactory/Foo2"; }
}
GameObject Foo2Prefab
{
get { return FixtureUtil.GetPrefab(Foo2PrefabResourcePath); }
}
[UnityTest]
public IEnumerator Test1()
{
PreInstall();
Container.BindFactory<Object, Foo, Foo.Factory>().FromFactory<PrefabFactory<Foo>>();
Container.Bind<IInitializable>().To<Runner>().AsSingle().WithArguments(FooPrefab);
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator Test2()
{
PreInstall();
Container.BindFactory<Object, string, Foo2, Foo2.Factory>().FromFactory<PrefabFactory<string, Foo2>>();
Container.Bind<IInitializable>().To<Runner2>().AsSingle().WithArguments(Foo2Prefab);
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestResource1()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory2>().FromFactory<PrefabResourceFactory<Foo>>();
Container.Bind<IInitializable>().To<Runner3>().AsSingle().WithArguments(FooPrefabResourcePath);
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestResource2()
{
PreInstall();
Container.BindFactory<string, string, Foo2, Foo2.Factory2>().FromFactory<PrefabResourceFactory<string, Foo2>>();
Container.Bind<IInitializable>().To<Runner4>().AsSingle().WithArguments(Foo2PrefabResourcePath);
PostInstall();
yield break;
}
public class Runner : IInitializable
{
readonly GameObject _prefab;
readonly Foo.Factory _fooFactory;
public Runner(
Foo.Factory fooFactory,
GameObject prefab)
{
_prefab = prefab;
_fooFactory = fooFactory;
}
public void Initialize()
{
var foo = _fooFactory.Create(_prefab);
Assert.That(foo.WasInitialized);
}
}
public class Runner2 : IInitializable
{
readonly GameObject _prefab;
readonly Foo2.Factory _fooFactory;
public Runner2(
Foo2.Factory fooFactory,
GameObject prefab)
{
_prefab = prefab;
_fooFactory = fooFactory;
}
public void Initialize()
{
var foo = _fooFactory.Create(_prefab, "asdf");
Assert.IsEqual(foo.Value, "asdf");
}
}
public class Runner3 : IInitializable
{
readonly string _prefabPath;
readonly Foo.Factory2 _fooFactory;
public Runner3(
Foo.Factory2 fooFactory,
string prefabPath)
{
_prefabPath = prefabPath;
_fooFactory = fooFactory;
}
public void Initialize()
{
var foo = _fooFactory.Create(_prefabPath);
Assert.That(foo.WasInitialized);
}
}
public class Runner4 : IInitializable
{
readonly string _prefabPath;
readonly Foo2.Factory2 _fooFactory;
public Runner4(
Foo2.Factory2 fooFactory,
string prefabPath)
{
_prefabPath = prefabPath;
_fooFactory = fooFactory;
}
public void Initialize()
{
var foo = _fooFactory.Create(_prefabPath, "asdf");
Assert.IsEqual(foo.Value, "asdf");
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d68637dd8a89bba40b7d4506d09c1bad
timeCreated: 1476628483
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: c021ba356ec385d469d715722ac7c4a7
folderAsset: yes
timeCreated: 1476627237
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,498 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Factories.BindFactory;
namespace Zenject.Tests.Factories
{
public class TestBindFactory : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get { return FixtureUtil.GetPrefab("TestBindFactory/Foo"); }
}
GameObject CameraPrefab
{
get { return FixtureUtil.GetPrefab("TestBindFactory/Camera"); }
}
GameObject FooSubContainerPrefab
{
get { return FixtureUtil.GetPrefab("TestBindFactory/FooSubContainer"); }
}
[UnityTest]
public IEnumerator TestFromNewScriptableObjectResource()
{
PreInstall();
Container.BindFactory<Bar, Bar.Factory>()
.FromNewScriptableObjectResource("TestBindFactory/Bar");
PostInstall();
var factory = Container.Resolve<Bar.Factory>();
var bar = factory.Create();
Assert.IsNotNull(bar);
Assert.IsNotEqual(bar, factory.Create());
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInHierarchy()
{
PreInstall();
var foo = new GameObject().AddComponent<Foo>();
Container.BindFactory<Foo, Foo.Factory>().FromComponentInHierarchy();
PostInstall();
var factory = Container.Resolve<Foo.Factory>();
var foo2 = factory.Create();
Assert.IsNotNull(foo2);
Assert.IsEqual(foo, foo2);
Assert.IsEqual(foo, factory.Create());
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInHierarchyErrors()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().FromComponentInHierarchy();
PostInstall();
var factory = Container.Resolve<Foo.Factory>();
// zero matches
Assert.Throws(() => factory.Create());
new GameObject().AddComponent<Foo>();
factory.Create();
new GameObject().AddComponent<Foo>();
// Multiple is ok too to mirror unity's GetComponentsInChildren behaviour
factory.Create();
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOn()
{
PreInstall();
var go = new GameObject();
Container.BindFactory<Foo, Foo.Factory>().FromNewComponentOn(go);
PostInstall();
var factory = Container.Resolve<Foo.Factory>();
Assert.IsNull(go.GetComponent<Foo>());
var foo = factory.Create();
Assert.IsNotNull(go.GetComponent<Foo>());
Assert.IsEqual(go.GetComponent<Foo>(), foo);
var foo2 = factory.Create();
Assert.IsNotEqual(foo2, foo);
var allFoos = go.GetComponents<Foo>();
Assert.IsEqual(allFoos.Length, 2);
Assert.IsEqual(allFoos[0], foo);
Assert.IsEqual(allFoos[1], foo2);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObject()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().FromNewComponentOnNewGameObject();
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectComponent()
{
PreInstall();
Container.BindFactory<Camera, CameraFactory>().FromNewComponentOnNewGameObject();
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Camera, CameraFactory>(Container);
FixtureUtil.AssertComponentCount<Camera>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectComponentFailure()
{
PreInstall();
Container.BindFactory<string, Camera, CameraFactory2>().FromNewComponentOnNewGameObject();
PostInstall();
Assert.Throws(() => Container.Resolve<CameraFactory2>().Create("asdf"));
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectWithParamsSuccess()
{
PreInstall();
Container.BindFactory<int, Foo2, Foo2.Factory2>().FromNewComponentOnNewGameObject();
PostInstall();
Container.Resolve<Foo2.Factory2>().Create(5);
FixtureUtil.AssertComponentCount<Foo2>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectWithParamsFailure()
{
PreInstall();
Container.BindFactory<Foo2, Foo2.Factory>().FromNewComponentOnNewGameObject();
PostInstall();
Assert.Throws(() => Container.Resolve<Foo2.Factory>().Create());
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectConcrete()
{
PreInstall();
Container.BindFactory<IFoo, IFooFactory>().To<Foo>().FromNewComponentOnNewGameObject();
PostInstall();
FixtureUtil.CallFactoryCreateMethod<IFoo, IFooFactory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnSelf()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<Foo, Foo.Factory>().FromNewComponentOn(gameObject);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnSelfFail()
{
PreInstall();
Assert.Throws(() => Container.BindFactory<Foo2, Foo2.Factory>().FromNewComponentOn((GameObject)null));
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnConcrete()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<IFoo, IFooFactory>().To<Foo>().FromNewComponentOn(gameObject);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<IFoo, IFooFactory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefab()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInPrefabComponent()
{
PreInstall();
Container.BindFactory<Camera, CameraFactory>().FromComponentInNewPrefab(CameraPrefab).WithGameObjectName("asdf");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Camera, CameraFactory>(Container);
FixtureUtil.AssertComponentCount<Camera>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabSelfFail()
{
PreInstall();
// Foo3 is not on the prefab
Container.BindFactory<Foo3, Foo3.Factory>().FromComponentInNewPrefab(FooPrefab);
PostInstall();
Assert.Throws(() => FixtureUtil.CallFactoryCreateMethod<Foo3, Foo3.Factory>(Container));
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabConcrete()
{
PreInstall();
Container.BindFactory<IFoo, IFooFactory>().To<Foo>().FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<IFoo, IFooFactory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToResourceSelf()
{
PreInstall();
Container.BindFactory<Texture, PlaceholderFactory<Texture>>()
.FromResource("TestBindFactory/TestTexture").NonLazy();
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Texture, PlaceholderFactory<Texture>>(Container);
yield break;
}
[UnityTest]
public IEnumerator TestToResource()
{
PreInstall();
Container.BindFactory<Object, PlaceholderFactory<Object>>()
.To<Texture>().FromResource("TestBindFactory/TestTexture").NonLazy();
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().FromComponentInNewPrefabResource("TestBindFactory/Foo").WithGameObjectName("asdf");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().To<Foo>().FromComponentInNewPrefabResource("TestBindFactory/Foo").WithGameObjectName("asdf");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabSelf()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>().FromSubContainerResolve().ByNewContextPrefab(FooSubContainerPrefab);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabConcrete()
{
PreInstall();
Container.BindFactory<IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefab(FooSubContainerPrefab);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<IFoo, IFooFactory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>()
.FromSubContainerResolve().ByNewContextPrefabResource("TestBindFactory/FooSubContainer");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource("TestBindFactory/FooSubContainer");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<IFoo, IFooFactory>(Container);
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransformGroup()
{
PreInstall();
Container.BindFactory<Foo, Foo.Factory>()
.FromNewComponentOnNewGameObject().UnderTransformGroup("Foos");
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
var child = GameObject.Find("Foos").transform.GetChild(0);
Assert.IsNotNull(child.GetComponent<Foo>());
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransform()
{
PreInstall();
var tempGameObject = new GameObject("Foo");
Container.BindFactory<Foo, Foo.Factory>().FromNewComponentOnNewGameObject().
UnderTransform(tempGameObject.transform);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
Assert.IsNotNull(tempGameObject.transform.GetChild(0).GetComponent<Foo>());
yield break;
}
[UnityTest]
public IEnumerator TestUnderTransformGetter()
{
PreInstall();
var tempGameObject = new GameObject("Foo");
Container.BindFactory<Foo, Foo.Factory>().FromNewComponentOnNewGameObject()
.UnderTransform(context => tempGameObject.transform);
PostInstall();
FixtureUtil.CallFactoryCreateMethod<Foo, Foo.Factory>(Container);
Assert.IsNotNull(tempGameObject.transform.GetChild(0).GetComponent<Foo>());
yield break;
}
public class CameraFactory2 : PlaceholderFactory<string, Camera>
{
}
public class CameraFactory : PlaceholderFactory<Camera>
{
}
public class Foo3 : MonoBehaviour
{
public class Factory : PlaceholderFactory<Foo3>
{
}
}
public class Foo2 : MonoBehaviour
{
[Inject]
public int Value
{
get; private set;
}
public class Factory : PlaceholderFactory<Foo2>
{
}
public class Factory2 : PlaceholderFactory<int, Foo2>
{
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 27adf673c597fc3409c6f978c63ab887
timeCreated: 1476628483
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 99205e310884d9d4b9039013bf5eaaee
folderAsset: yes
timeCreated: 1476627243
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,250 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Factories.BindFactoryFive;
namespace Zenject.Tests.Factories
{
public class TestBindFactoryFive : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get
{
return FixtureUtil.GetPrefab("TestBindFactoryFive/Foo");
}
}
GameObject FooSubContainerPrefab
{
get
{
return FixtureUtil.GetPrefab("TestBindFactoryFive/FooSubContainer");
}
}
[UnityTest]
public IEnumerator TestToGameObjectSelf()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>().FromNewComponentOnNewGameObject();
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToGameObjectConcrete()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>().To<Foo>().FromNewComponentOnNewGameObject();
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToMonoBehaviourSelf()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>().FromNewComponentOn(gameObject);
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToMonoBehaviourConcrete()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>().To<Foo>().FromNewComponentOn(gameObject);
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabSelf()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>().FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabConcrete()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>().To<Foo>().FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>().FromComponentInNewPrefabResource("TestBindFactoryFive/Foo").WithGameObjectName("asdf");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>()
.To<Foo>().FromComponentInNewPrefabResource("TestBindFactoryFive/Foo").WithGameObjectName("asdf");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabSelf()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>()
.FromSubContainerResolve().ByNewContextPrefab<FooInstaller>(FooSubContainerPrefab);
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabConcrete()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefab<FooInstaller>(FooSubContainerPrefab);
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, Foo, Foo.Factory>().FromSubContainerResolve().ByNewContextPrefabResource<FooInstaller>("TestBindFactoryFive/FooSubContainer");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestToSubContainerPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<double, int, float, string, char, IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource<FooInstaller>("TestBindFactoryFive/FooSubContainer");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
void AddFactoryUser<TValue, TFactory>()
where TValue : IFoo
where TFactory : PlaceholderFactory<double, int, float, string, char, TValue>
{
Container.Bind<IInitializable>()
.To<FooFactoryTester<TValue, TFactory>>().AsSingle();
Container.BindExecutionOrder<FooFactoryTester<TValue, TFactory>>(-100);
}
public class FooFactoryTester<TValue, TFactory> : IInitializable
where TFactory : PlaceholderFactory<double, int, float, string, char, TValue>
where TValue : IFoo
{
readonly TFactory _factory;
public FooFactoryTester(TFactory factory)
{
_factory = factory;
}
public void Initialize()
{
Assert.IsEqual(_factory.Create(0.15, 0, 2.4f, "zxcv", 'z').Value, "zxcv");
Log.Info("Factory created foo successfully");
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 572457f9104bd1e4b9b08350f69f5041
timeCreated: 1476628483
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 26299dac98af5b84483bf41c4b2897ca
folderAsset: yes
timeCreated: 1476627250
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,298 @@
using System.Collections;
using ModestTree;
using UnityEngine;
using UnityEngine.TestTools;
using Zenject.Tests.Factories.BindFactoryOne;
namespace Zenject.Tests.Factories
{
public class TestBindFactoryOne : ZenjectIntegrationTestFixture
{
GameObject FooPrefab
{
get
{
return FixtureUtil.GetPrefab("TestBindFactoryOne/Foo");
}
}
GameObject FooSubContainerPrefab
{
get
{
return FixtureUtil.GetPrefab("TestBindFactoryOne/FooSubContainer");
}
}
[UnityTest]
public IEnumerator TestFromNewComponentOn()
{
PreInstall();
var go = new GameObject();
Container.BindFactory<string, Foo, Foo.Factory>().FromNewComponentOn(go);
PostInstall();
var factory = Container.Resolve<Foo.Factory>();
Assert.IsNull(go.GetComponent<Foo>());
var foo = factory.Create("asdf");
Assert.IsEqual(foo.Value, "asdf");
Assert.IsNotNull(go.GetComponent<Foo>());
Assert.IsEqual(go.GetComponent<Foo>(), foo);
var foo2 = factory.Create("zxcv");
Assert.IsNotEqual(foo2, foo);
var allFoos = go.GetComponents<Foo>();
Assert.IsEqual(allFoos.Length, 2);
Assert.IsEqual(allFoos[0], foo);
Assert.IsEqual(allFoos[1], foo2);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewScriptableObjectResource()
{
PreInstall();
Container.BindFactory<string, Bar, Bar.Factory>()
.FromNewScriptableObjectResource("TestBindFactoryOne/Bar");
PostInstall();
var factory = Container.Resolve<Bar.Factory>();
var bar = factory.Create("asdf");
Assert.IsNotNull(bar);
Assert.IsEqual(bar.Value, "asdf");
Assert.IsNotEqual(bar, factory.Create("zxcv"));
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectSelf()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory>().FromNewComponentOnNewGameObject();
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnNewGameObjectConcrete()
{
PreInstall();
Container.BindFactory<string, IFoo, IFooFactory>().To<Foo>().FromNewComponentOnNewGameObject();
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnSelf()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<string, Foo, Foo.Factory>().FromNewComponentOn(gameObject);
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromNewComponentOnConcrete()
{
PreInstall();
var gameObject = Container.CreateEmptyGameObject("foo");
Container.BindFactory<string, IFoo, IFooFactory>().To<Foo>().FromNewComponentOn(gameObject);
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefabSelf()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory>().FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefabConcrete()
{
PreInstall();
Container.BindFactory<string, IFoo, IFooFactory>().To<Foo>()
.FromComponentInNewPrefab(FooPrefab).WithGameObjectName("asdf");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory>().FromComponentInNewPrefabResource("TestBindFactoryOne/Foo").WithGameObjectName("asdf");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestFromComponentInNewPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<string, IFoo, IFooFactory>().To<Foo>()
.FromComponentInNewPrefabResource("TestBindFactoryOne/Foo").WithGameObjectName("asdf");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
FixtureUtil.AssertNumGameObjectsWithName("asdf", 1);
yield break;
}
[UnityTest]
public IEnumerator TestFromSubContainerResolveByNewPrefabSelf()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory>()
.FromSubContainerResolve().ByNewContextPrefab<FooInstaller>(FooSubContainerPrefab);
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromSubContainerResolveByNewPrefabConcrete()
{
PreInstall();
Container.BindFactory<string, IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefab<FooInstaller>(FooSubContainerPrefab);
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromSubContainerResolveByNewPrefabResourceSelf()
{
PreInstall();
Container.BindFactory<string, Foo, Foo.Factory>()
.FromSubContainerResolve().ByNewContextPrefabResource<FooInstaller>("TestBindFactoryOne/FooSubContainer");
AddFactoryUser<Foo, Foo.Factory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
[UnityTest]
public IEnumerator TestFromSubContainerResolveByNewPrefabResourceConcrete()
{
PreInstall();
Container.BindFactory<string, IFoo, IFooFactory>()
.To<Foo>().FromSubContainerResolve().ByNewContextPrefabResource<FooInstaller>("TestBindFactoryOne/FooSubContainer");
AddFactoryUser<IFoo, IFooFactory>();
PostInstall();
FixtureUtil.AssertComponentCount<Foo>(1);
FixtureUtil.AssertNumGameObjects(1);
yield break;
}
void AddFactoryUser<TValue, TFactory>()
where TValue : IFoo
where TFactory : PlaceholderFactory<string, TValue>
{
Container.Bind<IInitializable>()
.To<FooFactoryTester<TValue, TFactory>>().AsSingle();
Container.BindExecutionOrder<FooFactoryTester<TValue, TFactory>>(-100);
}
public class FooFactoryTester<TValue, TFactory> : IInitializable
where TFactory : PlaceholderFactory<string, TValue>
where TValue : IFoo
{
readonly TFactory _factory;
public FooFactoryTester(TFactory factory)
{
_factory = factory;
}
public void Initialize()
{
Assert.IsEqual(_factory.Create("asdf").Value, "asdf");
Log.Info("Factory created foo successfully");
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 07b8699c6cfb35041acbf91f227fe7d4
timeCreated: 1476628483
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0cf5d221a15233c4a96f91df1d41379e
folderAsset: yes
timeCreated: 1506454125
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,145 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
#pragma warning disable 219
namespace Zenject.Tests.Bindings
{
public class TestMemoryPool1 : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestFactoryProperties()
{
PreInstall();
Container.BindMemoryPool<Foo, Foo.Pool>();
PostInstall();
var pool = Container.Resolve<Foo.Pool>();
Assert.IsEqual(pool.NumActive, 0);
Assert.IsEqual(pool.NumTotal, 0);
Assert.IsEqual(pool.NumInactive, 0);
var foo = pool.Spawn("asdf");
Assert.IsEqual(pool.NumActive, 1);
Assert.IsEqual(pool.NumTotal, 1);
Assert.IsEqual(pool.NumInactive, 0);
Assert.IsEqual(foo.ResetCount, 1);
Assert.IsEqual(foo.Value, "asdf");
pool.Despawn(foo);
Assert.IsEqual(pool.NumActive, 0);
Assert.IsEqual(pool.NumTotal, 1);
Assert.IsEqual(pool.NumInactive, 1);
Assert.IsEqual(foo.ResetCount, 1);
foo = pool.Spawn("zxcv");
Assert.IsEqual(pool.NumActive, 1);
Assert.IsEqual(pool.NumTotal, 1);
Assert.IsEqual(pool.NumInactive, 0);
Assert.IsEqual(foo.ResetCount, 2);
Assert.IsEqual(foo.Value, "zxcv");
var foo2 = pool.Spawn("qwer");
Assert.IsEqual(pool.NumActive, 2);
Assert.IsEqual(pool.NumTotal, 2);
Assert.IsEqual(pool.NumInactive, 0);
Assert.IsEqual(foo2.ResetCount, 1);
Assert.IsEqual(foo2.Value, "qwer");
pool.Despawn(foo);
Assert.IsEqual(pool.NumActive, 1);
Assert.IsEqual(pool.NumTotal, 2);
Assert.IsEqual(pool.NumInactive, 1);
Assert.IsEqual(foo.ResetCount, 2);
pool.Despawn(foo2);
Assert.IsEqual(pool.NumActive, 0);
Assert.IsEqual(pool.NumTotal, 2);
Assert.IsEqual(pool.NumInactive, 2);
pool.Spawn("zxcv");
pool.Spawn("bxzc");
pool.Spawn("bxzc");
Assert.IsEqual(pool.NumActive, 3);
Assert.IsEqual(pool.NumTotal, 3);
Assert.IsEqual(pool.NumInactive, 0);
yield break;
}
class Foo
{
public string Value
{
get;
private set;
}
public int ResetCount
{
get; private set;
}
public class Pool : MemoryPool<string, Foo>
{
protected override void Reinitialize(string value, Foo foo)
{
foo.Value = value;
foo.ResetCount++;
}
}
}
[UnityTest]
public IEnumerator TestAbstractMemoryPoolValidate()
{
TestAbstractMemoryPoolInternal();
yield break;
}
[UnityTest]
public IEnumerator TestAbstractMemoryPool()
{
TestAbstractMemoryPoolInternal();
var pool = Container.Resolve<BarPool>();
var foo = pool.Spawn(5);
Assert.IsEqual(foo.GetType(), typeof(Bar));
yield break;
}
void TestAbstractMemoryPoolInternal()
{
PreInstall();
Container.BindMemoryPool<IBar, BarPool>()
.WithInitialSize(3).To<Bar>().NonLazy();
PostInstall();
}
public interface IBar
{
}
public class Bar : IBar
{
}
public class BarPool : MemoryPool<int, IBar>
{
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f50a5f22f2c3e034d9e90b4244a3e412
timeCreated: 1506454125
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 12c03aec56b42a246bcd063539109901
folderAsset: yes
timeCreated: 1533537397
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: fa8246ebe523f444d8a36e1473a69c9f
folderAsset: yes
timeCreated: 1476629271
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,48 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Installers.Installers;
namespace Zenject.Tests.Installers
{
public class TestInstallers : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestZeroArgs()
{
PreInstall();
FooInstaller.Install(Container);
PostInstall();
FixtureUtil.AssertResolveCount<Foo>(Container, 1);
yield break;
}
[UnityTest]
public IEnumerator TestOneArg()
{
PreInstall();
BarInstaller.Install(Container, "blurg");
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
[UnityTest]
public IEnumerator TestThreeArgs()
{
PreInstall();
QuxInstaller.Install(Container, "blurg", 2.0f, 1);
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 32558f6368b08f645928a4a03327df55
timeCreated: 1476629271
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ce19e0da982ee004ab1ac04ad4ee376a
folderAsset: yes
timeCreated: 1476629271
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Installers.MonoInstallers;
namespace Zenject.Tests.Installers
{
public class TestMonoInstallers : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestBadResourcePath()
{
PreInstall();
Assert.Throws(() => FooInstaller.InstallFromResource("TestMonoInstallers/SDFSDFSDF", Container));
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestZeroArgs()
{
PreInstall();
FooInstaller.InstallFromResource("TestMonoInstallers/FooInstaller", Container);
PostInstall();
FixtureUtil.AssertResolveCount<Foo>(Container, 1);
yield break;
}
[UnityTest]
public IEnumerator TestOneArg()
{
PreInstall();
BarInstaller.InstallFromResource("TestMonoInstallers/BarInstaller", Container, "blurg");
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
[UnityTest]
public IEnumerator TestThreeArgs()
{
PreInstall();
QuxInstaller.InstallFromResource("TestMonoInstallers/QuxInstaller", Container, "blurg", 2.0f, 1);
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 93f2c1be16a3dce4a8a498951113458f
timeCreated: 1476629272
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 2668028b00be0f74bb1a41abc9199438
folderAsset: yes
timeCreated: 1476629271
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
using Zenject.Tests.Installers.ScriptableObjectInstallers;
namespace Zenject.Tests.Installers
{
public class TestScriptableObjectInstallers : ZenjectIntegrationTestFixture
{
[UnityTest]
public IEnumerator TestBadResourcePath()
{
PreInstall();
Assert.Throws(() => FooInstaller.InstallFromResource("TestScriptableObjectInstallers/SDFSDFSDF", Container));
PostInstall();
yield break;
}
[UnityTest]
public IEnumerator TestZeroArgs()
{
PreInstall();
FooInstaller.InstallFromResource("TestScriptableObjectInstallers/FooInstaller", Container);
PostInstall();
FixtureUtil.AssertResolveCount<Foo>(Container, 1);
yield break;
}
[UnityTest]
public IEnumerator TestOneArg()
{
PreInstall();
BarInstaller.InstallFromResource("TestScriptableObjectInstallers/BarInstaller", Container, "blurg");
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
[UnityTest]
public IEnumerator TestThreeArgs()
{
PreInstall();
QuxInstaller.InstallFromResource("TestScriptableObjectInstallers/QuxInstaller", Container, "blurg", 2.0f, 1);
PostInstall();
Assert.IsEqual(Container.Resolve<string>(), "blurg");
yield break;
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1e5c2b8474b1ca34ba877a52ba18d05f
timeCreated: 1476629271
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b97ab04110b7d5a4ea3f45c3acf61671
folderAsset: yes
timeCreated: 1533537796
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,74 @@
using System;
using System.Collections;
using ModestTree;
using UnityEngine.TestTools;
namespace Zenject.Tests
{
public class TestIntegrationTest : ZenjectIntegrationTestFixture
{
public class Foo : IInitializable, IDisposable
{
public static bool WasDisposed
{
get; set;
}
public static bool WasInitialized
{
get; set;
}
public void Initialize()
{
WasInitialized = true;
}
public void Dispose()
{
WasDisposed = true;
}
}
[UnityTest]
public IEnumerator TestRun()
{
PreInstall();
Foo.WasDisposed = false;
Foo.WasInitialized = false;
Container.BindInterfacesTo<Foo>().AsSingle();
Assert.That(!Foo.WasInitialized);
PostInstall();
yield return null;
Assert.That(Foo.WasInitialized);
yield return DestroyEverything();
Assert.That(Foo.WasDisposed);
}
[UnityTest]
public IEnumerator TestSkipInstall()
{
SkipInstall();
yield break;
}
[UnityTest]
public IEnumerator TestProjectContextDestroyed()
{
Assert.That(!ProjectContext.HasInstance);
SkipInstall();
yield return null;
Assert.That(ProjectContext.HasInstance);
yield return DestroyEverything();
Assert.That(!ProjectContext.HasInstance);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 056c7f636d28cd740aa4f1506db0593d
timeCreated: 1506428837
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 4e9bd8259ac41484a89d4c3ded0e11f4
folderAsset: yes
timeCreated: 1533537402
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b3f01a7aab70acf449c179f9d22e6ff5
folderAsset: yes
timeCreated: 1527865953
licenseType: Free
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
@@ -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;
}
}
}
}
@@ -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:
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 503a300139444eda80c6549ec29b3b20
timeCreated: 1587924687
@@ -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();
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 983f0bc44f6541bfab062ceec72231d3
timeCreated: 1587867811
@@ -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>();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 71d4a84946422ad49ae352537c257aed
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -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;
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 166ad9cc65d872b48badf6da39e4a31c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show More