100coding
5/6/2017 - 5:32 AM

D52FB56F-AAC5-49C2-8715-3592CC672AC5

D52FB56F-AAC5-49C2-8715-3592CC672AC5

using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;

namespace Zenject.Tests.BindFeatures
{
    [TestFixture]
    public class TestMultipleContractTypes : ZenjectUnitTestFixture
    {
        private class Test1
        { }

        private class Test2 : Test1
        { }

        private class Test3 : Test1
        { }

        private class Test4
        {
            public readonly List<Test1> tests;

            public Test4(List<Test1> tests)
            {
                this.tests = tests;
            }
        }

        private class Test5
        {
            [Inject] public List<Test1> tests;
        }

        [Test]
        public void Test_multibind_with_constructor_injection()
        {
            Container.Bind<Test1>().To<Test2>().AsSingle().NonLazy();
            Container.Bind<Test1>().To<Test3>().AsSingle().NonLazy();
            Container.Bind<Test4>().AsSingle().NonLazy();

            var test4 = Container.Resolve<Test4>();

            Assert.AreEqual(test4.tests.Count, 2);
        }

        [Test]
        public void Test_multibind_with_field_injection()
        {
            Container.Bind<Test1>().To<Test2>().AsSingle().NonLazy();
            Container.Bind<Test1>().To<Test3>().AsSingle().NonLazy();
            Container.Bind<Test5>().AsSingle().NonLazy();

            var test5 = Container.Resolve<Test5>();

            Assert.AreEqual(test5.tests.Count, 2);
        }
    }
}