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().FromSubContainerResolve() .ByNewPrefabInstaller(FooPrefab).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } [UnityTest] public IEnumerator TestInstallerGetter() { PreInstall(); Container.Bind().FromSubContainerResolve() .ByNewPrefabInstaller(_ => FooPrefab).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } [UnityTest] public IEnumerator TestMethod() { PreInstall(); Container.Bind().FromSubContainerResolve() .ByNewPrefabMethod(FooPrefab, InstallFoo).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } [UnityTest] public IEnumerator TestMethodGetter() { PreInstall(); Container.Bind().FromSubContainerResolve() .ByNewPrefabMethod((context) => FooPrefab, InstallFoo).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } [UnityTest] public IEnumerator TestResourceInstaller() { PreInstall(); Container.Bind().FromSubContainerResolve() .ByNewPrefabResourceInstaller(FooPrefabResourcePath).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } [UnityTest] public IEnumerator TestResourceMethod() { PreInstall(); Container.Bind().FromSubContainerResolve() .ByNewPrefabResourceMethod(FooPrefabResourcePath, InstallFoo).AsCached(); PostInstall(); Assert.IsEqual(Container.Resolve().Data, "asdf"); yield break; } void InstallFoo(DiContainer subContainer) { subContainer.Bind().AsSingle().WithArguments("asdf"); } public class Qux { [Inject] public string Data; [Inject] public Foo Foo; } public class FooInstaller : Installer { public override void InstallBindings() { Container.Bind().AsSingle().WithArguments("asdf"); } } } }