示例#1
0
        public void InstanceResolveTest()
        {
            InvertContainer container = new InvertContainer();

            container.Register <MockDependency>();

            MockDependency dependency1 = container.Resolve <MockDependency>();
            MockDependency dependency2 = container.Resolve <MockDependency>();

            Assert.NotSame(dependency1, dependency2);
        }
示例#2
0
        public void SingletonResolveTest()
        {
            InvertContainer container = new InvertContainer();

            container.Register <MockDependency>().Singleton();

            MockDependency dependency1 = container.Resolve <MockDependency>();
            MockDependency dependency2 = container.Resolve <MockDependency>();

            Assert.Same(dependency1, dependency2);
        }
示例#3
0
        public void DependencyWithNoConstructorTest()
        {
            InvertContainer container = new InvertContainer();

            container.Register <BadMockDependency>();

            Assert.Throws <MissingMethodException>(() => { container.Resolve <BadMockDependency>(); });
        }
示例#4
0
        public void NestedDependencyMissingResolveTest()
        {
            InvertContainer container = new InvertContainer();

            container.Register <MockParentDependency>();

            Assert.Throws <DependencyNotFoundException>(() => { container.Resolve <MockParentDependency>(); });
        }
示例#5
0
        public void NestedDependencyResolveTest()
        {
            InvertContainer container = new InvertContainer();

            container.Register <MockParentDependency>();
            container.Register <MockChildDependency>();

            Assert.NotNull(container.Resolve <MockParentDependency>());
        }
示例#6
0
        static void Main(string[] args)
        {
            InvertContainer container = new InvertContainer();

            container.Register <IFoo>().To <Foo>();

            Console.WriteLine(container.Resolve <IFoo>());

            Console.ReadKey();
        }
示例#7
0
        public void DependencyMissingTest()
        {
            InvertContainer container = new InvertContainer();

            Assert.Throws <DependencyNotFoundException>(() => { container.Resolve <MockDependency>(); });
        }