Initial Commit
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bcfe42301470d994596ab617acdc6545
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+314
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03827fc575424954ba63c60d88fdd289
|
||||
timeCreated: 1506426682
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3da0ff226e0beea4d91bdef5be3cc543
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+138
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
+13
@@ -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:
|
||||
+152
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -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:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b28f74c42a00cce4c966429fc9bf3304
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+229
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 60e4db58b41116646b1675963b1c75a1
|
||||
timeCreated: 1485741160
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 703bae5899505584ea4bd2f89e7c5686
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+213
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33f32e2013960314f841932f66d9b92c
|
||||
timeCreated: 1485743323
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4dba59ca52fc08499490254c3940f59
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+46
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4a3a41ae23a4bb44b068790d065e7e4
|
||||
timeCreated: 1485743325
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b12b2bde79e96504980df2b05b948e89
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+237
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9df118a8d9c898344bed28c6913a6d7e
|
||||
timeCreated: 1485741161
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1f10443fc834f9f4cbd6ce1fd5bce4a3
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+244
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b0d37dd020d97b3459f64a7f3434ff96
|
||||
timeCreated: 1485741161
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9116904793056a445abaca59d9fd9c91
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+207
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e879b4e0ab309f247a1efc11a7a71bba
|
||||
timeCreated: 1476623361
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7bad27777f963f244b6475fdd2f56155
|
||||
folderAsset: yes
|
||||
timeCreated: 1538468409
|
||||
licenseType: Pro
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+59
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -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:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1584905eb3a75484099619f9e66362b1
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+101
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 524c1ea1726f5b24e99d297bf3bab1b3
|
||||
timeCreated: 1487537569
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d3728543fde13364396f833fea981d45
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+222
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a11ff4a9421f2949993c4dc34f50335
|
||||
timeCreated: 1454819941
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 004fb639c2306474c8f8825720e5a9d2
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+128
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -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:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab61730ee27e0954db743cf10ae967bd
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+179
@@ -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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 100b8c53531c9e049bd6ac742c979248
|
||||
timeCreated: 1476625195
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77895b2c18397dd4eb7b086f557cfaa1
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537470
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+106
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dea2fb7319188134c9049c249f465009
|
||||
timeCreated: 1476625641
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac3824324711c3f489d292e1b03858b9
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+103
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb7b9080f4910bd4bae9f726194b1c50
|
||||
timeCreated: 1476625795
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9ab8e28ca08241e41982482e00de08f0
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+281
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bdaee535959c3024c889b3b486fa661a
|
||||
timeCreated: 1476626071
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ecae311eb84afdb4e812a5c20367cb1e
|
||||
folderAsset: yes
|
||||
timeCreated: 1533537471
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+230
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 334541748134b72468ffe34ea80cf8f0
|
||||
timeCreated: 1476626323
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f115948ffad7e54f8a47ea450e67581
|
||||
folderAsset: yes
|
||||
timeCreated: 1535264071
|
||||
licenseType: Free
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+224
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -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:
|
||||
+145
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ce0b6eda7a924b40a99633734931bb9
|
||||
timeCreated: 1485556448
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user