Initial Commit

This commit is contained in:
2026-03-16 14:38:46 +02:00
commit b8f7327a21
2327 changed files with 253610 additions and 0 deletions
@@ -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
{
}
}
}
@@ -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:
@@ -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
{
}
}
}
@@ -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: