コード例 #1
0
        public void GetInstanceThrowsActivationExceptionWhenComponentNotFound()
        {
            var container = new ContainerMock();
            var adapter   = new CommonServiceLocatorAdapter(container);

            container.AddExpectation("Resolve", () =>
            {
                throw new ServiceNotFoundException(typeof(IService));
            });
            Assert.Throws <ActivationException>(() => adapter.GetInstance <IService>());
        }
コード例 #2
0
        public void GetInstanceThrowsActivationExceptionWhenComponentNotFound()
        {
            var container = new ContainerMock();
            var adapter = new CommonServiceLocatorAdapter(container);
            container.AddExpectation("Resolve", () =>
                                                           {
                                                               throw new ServiceNotFoundException(typeof(IService));

                                                           });
            Assert.Throws<ActivationException>(() => adapter.GetInstance<IService>());
        }
コード例 #3
0
        public void GetInstanceTranslatesToResolveOnContainer()
        {
            var container = new ContainerMock();
            var weakResolveWasCalled = false;
            container.AddExpectation("Resolve", () =>
                                                    {
                                                        weakResolveWasCalled = true;
                                                        return new ClassWithNoDependencies();
                                                    });

            var adapter = new CommonServiceLocatorAdapter(container);
            adapter.GetInstance<IService>();

            Assert.True(weakResolveWasCalled);
        }
コード例 #4
0
        public void GetInstanceTranslatesToResolveOnContainer()
        {
            var container            = new ContainerMock();
            var weakResolveWasCalled = false;

            container.AddExpectation("Resolve", () =>
            {
                weakResolveWasCalled = true;
                return(new ClassWithNoDependencies());
            });

            var adapter = new CommonServiceLocatorAdapter(container);

            adapter.GetInstance <IService>();

            Assert.True(weakResolveWasCalled);
        }