Exemplo n.º 1
0
        public void TestResolveUnregisteredType()
        {
            IWTWContainer container    = new WTWContainer();
            TestDelegate  testFunction = delegate() { container.Resolve <ICalculator>(); };

            Assert.Catch(testFunction);
        }
Exemplo n.º 2
0
        public void TestSimpleTypeResolutionWithParameter()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>();

            var calc = container.Resolve(typeof(ICalculator));

            Assert.IsNotNull(calc);
        }
Exemplo n.º 3
0
        public static void Register(HttpConfiguration config)
        {
            var container = new WTWContainer();

            // Register types.
            container.Register <ResumeController, ResumeController>();
            container.Register <IResumeRepository, ResumeRepositoryXml>();

            // Set the DependencyResolver to enable dependency injection in WebAPI controllers.
            config.DependencyResolver = new WTWDependencyResolver(container);
        }
Exemplo n.º 4
0
        public void TestTransientLifecycleIsDefault()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>();

            var calc1 = container.Resolve <ICalculator>();
            var calc2 = container.Resolve <ICalculator>();

            Assert.AreNotSame(calc1, calc2);
        }
Exemplo n.º 5
0
        public void TestSingletonLifecycle()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>(new SingletonLifeTimeManager());

            var calc1 = container.Resolve <ICalculator>();
            var calc2 = container.Resolve <ICalculator>();

            Assert.AreSame(calc1, calc2);
        }
Exemplo n.º 6
0
        public void TestPartiallyRegisteredParameterizedConstructorResolution()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>();
            // Missing registration of email service.
            container.Register <IUsersController, UsersController>();

            TestDelegate testFunction = delegate() { container.Resolve <IUsersController>(); };

            Assert.Catch(testFunction);
        }
Exemplo n.º 7
0
        public void TestParameterizedConstructorResolution()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>();
            container.Register <IEmailService, EmailService>();
            container.Register <IUsersController, UsersController>();

            var ctrl = container.Resolve <IUsersController>();

            Assert.IsNotNull(ctrl);
        }
Exemplo n.º 8
0
        public void TestSimpleTypeRegistration()
        {
            IWTWContainer container = new WTWContainer();

            container.Register <ICalculator, Calculator>();
        }