diff --git a/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs b/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs new file mode 100644 index 000000000..5ba7a6fd2 --- /dev/null +++ b/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs @@ -0,0 +1,163 @@ +using System.Collections; +using ModestTree; +using UnityEngine; +using UnityEngine.TestTools; +using Zenject.Tests.Factories.BindFactoryOne; + +namespace Zenject.Tests.Factories +{ + public class TestBindFactoryOneWithArguments : ZenjectIntegrationTestFixture + { + private const string ArgumentValue = "asdf"; + + GameObject FooPrefab + { + get + { + return FixtureUtil.GetPrefab("TestBindFactoryOne/Foo"); + } + } + + [UnityTest] + public IEnumerator TestFromNewComponentOnNewGameObjectSelf() + { + PreInstall(); + Container.BindIFactory() + .FromNewComponentOnNewGameObject() + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + yield break; + } + + [UnityTest] + public IEnumerator TestFromNewComponentOnNewGameObjectConcrete() + { + PreInstall(); + Container.BindIFactory() + .To() + .FromNewComponentOnNewGameObject() + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + yield break; + } + + [UnityTest] + public IEnumerator TestFromComponentInNewPrefabSelf() + { + PreInstall(); + Container.BindIFactory() + .FromComponentInNewPrefab(FooPrefab) + .WithGameObjectName("asdf") + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); + yield break; + } + + [UnityTest] + public IEnumerator TestFromComponentInNewPrefabConcrete() + { + PreInstall(); + Container.BindIFactory() + .To() + .FromComponentInNewPrefab(FooPrefab) + .WithGameObjectName("asdf") + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); + yield break; + } + + [UnityTest] + public IEnumerator TestFromComponentInNewPrefabResourceSelf() + { + PreInstall(); + Container.BindIFactory() + .FromComponentInNewPrefabResource("TestBindFactoryOne/Foo") + .WithGameObjectName("asdf") + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); + yield break; + } + + [UnityTest] + public IEnumerator TestFromComponentInNewPrefabResourceConcrete() + { + PreInstall(); + Container.BindIFactory().To() + .FromComponentInNewPrefabResource("TestBindFactoryOne/Foo") + .WithGameObjectName("asdf") + .WithArguments(ArgumentValue); + + AddFactoryUser(); + + PostInstall(); + + FixtureUtil.AssertComponentCount(1); + FixtureUtil.AssertNumGameObjects(1); + FixtureUtil.AssertNumGameObjectsWithName("asdf", 1); + yield break; + } + + // Note that unlike the TestBindFactory tests, WithArguments still doesn't work nicely with subcontainers... + + void AddFactoryUser() + where TValue : IFoo + { + Container.Bind() + .To>().AsSingle(); + + Container.BindExecutionOrder>(-100); + } + + public class FooFactoryTester : IInitializable + where TValue : IFoo + { + readonly IFactory _factory; + + public FooFactoryTester(IFactory factory) + { + _factory = factory; + } + + public void Initialize() + { + Assert.IsEqual(_factory.Create().Value, ArgumentValue); + + Log.Info("Factory created foo successfully"); + } + } + } +} + diff --git a/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs.meta b/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs.meta new file mode 100644 index 000000000..3ad755a56 --- /dev/null +++ b/UnityProject/Assets/Plugins/Zenject/OptionalExtras/IntegrationTests/Tests/Factories/TestBindFactoryOne/TestBindFactoryOneWithArguments.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 94b7f15ee7704375a72da83287e0a7b1 +timeCreated: 1604660417 \ No newline at end of file