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().FromNewScriptableObjectResource(PathPrefix + "asdfasdfas").AsTransient().NonLazy(); Assert.Throws(() => PostInstall()); yield break; } [UnityTest] public IEnumerator TestTransient() { PreInstall(); Foo.InstanceCount = 0; Container.Bind().FromNewScriptableObjectResource(PathPrefix + "Foo").AsTransient(); PostInstall(); var foo = Container.Resolve(); Assert.That(foo.WasInjected); Assert.IsEqual(Foo.InstanceCount, 1); var foo2 = Container.Resolve(); 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().FromNewScriptableObjectResource(PathPrefix + "Foo").AsSingle(); PostInstall(); Container.Resolve(); Assert.IsEqual(Foo.InstanceCount, 1); yield break; } [UnityTest] public IEnumerator TestAbstractBinding() { PreInstall(); Foo.InstanceCount = 0; Container.Bind().To() .FromNewScriptableObjectResource(PathPrefix + "Foo").AsSingle().NonLazy(); PostInstall(); Container.Resolve(); Assert.IsEqual(Foo.InstanceCount, 1); yield break; } [UnityTest] public IEnumerator TestWithArgumentsFail() { PreInstall(); Container.Bind() .FromNewScriptableObjectResource(PathPrefix + "Bob").AsSingle().NonLazy(); Assert.Throws(() => PostInstall()); yield break; } [UnityTest] public IEnumerator TestWithArguments() { PreInstall(); Container.Bind() .FromNewScriptableObjectResource(PathPrefix + "Bob").AsSingle() .WithArguments("test1").NonLazy(); PostInstall(); Assert.IsEqual(Container.Resolve().Arg, "test1"); yield break; } } }