using NUnit.Framework; using Assert = ModestTree.Assert; namespace Zenject.Tests.Bindings { [TestFixture] public class TestFromInstance : ZenjectUnitTestFixture { [Test] public void TestTransient() { var foo = new Foo(); Container.Bind().FromInstance(foo).NonLazy(); Container.Bind().FromInstance(foo).NonLazy(); Assert.IsEqual(Container.Resolve(), Container.Resolve()); Assert.IsEqual(Container.Resolve(), foo); } [Test] public void TestSingle() { Container.Bind().FromInstance(new Foo()).AsSingle().NonLazy(); Container.Bind().AsSingle().NonLazy(); Assert.Throws(() => Container.FlushBindings()); } // There's really no good reason to do this but it is part of the api [Test] public void TestCached() { var foo = new Foo(); Container.Bind().FromInstance(foo).AsSingle().NonLazy(); Container.Bind().FromInstance(foo).AsSingle().NonLazy(); Assert.IsEqual(Container.Resolve(), Container.Resolve()); Assert.IsEqual(Container.Resolve(), foo); } interface IFoo { } class Foo : IFoo { } } }