Initial Commit
This commit is contained in:
+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:
|
||||
Reference in New Issue
Block a user