using JamesKovacs.IoCArticle.IoCContainer.Infrastructure.Container;
using JamesKovacs.IoCArticle.IoCContainer.Services;
using MbUnit.Framework;

namespace JamesKovacs.IoCArticle.IoCContainer.Tests.Unit.Infrastructure.Container {
    [TestFixture]
    public class IoCTests {
        [TearDown]
        public void TearDown() {
            IoC.Initialize(null);
        }

        [Test]
        public void CanResolveDependencyWithSimpleHashtable() {
            SimpleDependencyResolver resolver = new SimpleDependencyResolver();
            resolver.Register<IFoo>(new Foo());
            IoC.Initialize(resolver);
            IFoo foo = IoC.Resolve<IFoo>();
            Assert.IsInstanceOfType(typeof(Foo), foo);
        }

        [Test]
        public void CanResolveDependencyWithWindsor() {
            WindsorDependencyResolver resolver = new WindsorDependencyResolver(@".\Unit\Infrastructure\Container\Windsor.config");
            IoC.Initialize(resolver);
            IFoo foo = IoC.Resolve<IFoo>();
            Assert.IsInstanceOfType(typeof(Foo), foo);
        }

        [Test]
        public void CanResolveDependencyWithBinsor() {
            RhinoDependencyResolver resolver = new RhinoDependencyResolver(@".\Unit\Infrastructure\Container\Windsor.boo");
            IoC.Initialize(resolver);
            IFoo foo = IoC.Resolve<IFoo>();
            Assert.IsInstanceOfType(typeof(Foo), foo);
        }

        [Test]
        public void CanResolveDependencyWithBinsorConventionOverConfiguration() {
            RhinoDependencyResolver resolver = new RhinoDependencyResolver(@".\Unit\Infrastructure\Container\Windsor2.boo");
            IoC.Initialize(resolver);
            IInvoiceService foo = IoC.Resolve<IInvoiceService>();
            Assert.IsInstanceOfType(typeof(InvoiceService), foo);
        }
    }
}