Ejemplo n.º 1
0
        public void OpenProject(string testFileName, string configName, string testName)
        {
            if (loader.IsProjectLoaded && SaveProjectIfDirty() == DialogResult.Cancel)
            {
                return;
            }

            loader.LoadProject(testFileName, configName);
            if (loader.IsProjectLoaded)
            {
                NUnitProject testProject = loader.TestProject;
                if (testProject.Configs.Count == 0)
                {
                    Form.MessageDisplay.Info("Loaded project contains no configuration data");
                }
                else if (testProject.ActiveConfig == null)
                {
                    Form.MessageDisplay.Info("Loaded project has no active configuration");
                }
                else if (testProject.ActiveConfig.Assemblies.Count == 0)
                {
                    Form.MessageDisplay.Info("Active configuration contains no assemblies");
                }
                else
                {
                    loader.LoadTest(testName);
                }
            }
        }
Ejemplo n.º 2
0
        public static TestsContainer LoadTests()
        {
            TestsContainer Container = new TestsContainer();

            TestLoader.LoadTest(out Container);
            return(Container);
        }
Ejemplo n.º 3
0
        public static void OpenProject(Form owner, string testFileName, string configName, string testName)
        {
            TestLoader loader = Services.TestLoader;

            if (loader.IsProjectLoaded && SaveProjectIfDirty(owner) == DialogResult.Cancel)
            {
                return;
            }

            loader.LoadProject(testFileName, configName);
            if (loader.IsProjectLoaded)
            {
                NUnitProject testProject = loader.TestProject;
                if (testProject.Configs.Count == 0)
                {
                    UserMessage.DisplayInfo("Loaded project contains no configuration data");
                }
                else if (testProject.ActiveConfig == null)
                {
                    UserMessage.DisplayInfo("Loaded project has no active configuration");
                }
                else if (testProject.ActiveConfig.Assemblies.Count == 0)
                {
                    UserMessage.DisplayInfo("Active configuration contains no assemblies");
                }
                else
                {
                    using (new LongRunningOperationDisplay(owner, "Loading..."))
                    {
                        loader.LoadTest(testName);
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void AddVSProject(Form owner)
        {
            TestLoader     loader = Services.TestLoader;
            OpenFileDialog dlg    = new OpenFileDialog();

            dlg.Title = "Add Visual Studio Project";

            dlg.Filter =
                "All Project Types (*.csproj,*.vjsproj,*.vbproj,*.vcproj)|*.csproj;*.vjsproj;*.vbproj;*.vcproj|" +
                "C# Projects (*.csproj)|*.csproj|" +
                "J# Projects (*.vjsproj)|*.vjsproj|" +
                "VB Projects (*.vbproj)|*.vbproj|" +
                "C++ Projects (*.vcproj)|*.vcproj|" +
                "All Files (*.*)|*.*";

            dlg.FilterIndex = 1;
            dlg.FileName    = "";

            if (dlg.ShowDialog(owner) == DialogResult.OK)
            {
                try
                {
                    VSProject vsProject = new VSProject(dlg.FileName);
                    loader.TestProject.Add(vsProject);
                    loader.LoadTest();
                }
                catch (Exception ex)
                {
                    UserMessage.DisplayFailure(ex.Message, "Invalid VS Project");
                }
            }
        }
 private void LoadTest(string assembly)
 {
     loader.LoadProject(assembly);
     if (loader.IsProjectLoaded && loader.TestProject.IsLoadable)
     {
         loader.LoadTest();
     }
 }
Ejemplo n.º 6
0
        public void Load1000TestsUsingTestLoader()
        {
            loader = new TestLoader();
            int start = Environment.TickCount;

            loader.LoadProject("loadtest-assembly.dll");
            Assert.IsTrue(loader.IsProjectLoaded);
            loader.LoadTest();
            Assert.IsTrue(loader.IsTestLoaded);
            Assert.AreEqual(1000, loader.TestCount);
            int ms = Environment.TickCount - start;

            Assert.LessOrEqual(ms, 4000);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///     Overrides <see cref="TestExtractor.Extractor.Extractor.Extractor.Extract()" />
        /// </summary>
        protected override void Extract()
        {
            var assemblies = AppDomain.CurrentDomain.GetData(AppDataDomainExtractionAssemblyName) as IList <string>;

            if (assemblies == null || !assemblies.Any())
            {
                return;
            }

            TestSuites  = new List <ISuiteNode>();
            TestMethods = new List <IStubNode>();

            ServiceManager.Services.AddService(new SettingsService());
            ServiceManager.Services.AddService(new DomainManager());
            ServiceManager.Services.AddService(new ProjectService());
            ServiceManager.Services.AddService(new AddinRegistry());
            ServiceManager.Services.AddService(new AddinManager());
            ServiceManager.Services.AddService(new TestAgency());
            ServiceManager.Services.InitializeServices();

            foreach (var assembly in assemblies.Distinct().Where(File.Exists))
            {
                _assembly = assembly;

                var loader = new TestLoader();
                loader.Events.TestLoaded += NodeLoadEvent;
                loader.LoadProject(assembly);
                loader.LoadTest();

                loader.UnloadTest();
                loader.UnloadProject();
                loader.Events.TestLoaded -= NodeLoadEvent;

                _assembly = string.Empty;
            }

            var tests      = TestMethods.ToList();
            var testSuites = TestSuites.ToList();

            AppDomain.CurrentDomain.SetData(AppDataDomainExtractionStubName, tests);
            AppDomain.CurrentDomain.SetData(AppDataDomainExtractionSuiteName, testSuites);

            ServiceManager.Services.StopAllServices();
            ServiceManager.Services.ClearServices();
        }
Ejemplo n.º 8
0
        public static void AddToProject(Form owner, string configName)
        {
            TestLoader    loader = Services.TestLoader;
            ProjectConfig config = configName == null
                                ? loader.TestProject.ActiveConfig
                                : loader.TestProject.Configs[configName];

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Title            = "Add Assemblies To Project";
            dlg.InitialDirectory = config.BasePath;

            if (VisualStudioSupport)
            {
                dlg.Filter =
                    "Projects & Assemblies(*.csproj,*.vbproj,*.vjsproj, *.vcproj,*.dll,*.exe )|*.csproj;*.vjsproj;*.vbproj;*.vcproj;*.dll;*.exe|" +
                    "Visual Studio Projects (*.csproj,*.vjsproj,*.vbproj,*.vcproj)|*.csproj;*.vjsproj;*.vbproj;*.vcproj|" +
                    "C# Projects (*.csproj)|*.csproj|" +
                    "J# Projects (*.vjsproj)|*.vjsproj|" +
                    "VB Projects (*.vbproj)|*.vbproj|" +
                    "C++ Projects (*.vcproj)|*.vcproj|" +
                    "Assemblies (*.dll,*.exe)|*.dll;*.exe";
            }
            else
            {
                dlg.Filter = "Assemblies (*.dll,*.exe)|*.dll;*.exe";
            }

            dlg.FilterIndex = 1;
            dlg.FileName    = "";

            if (dlg.ShowDialog(owner) != DialogResult.OK)
            {
                return;
            }

            if (PathUtils.IsAssemblyFileType(dlg.FileName))
            {
                config.Assemblies.Add(dlg.FileName);
            }
            else if (VSProject.IsProjectFile(dlg.FileName))
            {
                try
                {
                    VSProject         vsProject = new VSProject(dlg.FileName);
                    MessageBoxButtons buttons;
                    string            msg;

                    if (configName != null && vsProject.Configs.Contains(configName))
                    {
                        msg = "The project being added may contain multiple configurations;\r\r" +
                              "Select\tYes to add all configurations found.\r" +
                              "\tNo to add only the " + configName + " configuration.\r" +
                              "\tCancel to exit without modifying the project.";
                        buttons = MessageBoxButtons.YesNoCancel;
                    }
                    else
                    {
                        msg = "The project being added may contain multiple configurations;\r\r" +
                              "Select\tOK to add all configurations found.\r" +
                              "\tCancel to exit without modifying the project.";
                        buttons = MessageBoxButtons.OKCancel;
                    }

                    DialogResult result = UserMessage.Ask(msg, buttons);
                    if (result == DialogResult.Yes || result == DialogResult.OK)
                    {
                        loader.TestProject.Add(vsProject);
                        if (loader.IsTestLoaded)
                        {
                            loader.ReloadTest();
                        }
                        else
                        {
                            loader.LoadTest();
                        }
                    }
                    else if (result == DialogResult.No)
                    {
                        foreach (string assembly in vsProject.Configs[configName].Assemblies)
                        {
                            config.Assemblies.Add(assembly);
                        }
                    }
                }
                catch (Exception ex)
                {
                    UserMessage.DisplayFailure(ex.Message, "Invalid VS Project");
                }
            }
        }