060CC82C-9A7A-4364-BBCA-B65CB7C9AE76
using System;
using NUnit.Framework;
using Assert = ModestTree.Assert;
namespace Zenject.Tests.BindFeatures
{
public class TestMultipleContractType : ZenjectUnitTestFixture
{
public class Bar
{ }
public interface IFoo
{ }
public interface IQux
{ }
public class Foo : IQux, IFoo
{ }
[Test]
public void Test_contract_type_list()
{
var types = new Type[]
{
typeof(Bar),
typeof(Foo)
};
Container.Bind(types)
.AsSingle()
.NonLazy();
Container.Resolve<Bar>();
Container.Resolve<Foo>();
}
[Test]
public void Test_interfaces()
{
Container.Bind<IFoo>()
.AsSingle()
.NonLazy();
Assert.Throws(() => Container.FlushBindings());
}
[Test]
public void Test_all_interfaces_misktake()
{
Container.BindInterfacesTo<Foo>();
// Scop를 Setting해야 한다.
Assert.Throws(() => Container.FlushBindings());
}
[Test]
public void Test_all_interfaces()
{
Container.BindInterfacesTo<Foo>()
.AsSingle()
.NonLazy();
Assert.IsNull(Container.TryResolve<Foo>());
Assert.IsNotNull(Container.Resolve<IFoo>());
Assert.IsNotNull(Container.Resolve<IQux>());
}
[Test]
public void Test_all_interfaces_and_self_mistake()
{
Container.BindInterfacesAndSelfTo<Foo>();
// Scrop를 Setting해야 한다.
Assert.Throws(() => Container.FlushBindings());
}
[Test]
public void Test_all_interfaces_and_self()
{
Container.BindInterfacesAndSelfTo<Foo>()
.AsSingle()
.NonLazy();
Assert.IsNotNull(Container.Resolve<Foo>());
Assert.IsNotNull(Container.Resolve<IFoo>());
Assert.IsNotNull(Container.Resolve<IQux>());
}
}
}