Esempio n. 1
0
        public void Container_Register_AddsMappingToList()
        {
            var container = new Yadndil.Container();

            container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
            Assert.AreEqual(1, container._mapping.Count);
        }
Esempio n. 2
0
        public void Container_Get_CanCallInterfaceMethod()
        {
            var container = new Yadndil.Container();

            container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
            var result = container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>();

            Assert.AreEqual("Hi!", result.PrintSomething());
        }
Esempio n. 3
0
        public void Container_Get_ReturnsImplementationWhenConstructorIsEmpty()
        {
            var container = new Yadndil.Container();

            container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
            var result = container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>();

            Assert.IsInstanceOf <TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>(result);
        }
Esempio n. 4
0
        public void Container_Get_ExceptionWhenNotMapped()
        {
            var container = new Yadndil.Container();

            Assert.Throws <Exception>(() =>
            {
                container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor>();
            });
        }
Esempio n. 5
0
        public void Container_Get_ExceptionWhenFirstParameterIsNotInterface()
        {
            var container = new Yadndil.Container();

            Assert.Throws <ArgumentException>(() =>
            {
                container.Get <TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
            });
        }
Esempio n. 6
0
        public void Container_Register_ThrowsWhenInterfaceHasAlreadyBeenAdded()
        {
            var container = new Yadndil.Container();

            Assert.Throws <Exception>(() =>
            {
                container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
                container.Register <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithEmptyConstructor, TypesForTests.ContainerTestTypes.ClassForContainerTestsWithEmptyConstructor>();
            });
        }
Esempio n. 7
0
        public void Container_FinishRegistering_CircularReferenceCausesStackOverflow()
        {
            var container = new Yadndil.Container();

            Assert.Throws <Exception>(() =>
            {
                container.Register <TypesForTests.ContainerTestTypes.IInterafce1ForStackOverflow, TypesForTests.ContainerTestTypes.Class1ForStackOverflow>();
                container.Register <TypesForTests.ContainerTestTypes.IInterafce2ForStackOverflow, TypesForTests.ContainerTestTypes.Class2ForStackOverflow>();
                container.Get <TypesForTests.ContainerTestTypes.IInterfaceForContainerTestsWithNonEmptyConstructor>();
            });
        }