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)
                {
                    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);
                }
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
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);
                    }
                }
            }
        }
        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);
        }
Ejemplo n.º 6
0
 public void AddingInitialConfigRequiresReload()
 {
     NUnitProject newProj = new NUnitProject("/junk");
     newProj.HasChangesRequiringReload = false;
     newProj.Configs.Add("New");
     Assert.That(newProj.HasChangesRequiringReload);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 9
0
 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");
                     }
 }
Ejemplo n.º 10
0
 public RenameConfigurationDialog(NUnitProject project, string configurationName)
 {
     InitializeComponent();
     this.project           = project;
     this.configurationName = configurationName;
     this.originalName      = configurationName;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 12
0
 public void TestSaveEmptyProjectPUT1([PexAssumeUnderTest] NUnitProject savedProject)
 {
     //PexAssume.IsTrue(!xmlFILE.Equals(""));
     //project.Save(xmlFILE);
     //observer method
     CheckContentsPUT(NUnitProjectXml.EmptyProject, savedProject.ProjectPath);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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());
            }
        }
Ejemplo n.º 19
0
        public void SaveClearsAssemblyWrapper()
        {
            NUnitProject project = NUnitProject.FromAssembly("nunit.tests.dll");

            project.Save(xmlfile);
            Assert.IsFalse(project.IsAssemblyWrapper,
                           "Changed project should no longer be wrapper");
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 22
0
        public void AddingInitialConfigRequiresReload()
        {
            NUnitProject newProj = new NUnitProject("/junk");

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

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

            project = NUnitProject.FromAssembly(assemblyName);

            return(testDomain.Load(project));
        }
Ejemplo n.º 26
0
        public void SaveClearsAssemblyWrapper()
        {
            NUnitProject project = projectService.WrapAssembly(mockDll);

            project.Save(xmlfile);
            Assert.IsFalse(project.IsAssemblyWrapper,
                           "Changed project should no longer be wrapper");
        }
Ejemplo n.º 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]);
        }
Ejemplo n.º 28
0
        private static NUnitProject ConvertVSProject(string path)
        {
            NUnitProject project = new NUnitProject(Path.GetFullPath(path));

            project.Add(new VSProject(path));
            project.IsDirty = false;
            return(project);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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();
            }
        }
Ejemplo n.º 31
0
        public void SaveAndLoadEmptyProject()
        {
            project.Save(xmlfile);
            Assert.IsTrue(File.Exists(xmlfile));

            NUnitProject project2 = projectService.LoadProject(xmlfile);

            Assert.AreEqual(0, project2.Configs.Count);
        }
Ejemplo n.º 32
0
		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;
		}
Ejemplo n.º 33
0
 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;
		}
Ejemplo n.º 35
0
 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;
            }
        }
Ejemplo n.º 38
0
 public void SetUp()
 {
     //Console.WriteLine("testinitiliaze");
     project = NUnitProject.EmptyProject();
 }
Ejemplo n.º 39
0
 public void SetUp()
 {
     NUnitProject.ProjectSeed = 0;
     project = NUnitProject.EmptyProject();
     project.Changed += new ProjectEventHandler( OnProjectChanged );
     lastEvent = null;
 }
Ejemplo n.º 40
0
 public void SetUp()
 {
     project = NUnitProject.EmptyProject();
 }
Ejemplo n.º 41
0
 public void Setup()
 {
     project = new NUnitProject();
 }