Initial Commit
This commit is contained in:
+68
@@ -0,0 +1,68 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsBasic : ZenjectUnitTestFixture
|
||||
{
|
||||
public interface IFoo
|
||||
{
|
||||
}
|
||||
|
||||
class Foo1 : IFoo
|
||||
{
|
||||
}
|
||||
|
||||
class Foo2 : IFoo
|
||||
{
|
||||
}
|
||||
|
||||
class Bar1
|
||||
{
|
||||
public IFoo Foo;
|
||||
|
||||
public Bar1(IFoo foo)
|
||||
{
|
||||
Foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
class Bar2
|
||||
{
|
||||
public IFoo Foo;
|
||||
|
||||
public Bar2(IFoo foo)
|
||||
{
|
||||
Foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test1()
|
||||
{
|
||||
Container.Bind<Bar1>().AsSingle().NonLazy();
|
||||
Container.Bind<Bar2>().AsSingle().NonLazy();
|
||||
Container.Bind<IFoo>().To<Foo1>().AsSingle().NonLazy();
|
||||
Container.Bind<IFoo>().To<Foo2>().AsSingle().WhenInjectedInto<Bar2>().NonLazy();
|
||||
|
||||
Assert.IsNotEqual(
|
||||
Container.Resolve<Bar1>().Foo, Container.Resolve<Bar2>().Foo);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Test2()
|
||||
{
|
||||
Container.Bind<Bar1>().AsSingle().NonLazy();
|
||||
Container.Bind<Bar2>().AsSingle().NonLazy();
|
||||
Container.Bind<IFoo>().To<Foo1>().AsSingle().NonLazy();
|
||||
Container.Bind<IFoo>().To<Foo2>().AsSingle().WhenNotInjectedInto<Bar1>().NonLazy();
|
||||
|
||||
Assert.IsNotEqual(
|
||||
Container.Resolve<Bar1>().Foo, Container.Resolve<Bar2>().Foo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb63718e40b7bd429fc93d4542aaf01
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsComplex : ZenjectUnitTestFixture
|
||||
{
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
class Bar
|
||||
{
|
||||
public Foo Foo;
|
||||
|
||||
public Bar(Foo foo)
|
||||
{
|
||||
Foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCorrespondingIdentifiers()
|
||||
{
|
||||
var foo1 = new Foo();
|
||||
var foo2 = new Foo();
|
||||
|
||||
Container.Bind<Bar>().WithId("Bar1").AsTransient().NonLazy();
|
||||
Container.Bind<Bar>().WithId("Bar2").AsTransient().NonLazy();
|
||||
|
||||
Container.BindInstance(foo1).When(c => c.ParentContexts.Where(x => x.MemberType == typeof(Bar) && Equals(x.Identifier, "Bar1")).Any());
|
||||
Container.BindInstance(foo2).When(c => c.ParentContexts.Where(x => x.MemberType == typeof(Bar) && Equals(x.Identifier, "Bar2")).Any());
|
||||
|
||||
Assert.IsEqual(Container.ResolveId<Bar>("Bar1").Foo, foo1);
|
||||
Assert.IsEqual(Container.ResolveId<Bar>("Bar2").Foo, foo2);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f34becbac266acf42a68abcd73423b00
|
||||
timeCreated: 1461708055
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsFieldName : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
class Test1
|
||||
{
|
||||
public Test1(Test0 name1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Test2
|
||||
{
|
||||
public Test2(Test0 name2)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
Container.Bind<Test0>().AsSingle().When(r => r.MemberName == "name1");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNameConditionError()
|
||||
{
|
||||
Container.Bind<Test2>().AsSingle().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test2>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestNameConditionSuccess()
|
||||
{
|
||||
Container.Bind<Test1>().AsSingle().NonLazy();
|
||||
|
||||
var test1 = Container.Resolve<Test1>();
|
||||
|
||||
Assert.That(test1 != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6eacf4d3f8215d54dadba7ba02a91fbf
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+144
@@ -0,0 +1,144 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsIdentifier : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
}
|
||||
|
||||
class Test1
|
||||
{
|
||||
public Test1(
|
||||
[Inject(Id ="foo")]
|
||||
Test0 name1)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Test2
|
||||
{
|
||||
[Inject(Id ="foo")]
|
||||
public Test0 name2 = null;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUnspecifiedNameConstructorInjection()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test0>().AsTransient().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test1>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestUnspecifiedNameFieldInjection()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test2>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().AsTransient().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test2>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSuccessConstructorInjectionString()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test2>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("foo").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
// Should not throw exceptions
|
||||
Container.Resolve<Test1>();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test1>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSuccessFieldInjectionString()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test2>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("foo").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test2>());
|
||||
}
|
||||
|
||||
class Test3
|
||||
{
|
||||
public Test3(
|
||||
[Inject(Id ="TestValue2")]
|
||||
Test0 test0)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Test4
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFailConstructorInjectionEnum()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test2>().AsTransient().NonLazy();
|
||||
Container.Bind<Test3>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("TestValue1").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test3>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSuccessConstructorInjectionEnum()
|
||||
{
|
||||
Container.Bind<Test3>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("TestValue2").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
// No exceptions
|
||||
Container.Resolve<Test3>();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test3>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFailFieldInjectionEnum()
|
||||
{
|
||||
Container.Bind<Test1>().AsTransient().NonLazy();
|
||||
Container.Bind<Test2>().AsTransient().NonLazy();
|
||||
Container.Bind<Test3>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("TestValue1").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test3>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestSuccessFieldInjectionEnum()
|
||||
{
|
||||
Container.Bind<Test4>().AsTransient().NonLazy();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(new Test0()).NonLazy();
|
||||
Container.Bind<Test0>().WithId("TestValue3").FromInstance(new Test0()).NonLazy();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test4>());
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a3c3d9696613b32448c9d67ce36945e8
|
||||
timeCreated: 1461708052
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsParents : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
}
|
||||
|
||||
interface ITest1
|
||||
{
|
||||
}
|
||||
|
||||
class Test1 : ITest1
|
||||
{
|
||||
public Test0 test0;
|
||||
|
||||
public Test1(Test0 test0)
|
||||
{
|
||||
this.test0 = test0;
|
||||
}
|
||||
}
|
||||
|
||||
class Test2 : ITest1
|
||||
{
|
||||
public Test0 test0;
|
||||
|
||||
public Test2(Test0 test0)
|
||||
{
|
||||
this.test0 = test0;
|
||||
}
|
||||
}
|
||||
|
||||
class Test3 : ITest1
|
||||
{
|
||||
public Test1 test1;
|
||||
|
||||
public Test3(Test1 test1)
|
||||
{
|
||||
this.test1 = test1;
|
||||
}
|
||||
}
|
||||
|
||||
class Test4 : ITest1
|
||||
{
|
||||
public Test1 test1;
|
||||
|
||||
public Test4(Test1 test1)
|
||||
{
|
||||
this.test1 = test1;
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCase1()
|
||||
{
|
||||
Container.Bind<Test1>().AsSingle().NonLazy();
|
||||
Container.Bind<Test0>().AsSingle().When(c => c.AllObjectTypes.Contains(typeof(Test2)));
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test1>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCase2()
|
||||
{
|
||||
Container.Bind<Test1>().AsSingle().NonLazy();
|
||||
Container.Bind<Test0>().AsSingle().When(c => c.AllObjectTypes.Contains(typeof(Test1)));
|
||||
|
||||
var test1 = Container.Resolve<Test1>();
|
||||
Assert.That(test1 != null);
|
||||
}
|
||||
|
||||
// Test using parents to look deeper up the heirarchy..
|
||||
[Test]
|
||||
public void TestCase3()
|
||||
{
|
||||
var t0a = new Test0();
|
||||
var t0b = new Test0();
|
||||
|
||||
Container.Bind<Test3>().AsSingle();
|
||||
Container.Bind<Test4>().AsSingle();
|
||||
Container.Bind<Test1>().AsTransient();
|
||||
|
||||
Container.Bind<Test0>().FromInstance(t0a).When(c => c.AllObjectTypes.Contains(typeof(Test3)));
|
||||
Container.Bind<Test0>().FromInstance(t0b).When(c => c.AllObjectTypes.Contains(typeof(Test4)));
|
||||
|
||||
var test3 = Container.Resolve<Test3>();
|
||||
|
||||
var test4 = Container.Resolve<Test4>();
|
||||
|
||||
Assert.That(ReferenceEquals(test3.test1.test0, t0a));
|
||||
Assert.That(ReferenceEquals(test4.test1.test0, t0b));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCase4()
|
||||
{
|
||||
Container.Bind<ITest1>().To<Test2>().AsSingle().NonLazy();
|
||||
Container.Bind<Test0>().AsSingle().When(c => c.AllObjectTypes.Contains(typeof(ITest1)));
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<ITest1>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCase5()
|
||||
{
|
||||
Container.Bind<ITest1>().To<Test2>().AsSingle().NonLazy();
|
||||
Container.Bind<Test0>().AsSingle().When(c => c.AllObjectTypes.Contains(typeof(Test2)));
|
||||
|
||||
var test1 = Container.Resolve<ITest1>();
|
||||
Assert.That(test1 != null);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCase6()
|
||||
{
|
||||
Container.Bind<ITest1>().To<Test2>().AsSingle().NonLazy();
|
||||
Container.Bind<Test0>().AsSingle().When(c => c.AllObjectTypes.Where(x => typeof(ITest1).IsAssignableFrom(x)).Any());
|
||||
|
||||
var test1 = Container.Resolve<ITest1>();
|
||||
Assert.That(test1 != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 12290b4e2fc99dd4197a95555c4b7742
|
||||
timeCreated: 1461708048
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsTarget : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
}
|
||||
|
||||
class Test1
|
||||
{
|
||||
public Test1(Test0 test)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
class Test2
|
||||
{
|
||||
public Test2(Test0 test)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
Container.Bind<Test0>().AsSingle().When(r => r.ObjectType == typeof(Test2));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTargetConditionError()
|
||||
{
|
||||
Container.Bind<Test1>().AsSingle().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test1>(); });
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTargetConditionSuccess()
|
||||
{
|
||||
Container.Bind<Test2>().AsSingle().NonLazy();
|
||||
|
||||
var test2 = Container.Resolve<Test2>();
|
||||
|
||||
Assert.That(test2 != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fa53be31526be634795d3b724199e7ea
|
||||
timeCreated: 1461708055
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestConditionsTargetInstance : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
}
|
||||
|
||||
class Test1
|
||||
{
|
||||
[Inject]
|
||||
public Test0 test0 = null;
|
||||
}
|
||||
|
||||
Test1 _test1;
|
||||
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
|
||||
_test1 = new Test1();
|
||||
Container.Bind<Test0>().AsSingle().When(r => r.ObjectInstance == _test1);
|
||||
Container.Bind<Test1>().FromInstance(_test1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestTargetConditionError()
|
||||
{
|
||||
Container.Inject(_test1);
|
||||
|
||||
Assert.That(_test1.test0 != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0f79fbd0fa046ae429a33becfec16c75
|
||||
timeCreated: 1461708048
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestIdentifierTypes : ZenjectUnitTestFixture
|
||||
{
|
||||
class Foo
|
||||
{
|
||||
}
|
||||
|
||||
enum Things
|
||||
{
|
||||
Thing1,
|
||||
Thing2
|
||||
}
|
||||
|
||||
class Test0
|
||||
{
|
||||
public Test0(
|
||||
[Inject(Id = "asdf")]
|
||||
Foo foo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestStringIdentifiers1()
|
||||
{
|
||||
Container.Bind<Foo>().AsTransient();
|
||||
Container.Bind<Test0>().AsTransient();
|
||||
|
||||
Assert.Throws(() => Container.Resolve<Test0>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestStringIdentifiers2()
|
||||
{
|
||||
Container.Bind<Foo>().WithId("asdf").AsTransient();
|
||||
Container.Bind<Test0>().AsTransient();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test0>());
|
||||
}
|
||||
|
||||
class Test1
|
||||
{
|
||||
public Test1(
|
||||
[Inject(Id = 5)]
|
||||
Foo foo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIntIdentifiers1()
|
||||
{
|
||||
Container.Bind<Foo>().AsTransient();
|
||||
Container.Bind<Test1>().AsTransient();
|
||||
|
||||
Assert.Throws(() => Container.Resolve<Test1>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIntIdentifiers2()
|
||||
{
|
||||
Container.Bind<Foo>().WithId(4).AsTransient();
|
||||
Container.Bind<Test1>().AsTransient();
|
||||
|
||||
Assert.Throws(() => Container.Resolve<Test1>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestIntIdentifiers3()
|
||||
{
|
||||
Container.Bind<Foo>().WithId(5).AsTransient();
|
||||
Container.Bind<Test1>().AsTransient();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test1>());
|
||||
}
|
||||
|
||||
class Test2
|
||||
{
|
||||
public Test2(
|
||||
[Inject(Id = Things.Thing1)]
|
||||
Foo foo)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumIdentifiers1()
|
||||
{
|
||||
Container.Bind<Foo>().AsTransient();
|
||||
Container.Bind<Test2>().AsTransient();
|
||||
|
||||
Assert.Throws(() => Container.Resolve<Test2>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumIdentifiers2()
|
||||
{
|
||||
Container.Bind<Foo>().WithId(Things.Thing2).AsTransient();
|
||||
Container.Bind<Test2>().AsTransient();
|
||||
|
||||
Assert.Throws(() => Container.Resolve<Test2>());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestEnumIdentifiers3()
|
||||
{
|
||||
Container.Bind<Foo>().WithId(Things.Thing1).AsTransient();
|
||||
Container.Bind<Test2>().AsTransient();
|
||||
|
||||
Assert.IsNotNull(Container.Resolve<Test2>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9bc24db5ed5a5d047af12bf9c81319bb
|
||||
timeCreated: 1537241991
|
||||
licenseType: Free
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,69 @@
|
||||
using NUnit.Framework;
|
||||
using Assert = ModestTree.Assert;
|
||||
|
||||
namespace Zenject.Tests.Conditions
|
||||
{
|
||||
[TestFixture]
|
||||
public class TestIdentifiers : ZenjectUnitTestFixture
|
||||
{
|
||||
class Test0
|
||||
{
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic()
|
||||
{
|
||||
Container.Bind<Test0>().WithId("foo").AsTransient().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test0>(); });
|
||||
|
||||
Container.ResolveId<Test0>("foo");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic2()
|
||||
{
|
||||
Container.Bind<Test0>().WithId("foo").AsSingle().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test0>(); });
|
||||
|
||||
Container.ResolveId<Test0>("foo");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic3()
|
||||
{
|
||||
Container.Bind<Test0>().WithId("foo").FromMethod(ctx => new Test0()).NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test0>(); });
|
||||
|
||||
Container.ResolveId<Test0>("foo");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestBasic4()
|
||||
{
|
||||
Container.Bind<Test0>().WithId("foo").AsTransient().NonLazy();
|
||||
Container.Bind<Test0>().WithId("foo").AsTransient().NonLazy();
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.Resolve<Test0>(); });
|
||||
|
||||
Assert.Throws(
|
||||
delegate { Container.ResolveId<Test0>("foo"); });
|
||||
|
||||
Assert.IsEqual(Container.ResolveIdAll<Test0>("foo").Count, 2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestFromMethodUntyped()
|
||||
{
|
||||
Container.Bind(typeof(Test0)).FromMethod(ctx => new Test0()).NonLazy();
|
||||
|
||||
Container.Resolve<Test0>();
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 644729bec6228dd46a175eab4d04637a
|
||||
timeCreated: 1461708051
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user