Exemple #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)
                {
                    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
                {
                    loader.LoadTest(testName);
                }
            }
        }
        private static NUnitProject LegacyConvertVSSolution(string path)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(path));

            string solutionDirectory = Path.GetDirectoryName(path);

            using (StreamReader reader = new StreamReader(path))
            {
                char[] delims    = { '=', ',' };
                char[] trimchars = { ' ', '"' };

                string line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("Project("))
                    {
                        string[] parts         = line.Split(delims);
                        string   vsProjectPath = parts[2].Trim(trimchars);

                        if (VSProject.IsProjectFile(vsProjectPath))
                        {
                            project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath)));
                        }
                    }

                    line = reader.ReadLine();
                }

                project.IsDirty = false;
                return(project);
            }
        }
Exemple #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);
                    }
                }
            }
        }
        private static NUnitProject ConvertVSProject(string path)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(path));
            project.Add(new VSProject(path));
			project.IsDirty = false;
            return project;
        }
        public void LoadMakesProjectNotDirty()
        {
            project.Save(xmlfile);
            NUnitProject project2 = NUnitProject.LoadProject(xmlfile);

            Assert.IsFalse(project2.IsDirty);
        }
Exemple #6
0
 public void AddingInitialConfigRequiresReload()
 {
     NUnitProject newProj = new NUnitProject("/junk");
     newProj.HasChangesRequiringReload = false;
     newProj.Configs.Add("New");
     Assert.That(newProj.HasChangesRequiringReload);
 }
Exemple #7
0
        public void ConfigurationFileFromAssemblies()
        {
            NUnitProject project = projectService.WrapAssemblies(new string[] { "mock-assembly.dll" });
            string       config  = Path.GetFileName(project.ConfigurationFile);

            Assert.AreEqual("mock-assembly.dll.config", config);
        }
Exemple #8
0
        public void ConfigurationFileFromAssemblies()
        {
            NUnitProject project = projectService.WrapAssemblies(new string[] { mockDll });
            string       config  = Path.GetFileName(project.ConfigurationFile);

            Assert.That(config, Is.EqualTo("mock-assembly.dll.config").IgnoreCase);
        }
 public void FromVSSolution2003()
 {
     using (new TestResource("csharp-sample.csproj", @"csharp\csharp-sample.csproj"))
         using (new TestResource("jsharp.vjsproj", @"jsharp\jsharp.vjsproj"))
             using (new TestResource("vb-sample.vbproj", @"vb\vb-sample.vbproj"))
                 using (new TestResource("cpp-sample.vcproj", @"cpp-sample\cpp-sample.vcproj"))
                     using (TestResource file = new TestResource("samples.sln"))
                     {
                         NUnitProject project = converter.ConvertFrom(file.Path);
                         if (useSolutionConfigs)
                         {
                             Assert.AreEqual(2, project.Configs.Count);
                             Assert.AreEqual(4, project.Configs["Debug"].Assemblies.Count);
                             Assert.AreEqual(4, project.Configs["Release"].Assemblies.Count);
                         }
                         else
                         {
                             Assert.AreEqual(4, project.Configs.Count);
                             Assert.AreEqual(3, project.Configs["Debug"].Assemblies.Count);
                             Assert.AreEqual(3, project.Configs["Release"].Assemblies.Count);
                             Assert.AreEqual(1, project.Configs["Debug|Win32"].Assemblies.Count);
                             Assert.AreEqual(1, project.Configs["Release|Win32"].Assemblies.Count);
                         }
                         Assert.IsTrue(project.IsLoadable, "Not loadable");
                         Assert.IsFalse(project.IsDirty, "Project should not be dirty");
                     }
 }
Exemple #10
0
 public RenameConfigurationDialog(NUnitProject project, string configurationName)
 {
     InitializeComponent();
     this.project           = project;
     this.configurationName = configurationName;
     this.originalName      = configurationName;
 }
Exemple #11
0
        public void SaveNormalProjectPUT1([PexAssumeUnderTest] String config1, [PexAssumeUnderTest] String config2, [PexAssumeUnderTest] String _xmlFile)
        {
            NUnitProject savedProject = NUnitProject.EmptyProject();

            PexAssume.IsTrue(config1.Contains("t"));
            PexAssume.IsTrue(config2.Contains("t"));

            ProjectConfig config = new ProjectConfig(config1);

            config.BasePath = "bin" + Path.DirectorySeparatorChar + config1;
            config.Assemblies.Add(Path.GetFullPath("bin" + Path.DirectorySeparatorChar + config1 + Path.DirectorySeparatorChar + "assembly1.dll"));
            config.Assemblies.Add(Path.GetFullPath("bin" + Path.DirectorySeparatorChar + config1 + Path.DirectorySeparatorChar + "assembly2.dll"));
            savedProject.Configs.Add(config);

            ProjectConfig _config = new ProjectConfig(config2);

            _config.BasePath = "bin" + Path.DirectorySeparatorChar + config2;
            _config.Assemblies.Add(Path.GetFullPath("bin" + Path.DirectorySeparatorChar + config2 + Path.DirectorySeparatorChar + "assembly1.dll"));
            _config.Assemblies.Add(Path.GetFullPath("bin" + Path.DirectorySeparatorChar + config2 + Path.DirectorySeparatorChar + "assembly2.dll"));
            savedProject.Configs.Add(config);

            savedProject.Save(_xmlFile, true);
            String testOracle = NUnitProjectXml.NormalProject.Replace("Debug", config1);

            testOracle = testOracle.Replace("Release", config2);
            Console.WriteLine(CreatedProjects.currentProject);
            PexAssert.AreEqual(testOracle, CreatedProjects.currentProject);
        }
Exemple #12
0
 public void TestSaveEmptyProjectPUT1([PexAssumeUnderTest] NUnitProject savedProject)
 {
     //PexAssume.IsTrue(!xmlFILE.Equals(""));
     //project.Save(xmlFILE);
     //observer method
     CheckContentsPUT(NUnitProjectXml.EmptyProject, savedProject.ProjectPath);
 }
Exemple #13
0
        public void SaveAndLoadConfigsWithAssemblies()
        {
            ProjectConfig config1 = new ProjectConfig("Debug");

            config1.Assemblies.Add(Path.GetFullPath(@"bin\debug\assembly1.dll"));
            config1.Assemblies.Add(Path.GetFullPath(@"bin\debug\assembly2.dll"));

            ProjectConfig config2 = new ProjectConfig("Release");

            config2.Assemblies.Add(Path.GetFullPath(@"bin\release\assembly1.dll"));
            config2.Assemblies.Add(Path.GetFullPath(@"bin\release\assembly2.dll"));

            project.Configs.Add(config1);
            project.Configs.Add(config2);
            project.Save(xmlfile);

            Assert.IsTrue(File.Exists(xmlfile));

            NUnitProject project2 = projectService.LoadProject(xmlfile);

            Assert.AreEqual(2, project2.Configs.Count);

            config1 = project2.Configs["Debug"];
            Assert.AreEqual(2, config1.Assemblies.Count);
            Assert.AreEqual(Path.GetFullPath(@"bin\debug\assembly1.dll"), config1.Assemblies[0]);
            Assert.AreEqual(Path.GetFullPath(@"bin\debug\assembly2.dll"), config1.Assemblies[1]);

            config2 = project2.Configs["Release"];
            Assert.AreEqual(2, config2.Assemblies.Count);
            Assert.AreEqual(Path.GetFullPath(@"bin\release\assembly1.dll"), config2.Assemblies[0]);
            Assert.AreEqual(Path.GetFullPath(@"bin\release\assembly2.dll"), config2.Assemblies[1]);
        }
        public IProject LoadProject(string path)
        {
            NUnitProject project = new NUnitProject();

            project.Load(path);
            return(project);
        }
 public void SetUp()
 {
     NUnitProject.ProjectSeed = 0;
     project          = NUnitProject.EmptyProject();
     project.Changed += new ProjectEventHandler(OnProjectChanged);
     lastEvent        = null;
 }
        public void ConfigurationFileFromAssembly()
        {
            NUnitProject project = NUnitProject.FromAssembly("mock-assembly.dll");
            string       config  = Path.GetFileName(project.ConfigurationFile);

            Assert.AreEqual("mock-assembly.dll.config", config);
        }
Exemple #17
0
        public void SaveProjectAs()
        {
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.Title  = "Save Test Project";
            dlg.Filter = "NUnit Test Project (*.nunit)|*.nunit|All Files (*.*)|*.*";
            string path = NUnitProject.ProjectPathFromFile(loader.TestProject.ProjectPath);

            if (CanWriteProjectFile(path))
            {
                dlg.FileName = path;
            }
            dlg.DefaultExt      = "nunit";
            dlg.ValidateNames   = true;
            dlg.OverwritePrompt = true;

            while (dlg.ShowDialog(Form) == DialogResult.OK)
            {
                if (!CanWriteProjectFile(dlg.FileName))
                {
                    Form.MessageDisplay.Info(string.Format("File {0} is write-protected. Select another file name.", dlg.FileName));
                }
                else
                {
                    loader.TestProject.Save(dlg.FileName);
                    ReloadProject();
                    return;
                }
            }
        }
        public void Test_01_TypesAreComplete()
        {
            var actual   = new NUnitProject();
            var expected = Assembly.Load("nunit.framework");

            actual.Compare(expected, out var common, out var missing, out var extra);
            if (missing.Any() || extra.Any())
            {
                var builder = new StringBuilder();
                builder.AppendLine("NUnitProject is invalid");
                if (missing.Any())
                {
                    builder.AppendLine($"Missing ({missing.Count}):");
                    foreach (var item in missing)
                    {
                        builder.AppendLine(item.FullName);
                    }
                }
                if (extra.Any())
                {
                    builder.AppendLine($"Extra ({extra.Count}):");
                    foreach (var item in extra)
                    {
                        builder.AppendLine(item.FullName);
                    }
                }
                Assert.Fail(builder.ToString());
            }
        }
        public void SaveClearsAssemblyWrapper()
        {
            NUnitProject project = NUnitProject.FromAssembly("nunit.tests.dll");

            project.Save(xmlfile);
            Assert.IsFalse(project.IsAssemblyWrapper,
                           "Changed project should no longer be wrapper");
        }
Exemple #20
0
 public void SetUp()
 {
     project = new NUnitProject("path");
     project.Configs.Add("Debug");
     project.Configs.Add("Release");
     dlg    = new AddConfigurationDialog(project);
     tester = new FormTester(dlg);
 }
Exemple #21
0
        public void SaveEmptyProjectPUT1([PexAssumeUnderTest] String test)
        {
            PexAssume.IsTrue(test.Contains("tst"));
            NUnitProject savedProject = NUnitProject.EmptyProject();

            savedProject.Save(test, false);
            CheckContentsPUT(NUnitProjectXml.EmptyProject, savedProject.ProjectPath);
        }
        public void AddingInitialConfigRequiresReload()
        {
            NUnitProject newProj = new NUnitProject("/junk");

            newProj.HasChangesRequiringReload = false;
            newProj.Configs.Add("New");
            Assert.That(newProj.HasChangesRequiringReload);
        }
Exemple #23
0
 public void SetUp()
 {
     project = new NUnitProject("path");
     project.Configs.Add("Debug");
     project.Configs.Add("Release");
     dlg       = new AddConfigurationDialog(project);
     this.Form = dlg;
 }
Exemple #24
0
        public static NUnitProject Create()
        {
            //PexAssume.IsTrue(name.Contains("tst"));
            NUnitProject savedProject = NUnitProject.EmptyProject();

            savedProject.Save("test.nunit", true);
            return(savedProject);
        }
Exemple #25
0
        private Test MakeTest(TestDomain testDomain, string assemblyName)
        {
            NUnitProject project;

            project = NUnitProject.FromAssembly(assemblyName);

            return(testDomain.Load(project));
        }
        public void SaveClearsAssemblyWrapper()
        {
            NUnitProject project = projectService.WrapAssembly(mockDll);

            project.Save(xmlfile);
            Assert.IsFalse(project.IsAssemblyWrapper,
                           "Changed project should no longer be wrapper");
        }
Exemple #27
0
        public void ConfigurationFileFromAssemblies()
        {
            NUnitProject project = NUnitProject.FromAssemblies(new string[] { "mock-assembly.dll" });
            string       config  = project.ConfigurationFile;

            string[] splits = config.Split('\\');
            Assert.AreEqual("mock-assembly.dll.config", splits[splits.Length - 1]);
        }
        private static NUnitProject ConvertVSProject(string path)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(path));

            project.Add(new VSProject(path));
            project.IsDirty = false;
            return(project);
        }
Exemple #29
0
        public void NewProjectDefaultPath()
        {
            Assert.AreEqual(Path.GetFullPath("Project1"), project.ProjectPath);
            Assert.AreEqual("Project1", project.Name);
            NUnitProject another = projectService.EmptyProject();

            Assert.AreEqual(Path.GetFullPath("Project2"), another.ProjectPath);
        }
Exemple #30
0
        public void EditProject()
        {
            NUnitProject project = loader.TestProject;

            string editorPath = GetProjectEditorPath();

            if (!File.Exists(editorPath))
            {
                string NL      = Environment.NewLine;
                string message =
                    "Unable to locate the specified Project Editor:" + NL + NL + editorPath + NL + NL +
                    (Services.UserSettings.GetSetting("Options.ProjectEditor.EditorPath") == null
                        ? "Verify that nunit.editor.exe is properly installed in the NUnit bin directory."
                        : "Verify that you have set the path to the editor correctly.");

                Form.MessageDisplay.Error(message);

                return;
            }

            if (!NUnitProject.IsNUnitProjectFile(project.ProjectPath))
            {
                if (Form.MessageDisplay.Display(
                        "The project has not yet been saved. In order to edit the project, it must first be saved. Click OK to save the project or Cancel to exit.",
                        MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    project.Save();
                }
            }
            else if (!File.Exists(project.ProjectPath))
            {
                project.Save();
            }
            else if (project.IsDirty)
            {
                switch (Form.MessageDisplay.Ask(
                            "There are unsaved changes. Do you want to save them before running the editor?",
                            MessageBoxButtons.YesNoCancel))
                {
                case DialogResult.Yes:
                    project.Save();
                    break;

                case DialogResult.Cancel:
                    return;
                }
            }

            // In case we tried to save project and failed
            if (NUnitProject.IsNUnitProjectFile(project.ProjectPath) && File.Exists(project.ProjectPath))
            {
                Process p = new Process();

                p.StartInfo.FileName  = Quoted(editorPath);
                p.StartInfo.Arguments = Quoted(project.ProjectPath);
                p.Start();
            }
        }
Exemple #31
0
        public void SaveAndLoadEmptyProject()
        {
            project.Save(xmlfile);
            Assert.IsTrue(File.Exists(xmlfile));

            NUnitProject project2 = projectService.LoadProject(xmlfile);

            Assert.AreEqual(0, project2.Configs.Count);
        }
		public void SetUp()
		{
			activeConfig = new ProjectConfig( "Debug" );
            inactiveConfig = new ProjectConfig("Release");
			project = new NUnitProject( TestPath( "/test/myproject.nunit" ) );
			project.Configs.Add( activeConfig );
            project.Configs.Add(inactiveConfig);
            project.IsDirty = false;
            project.HasChangesRequiringReload = false;
		}
 public void FromMakefileProject()
 {
     using (TestResource file = new TestResource("MakeFileProject.vcproj"))
     {
         NUnitProject project = converter.ConvertFrom(file.Path);
         Assert.AreEqual(2, project.Configs.Count);
         Assert.AreEqual(1, project.Configs["Debug|Win32"].Assemblies.Count);
         Assert.AreEqual(1, project.Configs["Release|Win32"].Assemblies.Count);
     }
 }
		public NUnitProject ConvertFrom(string path)
		{
			NUnitProject project = new NUnitProject( Path.GetFullPath( path ) );

			if ( VSProject.IsProjectFile(path) )
			{
				VSProject vsProject = new VSProject( path );
				project.Add( vsProject );
			}
			else if ( VSProject.IsSolutionFile(path) )
			{
				string solutionDirectory = Path.GetDirectoryName( path );
				using(StreamReader reader = new StreamReader( path ))
				{
					char[] delims = { '=', ',' };
					char[] trimchars = { ' ', '"' };

					string line = reader.ReadLine();
					while ( line != null )
					{
						if ( line.StartsWith( "Project" ) )
						{
							string[] parts = line.Split( delims );
							string vsProjectPath = parts[2].Trim(trimchars);
						
							if ( VSProject.IsProjectFile( vsProjectPath ) )
								project.Add( new VSProject( Path.Combine( solutionDirectory, vsProjectPath ) ) );
						}

						line = reader.ReadLine();
					}
				}
			}

			project.IsDirty = false;

			return project;
		}
 public void SetUp()
 {
     config = new ProjectConfig( "Debug" );
     project = new NUnitProject( TestPath( "/test/myproject.nunit" ) );
     project.Configs.Add( config );
 }
		public void SetUp()
		{
			project = new ProjectService().EmptyProject();
		}
        private static NUnitProject ConvertVSSolution(string path)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(path));

            string solutionDirectory = Path.GetDirectoryName(path);
            using (StreamReader reader = new StreamReader(path))
            {
                char[] delims = { '=', ',' };
                char[] trimchars = { ' ', '"' };
                string buildMarker = ".Build.0 =";

                Hashtable projectLookup = new Hashtable();

                string line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("Project("))
                    {
                        string[] parts = line.Split(delims);
                        string vsProjectPath = parts[2].Trim(trimchars);
                        string vsProjectGuid = parts[3].Trim(trimchars);

                        if (VSProject.IsProjectFile(vsProjectPath))
                            projectLookup[vsProjectGuid] = new VSProject(Path.Combine(solutionDirectory, vsProjectPath));
                    }
                    else if (line.IndexOf(buildMarker) >= 0)
                    {
                        line = line.Trim();
                        int endBrace = line.IndexOf('}');

                        string vsProjectGuid = line.Substring(0, endBrace + 1);
                        VSProject vsProject = projectLookup[vsProjectGuid] as VSProject;

                        if (vsProject != null)
                        {
                            line = line.Substring(endBrace + 2);

                            int split = line.IndexOf(buildMarker) + 1;
                            string solutionConfig = line.Substring(0, split - 1);
                            int bar = solutionConfig.IndexOf('|');
                            if (bar >= 0)
                                solutionConfig = solutionConfig.Substring(0, bar);

                            string projectConfig = line.Substring(split + buildMarker.Length);
                            if (vsProject.Configs[projectConfig] == null)
                            {
                                bar = projectConfig.IndexOf('|');
                                if (bar >= 0)
                                    projectConfig = projectConfig.Substring(0, bar);
                            }

                            if (project.Configs[solutionConfig] == null)
                                project.Configs.Add(new ProjectConfig(solutionConfig));

                            foreach (string assembly in vsProject.Configs[projectConfig].Assemblies)
                                if (!project.Configs[solutionConfig].Assemblies.Contains(assembly))
                                    project.Configs[solutionConfig].Assemblies.Add(assembly);

                            //if (VSProject.IsProjectFile(vsProjectPath))
                            //    project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath)));
                        }
                    }

                    line = reader.ReadLine();
                }

                project.IsDirty = false;
                return project;
            }
        }
 public void SetUp()
 {
     //Console.WriteLine("testinitiliaze");
     project = NUnitProject.EmptyProject();
 }
Exemple #39
0
 public void SetUp()
 {
     NUnitProject.ProjectSeed = 0;
     project = NUnitProject.EmptyProject();
     project.Changed += new ProjectEventHandler( OnProjectChanged );
     lastEvent = null;
 }
Exemple #40
0
 public void SetUp()
 {
     project = NUnitProject.EmptyProject();
 }
 public void Setup()
 {
     project = new NUnitProject();
 }