예제 #1
0
        public void ShouldCreateTreeWithAComplexArrangementOfFactories()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly("MultipleCallsTestData", "ComplexFactory");
            (object factory1, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.ComplexFactory", assemblies: new Assembly[] { assembly });
            IResultGetter result = factory1 as IResultGetter;

            ;
            Assert.IsNotNull(result.GetResults()?.ChildOne);
            Assert.IsNotNull(result.GetResults()?.ChildTwo);
            Assert.IsNotNull(((IResultGetter)result.GetResults()?.ChildOne)?.GetResults().ChildTwo);
            Assert.AreEqual(result?.GetResults().ChildTwo
                            , ((IResultGetter)result.GetResults()?.ChildOne)?.GetResults().ChildTwo);
        }
예제 #2
0
        public void ShouldAddFactoryCreatedParameterBeansToInjectionState()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly(
                "MultipleCallsTestData", "FactoryMadeWithConstructor");
//            Assembly assembly = this.GetType().Assembly;
//            var pdi = new DependencyInjector();
            (object fmwc, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.FactoryMadeWithConstructor", assemblies: new Assembly[] { assembly });
            IResultGetter result = fmwc as IResultGetter;

            Assert.AreEqual(1, result?.GetResults().FurthestCtr);
            (object furthest, _)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.MultipleCallsTestData.Furthest", injectionState: injectionState, assemblies: new Assembly[] { assembly });
            Assert.AreEqual(1, result?.GetResults().FurthestCtr);
        }
예제 #3
0
        public void ShouldCreateLinuxTypesOnLinux()
        {
            (DependencyInjector pdi, Assembly assembly) = Utils.CreateIOCCinAssembly("TestData", "CrossPlatform");
            (object rootBean, InjectionState injectionState)
                = pdi.CreateAndInjectDependencies("IOCCTest.TestData.CrossPlatform"
                                                  , assemblies: new Assembly[] { assembly });
            IResultGetter result = rootBean as IResultGetter;

#if WINDOWSTEST
            Assert.IsNotNull(result.GetResults().Windows, "try \"dotnet run -c LinuxTest\" or \"dotnet run -c MacOsTest\"");
#endif
#if LINUXTEST
            Assert.IsNotNull(result.GetResults().Linux);
#endif
#if MACOSTEST
            Assert.IsNotNull(result.GetResults().Macos);
#endif
        }
예제 #4
0
        public void ShouldCreateTreeWithNamedRootConstructor()
        {
            (DependencyInjector pdi, Assembly assembly) =
                CreateIOCCinAssembly(CONSTRUCTOR_TEST_NAMESPACE
                                     , "NamedRootConstructor");
            (object bean, InjectionState injectionState) = pdi.CreateAndInjectDependencies(
                "IOCCTest.ConstructorTestData.NamedRootConstructor"
                , assemblies: new Assembly[] { assembly }
                , rootBeanSpec: new RootBeanSpec(rootConstructorName: "TestConstructor"));
            Diagnostics   diagnostics = injectionState.Diagnostics;
            IResultGetter result      = bean as IResultGetter;

            System.Diagnostics.Debug.WriteLine(diagnostics);
            Assert.AreEqual("stuff", result?.GetResults().Stuff);
            Assert.IsFalse(Falsify(diagnostics.HasWarnings));
        }
예제 #5
0
        public void ShouldCreateTreeWithDerivedConstructor()
        {
            (PDependencyInjector pdi, Assembly assembly) =
                CreateIOCCinAssembly(DERIVED_ATTRIBUTE_TEST_NAMESPACE
                                     , "DerivedConstructor");
            (object obj, InjectionState InjectionState)
                = pdi.CreateAndInjectDependencies(
                      "IOCCTest.DerivedAttributeTestData.DerivedConstructor"
                      , assemblies: new Assembly[] { assembly }
                      , rootBeanSpec: new RootBeanSpec(rootConstructorName: "TestConstructor"));
            IResultGetter result      = obj as IResultGetter;
            Diagnostics   diagnostics = InjectionState.Diagnostics;

            System.Diagnostics.Debug.WriteLine(diagnostics);
            Assert.AreEqual("somestuff", result?.GetResults().Stuff);
            Assert.IsFalse(Falsify(diagnostics.HasWarnings));
        }