using System.Collections.Generic;
using NUnit.Framework;
namespace Zenject.Tests.BindFeatures
{
[TestFixture]
public class TestMultipleContractTypes : ZenjectUnitTestFixture
{
public class A
{ }
public class AA : A
{ }
public class BA : A
{ }
public class Test1
{
public List<A> tests;
[Inject]
public void Construct(List<A> tests)
{
this.tests = tests;
}
}
public class Test2
{
[Inject] public List<A> tests = null;
}
public class Test3
{
[Inject] public A tests = null;
}
[Test]
public void Test_multiple_bind()
{
Container.Bind<A>().To<AA>().AsSingle().NonLazy();
Container.Bind<A>().To<BA>().AsSingle().NonLazy();
Container.Bind<Test1>().AsSingle().NonLazy();
var test1 = Container.Resolve<Test1>();
Assert.That(test1.tests.Count == 2);
}
[Test]
public void Test_multiple_bind_list_injection()
{
Container.Bind<A>().To<AA>().AsSingle().NonLazy();
Container.Bind<A>().To<BA>().AsSingle().NonLazy();
Container.Bind<Test2>().AsSingle().NonLazy();
var test = Container.Resolve<Test2>();
Assert.That(test.tests.Count == 2);
}
[Test]
[ExpectedException]
public void Test_multiple_bind_single_injection()
{
Container.Bind<A>().To<AA>().AsSingle().NonLazy();
Container.Bind<A>().To<BA>().AsSingle().NonLazy();
Container.Bind<Test3>().AsSingle().NonLazy();
Container.Resolve<Test3>();
}
}
}