Esempio n. 1
0
        public void testObjectBuilder()
        {
            var testString = "testString";
            var methodToCall = "getTest";
            var extraText = "extraText";
            var o2Assembly = new O2ObjectFactory(Assembly.GetExecutingAssembly().Location);

            var constructorParameters = new object[] {};

            O2Object usingFullTypeName = o2Assembly.ctor("O2.UnitTests.Test_O2CoreLib.O2Core.O2CoreLib.Reflection.ReflectTest");
            Assert.That(usingFullTypeName != null, "reflectTestClass == null");
            O2Object usingShortTypeName = o2Assembly.ctor("ReflectTest", constructorParameters);
            Assert.That(usingShortTypeName != null, "usingShortTypeName  == null");
            object methodToCallValue = usingShortTypeName.call(methodToCall);
            Assert.That(methodToCallValue != null, "usingShortTypeName.methodToCallValue == null");
            string reflectionValue = new ReflectTest().getTest();
            Assert.That(methodToCallValue.ToString() == reflectionValue, methodToCallValue + " != " + reflectionValue);

            O2Object usingShortTypeWithStringParam = o2Assembly.ctor("ReflectTest", new object[] {testString});
            Assert.That(usingShortTypeWithStringParam != null, "usingShortTypeWithStringParam  == null");
            methodToCallValue = usingShortTypeWithStringParam.call(methodToCall);
            Assert.That(methodToCallValue != null, "usingShortTypeWithStringParam.methodToCallValue == null");
            reflectionValue = new ReflectTest(testString).getTest();
            Assert.That(methodToCallValue.ToString() == reflectionValue, methodToCallValue + " != " + reflectionValue);

            methodToCallValue = usingShortTypeWithStringParam.call(methodToCall, new object[] {extraText});
            reflectionValue = new ReflectTest(testString).getTest(extraText);
            Assert.That(methodToCallValue.ToString() == reflectionValue,
                        "(extraText) " + methodToCallValue + " != " + extraText);
        }
Esempio n. 2
0
        /* public void startNunitInSeparateAppDomain(string fileToLoad)
        {
           // var args = new[] {  fileToLoad}; // (O2CorLib.dll) assembly that will be loaded and searched for Unit tests                                        
            var args = new string[] {}; 
            string exeToRun = Path.Combine(pathToNUnitBinFolder, "nunit-x86.exe");
            appDomain = AppDomainUtils.newAppDomain_ExecuteAssembly("nUnitExec", pathToNUnitBinFolder, exeToRun, args);
        }*/


        // ReSharper restore SuggestUseVarKeywordEvident


        /*  public bool isAttached
        {
            get { return NUnitControl != null; }
        }*/

        /*   public Control NUnitControl
        {
            get
            {
                if (nUnitRunnerDll == null)
                    loadNUnitDll();

                //return null;
                var label = new Label {Text = "aaaaaaaaaa"};
                return label;
            }
        }*/


        // On this one lets not use var keywords (since that will make it easier to understand what is going on)
        // ReSharper disable SuggestUseVarKeywordEvident             
        public Form getMainForm()
        {
            var nUnitGuiRunner = new O2ObjectFactory(NUnitGuiRunnerDll);
            var nUnitUtil = new O2ObjectFactory(nUnitUtilDll);
            var nUnitUikit = new O2ObjectFactory(nUnitUikitDll);


            // [code to implement] public static int Main(string[] args)
            // [code to implement] GuiOptions guiOptions = new GuiOptions(args);
            //var args = new[] { Config.getExecutingAssembly() }; // assembly that will be loaded and searched for Unit tests                                        
            var args = new[] { nUnitUtilDll };
            O2Object guiOptions = nUnitGuiRunner.ctor("GuiOptions", new[] { args });


            // [code to implement] 
            /*
            ServiceManager.Services.AddService(new SettingsService())            
            ServiceManager.Services.AddService(new DomainManager());
            ServiceManager.Services.AddService(new RecentFilesService());
            ServiceManager.Services.AddService(new TestLoader(new GuiTestEventDispatcher()));
            ServiceManager.Services.AddService(new AddinRegistry());
            ServiceManager.Services.AddService(new AddinManager());
            ServiceManager.Services.AddService(new TestAgency());*/

            O2Object serviceManager_Services = nUnitUtil.staticTypeGetProperty("ServiceManager", "Services");
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("SettingsService") });
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("DomainManager") });
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("RecentFilesService") });
            serviceManager_Services.call("AddService",
                                         new[]
                                             {
                                                 nUnitUtil.ctor("TestLoader",
                                                                new[] {nUnitUikit.ctor("GuiTestEventDispatcher")})
                                             });
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("AddinRegistry") });
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("AddinManager") });
            serviceManager_Services.call("AddService", new[] { nUnitUtil.ctor("TestAgency") });

            // [code to implement]  ServiceManager.Services.InitializeServices();
            serviceManager_Services.call("InitializeServices");

            // [code to implement] AppContainer container = new AppContainer();
            O2Object container = nUnitUikit.ctor("AppContainer");

            // [don't need to implement this one] AmbientProperties serviceInstance = new AmbientProperties();            
            var serviceInstance = new AmbientProperties();

            // [code to implement] container.Services.AddService(typeof(AmbientProperties), serviceInstance);
            O2Object container_services = container.get("Services");
            container_services.call("AddService", new object[] { typeof(AmbientProperties), serviceInstance });


            //  [code to implement] NUnitForm component = new NUnitForm(guiOptions);
            O2Object component = nUnitGuiRunner.ctor("NUnitForm", new[] { guiOptions });

            // [code to implement] container.Add(component);
            container.call("Add", new object[] { component });


            //  [code to implement]   new GuiAttachedConsole();
            nUnitUikit.ctor("GuiAttachedConsole");

            return (Form)component.Obj;

            /*return (form is Form) ? (Form) form.Obj : null;
            if (form is Form)
                return (Form) form.Obj;
            else
                return null;                */
        }