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,92 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Other
{
[TestFixture]
public class TestBindingInheritanceMethod : ZenjectUnitTestFixture
{
[Test]
public void TestNoCopy()
{
Container.Bind<Foo>().AsSingle();
var sub1 = Container.CreateSubContainer();
Assert.IsEqual(sub1.Resolve<Foo>(), Container.Resolve<Foo>());
}
[Test]
public void TestCopyIntoAll1()
{
Container.Bind<Foo>().AsSingle().CopyIntoAllSubContainers();
var sub1 = Container.CreateSubContainer();
Assert.IsNotEqual(sub1.Resolve<Foo>(), Container.Resolve<Foo>());
}
[Test]
public void TestCopyIntoAll2()
{
Container.Bind<IBar>().To<Bar>().FromResolve().CopyIntoAllSubContainers();
Container.Bind<Bar>().AsSingle();
var sub1 = Container.CreateSubContainer();
Assert.IsEqual(Container.ResolveAll<IBar>().Count, 1);
Assert.IsEqual(sub1.ResolveAll<IBar>().Count, 2);
}
[Test]
public void TestCopyDirect1()
{
Container.Bind<Foo>().AsSingle().CopyIntoDirectSubContainers();
var sub1 = Container.CreateSubContainer();
var sub2 = sub1.CreateSubContainer();
Assert.That(Container.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(sub1.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(!sub2.HasBindingId(typeof(Foo), null, InjectSources.Local));
}
[Test]
public void TestMoveDirect1()
{
Container.Bind<Foo>().AsSingle().MoveIntoDirectSubContainers();
var sub1 = Container.CreateSubContainer();
var sub2 = sub1.CreateSubContainer();
Assert.That(!Container.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(sub1.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(!sub2.HasBindingId(typeof(Foo), null, InjectSources.Local));
}
[Test]
public void TestMoveAll()
{
Container.Bind<Foo>().AsSingle().MoveIntoAllSubContainers();
var sub1 = Container.CreateSubContainer();
var sub2 = sub1.CreateSubContainer();
Assert.That(!Container.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(sub1.HasBindingId(typeof(Foo), null, InjectSources.Local));
Assert.That(sub2.HasBindingId(typeof(Foo), null, InjectSources.Local));
}
public interface IBar
{
}
public class Foo
{
}
public class Bar : IBar
{
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 645589d2772852246ac2ea1fd8ee4f92
timeCreated: 1519842213
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,47 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestConcreteIdentifier : ZenjectUnitTestFixture
{
[Test]
public void Test1()
{
Container.Bind<IFoo>().To<Foo>().AsCached().WithConcreteId("asdf");
Container.Bind<IFoo>().To<Foo>().AsCached();
Container.BindInstance("a").When(x => Equals(x.ConcreteIdentifier, "asdf") && x.ObjectType == typeof(Foo));
Container.BindInstance("b").When(x => x.ConcreteIdentifier == null && x.ObjectType == typeof(Foo));
var foos = Container.ResolveAll<IFoo>();
Assert.IsEqual(foos[0].Value, "a");
Assert.IsEqual(foos[1].Value, "b");
}
interface IFoo
{
string Value
{
get;
}
}
class Foo : IFoo
{
public Foo(string data)
{
Value = data;
}
public string Value
{
get; private set;
}
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 51d298299a99e3247aa3cc0b5caa1c88
timeCreated: 1523257672
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,41 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestIfNotBound : ZenjectUnitTestFixture
{
interface IFoo
{
}
public class Foo1 : IFoo
{
}
public class Foo2 : IFoo
{
}
[Test]
public void Test1()
{
Container.Bind<IFoo>().To<Foo1>().AsSingle();
Container.Bind<IFoo>().To<Foo2>().AsSingle();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count, 2);
}
[Test]
public void Test2()
{
Container.Bind<IFoo>().To<Foo1>().AsSingle();
Container.Bind<IFoo>().To<Foo2>().AsSingle().IfNotBound();
Assert.IsEqual(Container.ResolveAll<IFoo>().Count, 1);
Assert.IsType<Foo1>(Container.Resolve<IFoo>());
}
}
}
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 0fa385d656ffb584d8326240eb19c9f3
timeCreated: 1519798640
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 685a532a989c2f846b3fb97ea6c63b01
timeCreated: 1519798640
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,13 @@
fileFormatVersion: 2
guid: 7a57b8b648dfde647b2cc4de6e9ea944
timeCreated: 1519798640
licenseType: Free
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using System.Collections.Generic;
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestMultipleContractTypes : ZenjectUnitTestFixture
{
class Test1
{
}
class Test2 : Test1
{
}
class Test3 : Test1
{
}
class TestImpl1
{
public List<Test1> tests;
public TestImpl1(List<Test1> tests)
{
this.tests = tests;
}
}
class TestImpl2
{
[Inject]
public List<Test1> tests = null;
}
[Test]
public void TestMultiBind1()
{
Container.Bind<Test1>().To<Test2>().AsSingle().NonLazy();
Container.Bind<Test1>().To<Test3>().AsSingle().NonLazy();
Container.Bind<TestImpl1>().AsSingle().NonLazy();
var test1 = Container.Resolve<TestImpl1>();
Assert.That(test1.tests.Count == 2);
}
[Test]
public void TestMultiBindListInjection()
{
Container.Bind<Test1>().To<Test2>().AsSingle().NonLazy();
Container.Bind<Test1>().To<Test3>().AsSingle().NonLazy();
Container.Bind<TestImpl2>().AsSingle().NonLazy();
var test = Container.Resolve<TestImpl2>();
Assert.That(test.tests.Count == 2);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fb35253dbaabad84a815c3a9106cab8b
timeCreated: 1461708055
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,90 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestMultipleContractTypes2 : ZenjectUnitTestFixture
{
public class Bar
{
}
public interface IFoo
{
}
public interface IQux
{
}
public class Foo : IQux, IFoo
{
}
[Test]
public void Test1()
{
var types = new[]
{
typeof(Bar),
typeof(Foo)
};
Container.Bind(types).AsSingle().NonLazy();
Container.Resolve<Bar>();
Container.Resolve<Foo>();
}
[Test]
public void TestInterfaces()
{
Container.Bind<IFoo>().AsSingle().NonLazy();
Assert.Throws(() => Container.FlushBindings());
}
[Test]
public void TestAllInterfacesMistake()
{
Container.BindInterfacesTo<Foo>();
// Should require setting scope
Assert.Throws(() => Container.FlushBindings());
}
[Test]
public void TestAllInterfaces()
{
Container.BindInterfacesTo<Foo>().AsSingle().NonLazy();
Assert.IsNull(Container.TryResolve<Foo>());
Assert.IsNotNull(Container.Resolve<IFoo>());
Assert.IsNotNull(Container.Resolve<IQux>());
}
[Test]
public void TestAllInterfacesAndSelf()
{
Container.BindInterfacesAndSelfTo<Foo>().AsSingle().NonLazy();
Assert.IsNotNull(Container.Resolve<Foo>());
Assert.IsNotNull(Container.Resolve<IFoo>());
Assert.IsNotNull(Container.Resolve<IQux>());
}
[Test]
public void TestAllInterfacesAndSelfMistake()
{
Container.BindInterfacesAndSelfTo<Foo>();
// Should require setting scope
Assert.Throws(() => Container.FlushBindings());
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: b0c99e3d7ab1f7040b86e83fda23093b
timeCreated: 1461708052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,55 @@
using System.Collections.Generic;
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestMultipleContractTypes3 : ZenjectUnitTestFixture
{
class Test0
{
}
class Test3 : Test0
{
}
class Test4 : Test0
{
}
class Test2
{
public Test0 test;
public Test2(Test0 test)
{
this.test = test;
}
}
class Test1
{
public List<Test0> test;
public Test1(List<Test0> test)
{
this.test = test;
}
}
[Test]
public void TestMultiBind2()
{
// Multi-binds should not map to single-binds
Container.Bind<Test0>().To<Test3>().AsSingle().NonLazy();
Container.Bind<Test0>().To<Test4>().AsSingle().NonLazy();
Container.Bind<Test2>().AsSingle().NonLazy();
Assert.Throws(() => Container.Resolve<Test2>());
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a3c5d33d617b5d74386818cd004d2f3d
timeCreated: 1461708052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,45 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.Bindings
{
[TestFixture]
public class TestNonLazy : ZenjectUnitTestFixture
{
[Test]
public void Test1()
{
Container.Bind<Foo>().AsSingle().NonLazy();
Assert.Throws(() => Container.ResolveRoots());
}
[Test]
public void Test2()
{
Container.Bind<Foo>().AsSingle();
Container.ResolveRoots();
}
[Test]
public void Test3()
{
Container.Bind<Foo>().AsSingle().NonLazy();
Container.Bind<Bar>().AsSingle();
Container.ResolveRoots();
}
public class Foo
{
public Foo(Bar bar)
{
}
}
public class Bar
{
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: bd8592ec897336d4fb55f476488dfb1c
timeCreated: 1461708053
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,33 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestRebind : ZenjectUnitTestFixture
{
interface ITest
{
}
class Test2 : ITest
{
}
class Test3 : ITest
{
}
[Test]
public void Run()
{
Container.Bind<ITest>().To<Test2>().AsSingle();
Assert.That(Container.Resolve<ITest>() is Test2);
Container.Rebind<ITest>().To<Test3>().AsSingle();
Assert.That(Container.Resolve<ITest>() is Test3);
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 389794c3c2d66a24f9146f9071f398aa
timeCreated: 1464374481
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,62 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestUnbind : ZenjectUnitTestFixture
{
interface ITest
{
}
interface ITest2
{
}
class Test2 : ITest, ITest2
{
}
[Test]
public void Run()
{
Container.Bind<ITest>().To<Test2>().AsSingle();
Assert.IsNotNull(Container.Resolve<ITest>());
Container.Unbind<ITest>();
Assert.IsNull(Container.TryResolve<ITest>());
}
[Test]
public void TestUnbindInterfaces()
{
Container.BindInterfacesTo<Test2>().AsSingle();
Assert.IsNotNull(Container.Resolve<ITest>());
Assert.IsNotNull(Container.Resolve<ITest2>());
Container.UnbindInterfacesTo<Test2>();
Assert.IsNull(Container.TryResolve<ITest>());
Assert.IsNull(Container.TryResolve<ITest2>());
}
// Do we care about this?
//[Test]
public void TestUnbindAsSingle()
{
Container.Bind<ITest>().To<Test2>().AsSingle();
Container.Unbind<ITest>();
Assert.IsNull(Container.TryResolve<ITest>());
Container.Bind<ITest>().To<Test2>().AsSingle();
Assert.IsNotNull(Container.TryResolve<ITest>());
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 7bc1066beaa29be488a974f611aadf7f
timeCreated: 1464374492
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,57 @@
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestWithArguments : ZenjectUnitTestFixture
{
[Test]
public void Test1()
{
Container.Bind<Foo>().AsTransient().WithArguments(3).NonLazy();
Assert.IsEqual(Container.Resolve<Foo>().Value, 3);
}
[Test]
public void TestNullValues()
{
Container.Bind<Foo>().AsSingle().WithArguments(3, (string)null);
var foo = Container.Resolve<Foo>();
Assert.IsEqual(foo.Value, 3);
Assert.IsEqual(foo.Value2, null);
}
interface IFoo
{
}
class Foo : IFoo
{
public Foo(
int value,
[InjectOptional]
string value2)
{
Value = value;
Value2 = value2;
}
public int Value
{
get;
private set;
}
public string Value2
{
get;
private set;
}
}
}
}
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a9729dccd0a5529458a8ef18263587ae
timeCreated: 1461708052
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: