Exemplo n.º 1
0
 internal SolutionFolderFileCollection(SolutionFolder parent)
 {
     this.parent = parent;
 }
        public void ModelQueries()
        {
            DotNetProject     it2, it3, it4;
            DummySolutionItem it1;
            string            someFile, someId;

            Workspace ws  = new Workspace();
            Workspace cws = new Workspace();

            ws.Items.Add(cws);

            Solution sol1 = new Solution();

            cws.Items.Add(sol1);
            sol1.RootFolder.Items.Add(it1 = new DummySolutionItem());
            sol1.RootFolder.Items.Add(it2 = new DotNetAssemblyProject("C#"));

            Solution sol2 = new Solution();

            cws.Items.Add(sol2);
            SolutionFolder f = new SolutionFolder();

            sol2.RootFolder.Items.Add(f);
            f.Items.Add(it3 = new DotNetAssemblyProject("C#"));
            f.Items.Add(it4 = new DotNetAssemblyProject("C#"));

            it3.Name     = "it3";
            it4.FileName = "/test/it4";
            someFile     = it4.FileName;
            someId       = it3.ItemId;
            Assert.IsFalse(string.IsNullOrEmpty(someId));

            Assert.AreEqual(2, sol1.Items.Count);
            Assert.IsTrue(sol1.Items.Contains(it1));
            Assert.IsTrue(sol1.Items.Contains(it2));

            Assert.AreEqual(2, sol2.Items.Count);
            Assert.IsTrue(sol2.Items.Contains(it3));
            Assert.IsTrue(sol2.Items.Contains(it4));

            ReadOnlyCollection <SolutionItem> its = ws.GetAllSolutionItems();

            Assert.AreEqual(7, its.Count);
            Assert.IsTrue(its.Contains(it1));
            Assert.IsTrue(its.Contains(it2));
            Assert.IsTrue(its.Contains(it3));
            Assert.IsTrue(its.Contains(it4));
            Assert.IsTrue(its.Contains(sol1.RootFolder));
            Assert.IsTrue(its.Contains(sol2.RootFolder));
            Assert.IsTrue(its.Contains(f));

            ReadOnlyCollection <DotNetProject> its2 = ws.GetAllSolutionItems <DotNetProject> ();

            Assert.AreEqual(3, its2.Count);
            Assert.IsTrue(its2.Contains(it2));
            Assert.IsTrue(its2.Contains(it3));
            Assert.IsTrue(its2.Contains(it4));

            ReadOnlyCollection <Project> its3 = ws.GetAllProjects();

            Assert.AreEqual(3, its3.Count);
            Assert.IsTrue(its3.Contains(it2));
            Assert.IsTrue(its3.Contains(it3));
            Assert.IsTrue(its3.Contains(it4));

            ReadOnlyCollection <Solution> its4 = ws.GetAllSolutions();

            Assert.AreEqual(2, its4.Count);
            Assert.IsTrue(its4.Contains(sol1));
            Assert.IsTrue(its4.Contains(sol2));

            ReadOnlyCollection <WorkspaceItem> its5 = ws.GetAllItems();

            Assert.AreEqual(4, its5.Count);
            Assert.IsTrue(its5.Contains(ws));
            Assert.IsTrue(its5.Contains(cws));
            Assert.IsTrue(its5.Contains(sol2));
            Assert.IsTrue(its5.Contains(sol2));

            ReadOnlyCollection <Workspace> its6 = ws.GetAllItems <Workspace> ();

            Assert.AreEqual(2, its6.Count);
            Assert.IsTrue(its6.Contains(ws));
            Assert.IsTrue(its6.Contains(cws));

            SolutionEntityItem fi = ws.FindSolutionItem(someFile);

            Assert.AreEqual(it4, fi);

            fi = ws.FindSolutionItem(someFile + ".wrong");
            Assert.IsNull(fi);

            SolutionItem si = sol2.GetSolutionItem(someId);

            Assert.AreEqual(it3, si);

            fi = sol2.FindSolutionItem(someFile);
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it3");
            Assert.AreEqual(it3, fi);

            fi = sol2.FindProjectByName("it4");
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it2");
            Assert.IsNull(fi);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Builds the solution item
        /// </summary>
        /// <param name='monitor'>
        /// A progress monitor
        /// </param>
        /// <param name='solutionConfiguration'>
        /// Configuration to use to build the project
        /// </param>
        /// <param name='buildReferences'>
        /// When set to <c>true</c>, the referenced items will be built before building this item
        /// </param>
        public BuildResult Build(IProgressMonitor monitor, ConfigurationSelector solutionConfiguration, bool buildReferences)
        {
            ITimeTracker tt = Counters.BuildProjectTimer.BeginTiming("Building " + Name);

            try {
                if (!buildReferences)
                {
                    //SolutionFolder's OnRunTarget handles the begin/end task itself, don't duplicate
                    if (this is SolutionFolder)
                    {
                        return(RunTarget(monitor, ProjectService.BuildTarget, solutionConfiguration));
                    }

                    try {
                        SolutionEntityItem        it    = this as SolutionEntityItem;
                        SolutionItemConfiguration iconf = it != null?it.GetConfiguration(solutionConfiguration) : null;

                        string confName = iconf != null ? iconf.Id : solutionConfiguration.ToString();
                        monitor.BeginTask(GettextCatalog.GetString("Building: {0} ({1})", Name, confName), 1);

                        // This will end calling OnBuild ()
                        return(RunTarget(monitor, ProjectService.BuildTarget, solutionConfiguration));
                    } finally {
                        monitor.EndTask();
                    }
                }

                // Get a list of all items that need to be built (including this),
                // and build them in the correct order

                List <SolutionItem> referenced = new List <SolutionItem> ();
                Set <SolutionItem>  visited    = new Set <SolutionItem> ();
                GetBuildableReferencedItems(visited, referenced, this, solutionConfiguration);

                ReadOnlyCollection <SolutionItem> sortedReferenced = SolutionFolder.TopologicalSort(referenced, solutionConfiguration);

                BuildResult cres = new BuildResult();
                cres.BuildCount = 0;
                HashSet <SolutionItem> failedItems = new HashSet <SolutionItem> ();

                monitor.BeginTask(null, sortedReferenced.Count);
                foreach (SolutionItem p in sortedReferenced)
                {
                    if (!p.ContainsReferences(failedItems, solutionConfiguration))
                    {
                        BuildResult res = p.Build(monitor, solutionConfiguration, false);
                        cres.Append(res);
                        if (res.ErrorCount > 0)
                        {
                            failedItems.Add(p);
                        }
                    }
                    else
                    {
                        failedItems.Add(p);
                    }
                    monitor.Step(1);
                    if (monitor.IsCancelRequested)
                    {
                        break;
                    }
                }
                monitor.EndTask();
                return(cres);
            } finally {
                tt.End();
            }
        }
Exemplo n.º 4
0
 public DummySolutionFolderHandler(SolutionFolder folder)
 {
     this.folder = folder;
 }
Exemplo n.º 5
0
        public void SolutionItemsEvents()
        {
            int countFileAddedToProject          = 0;
            int countFileRemovedFromProject      = 0;
            int countFileRenamedInProject        = 0;
            int countReferenceAddedToProject     = 0;
            int countReferenceRemovedFromProject = 0;
            int countSolutionItemAdded           = 0;
            int countSolutionItemRemoved         = 0;

            Solution sol = new Solution();

            sol.FileAddedToProject += delegate {
                countFileAddedToProject++;
            };
            sol.FileRemovedFromProject += delegate {
                countFileRemovedFromProject++;
            };
            sol.FileRenamedInProject += delegate {
                countFileRenamedInProject++;
            };
            sol.ReferenceAddedToProject += delegate {
                countReferenceAddedToProject++;
            };
            sol.ReferenceRemovedFromProject += delegate {
                countReferenceRemovedFromProject++;
            };
            sol.SolutionItemAdded += delegate {
                countSolutionItemAdded++;
            };
            sol.SolutionItemRemoved += delegate {
                countSolutionItemRemoved++;
            };

            Assert.AreEqual(0, countFileAddedToProject);
            Assert.AreEqual(0, countFileRemovedFromProject);
            Assert.AreEqual(0, countFileRenamedInProject);
            Assert.AreEqual(0, countReferenceAddedToProject);
            Assert.AreEqual(0, countReferenceRemovedFromProject);
            Assert.AreEqual(0, countSolutionItemAdded);
            Assert.AreEqual(0, countSolutionItemRemoved);

            SolutionFolder folder = new SolutionFolder();

            folder.Name = "Folder1";
            sol.RootFolder.Items.Add(folder);

            Assert.AreEqual(1, countSolutionItemAdded);
            Assert.AreEqual(0, sol.Items.Count);

            var project = Services.ProjectService.CreateDotNetProject("C#");

            project.Name = "project1";
            sol.RootFolder.Items.Add(project);

            Assert.AreEqual(2, countSolutionItemAdded);
            Assert.AreEqual(1, sol.Items.Count);

            var project2 = Services.ProjectService.CreateDotNetProject("C#");

            project2.Name = "project2";
            folder.Items.Add(project2);

            Assert.AreEqual(3, countSolutionItemAdded);
            Assert.AreEqual(2, sol.Items.Count);

            ProjectFile p1 = new ProjectFile("test1.cs");

            project2.Files.Add(p1);
            Assert.AreEqual(1, countFileAddedToProject);

            ProjectFile p2 = new ProjectFile("test1.cs");

            project.Files.Add(p2);
            Assert.AreEqual(2, countFileAddedToProject);

            p1.Name = "test2.cs";
            Assert.AreEqual(1, countFileRenamedInProject);

            p2.Name = "test2.cs";
            Assert.AreEqual(2, countFileRenamedInProject);

            project2.Files.Remove(p1);
            Assert.AreEqual(1, countFileRemovedFromProject);

            project.Files.Remove("test2.cs");
            Assert.AreEqual(2, countFileRemovedFromProject);

            ProjectReference pr1 = ProjectReference.CreateAssemblyReference("SomeTest");

            project.References.Add(pr1);
            Assert.AreEqual(1, countReferenceAddedToProject);

            ProjectReference pr2 = ProjectReference.CreateProjectReference(project);

            project2.References.Add(pr2);
            Assert.AreEqual(2, countReferenceAddedToProject);

            project.References.Remove(pr1);
            Assert.AreEqual(1, countReferenceRemovedFromProject);

            sol.RootFolder.Items.Remove(project);
            Assert.AreEqual(2, countReferenceRemovedFromProject, "Removing a project must remove all references to it");
            Assert.AreEqual(1, countSolutionItemRemoved);
            Assert.AreEqual(1, sol.Items.Count);

            folder.Items.Remove(project2);
            Assert.AreEqual(2, countSolutionItemRemoved);
            Assert.AreEqual(0, sol.Items.Count);

            sol.RootFolder.Items.Remove(folder);

            Assert.AreEqual(2, countFileAddedToProject);
            Assert.AreEqual(2, countFileRemovedFromProject);
            Assert.AreEqual(2, countFileRenamedInProject);
            Assert.AreEqual(2, countReferenceAddedToProject);
            Assert.AreEqual(2, countReferenceRemovedFromProject);
            Assert.AreEqual(3, countSolutionItemAdded);
            Assert.AreEqual(3, countSolutionItemRemoved);
        }
Exemplo n.º 6
0
        public void SolutionBoundUnbound()
        {
            Solution sol = new Solution();

            var e = new SomeItem();

            Assert.AreEqual(0, e.BoundEvents);
            Assert.AreEqual(0, e.UnboundEvents);

            sol.RootFolder.AddItem(e);
            Assert.AreEqual(1, e.BoundEvents);
            Assert.AreEqual(0, e.UnboundEvents);
            Assert.AreEqual(1, e.InternalItem.BoundEvents);
            Assert.AreEqual(0, e.InternalItem.UnboundEvents);

            e.Reset();
            sol.RootFolder.Items.Remove(e);
            Assert.AreEqual(0, e.BoundEvents);
            Assert.AreEqual(1, e.UnboundEvents);
            Assert.AreEqual(0, e.InternalItem.BoundEvents);
            Assert.AreEqual(1, e.InternalItem.UnboundEvents);

            e.Reset();
            sol.RootFolder.AddItem(e);
            Assert.AreEqual(1, e.BoundEvents);
            Assert.AreEqual(0, e.UnboundEvents);
            Assert.AreEqual(1, e.InternalItem.BoundEvents);
            Assert.AreEqual(0, e.InternalItem.UnboundEvents);

            e.Reset();
            sol.RootFolder.Items.Remove(e);
            Assert.AreEqual(0, e.BoundEvents);
            Assert.AreEqual(1, e.UnboundEvents);
            Assert.AreEqual(0, e.InternalItem.BoundEvents);
            Assert.AreEqual(1, e.InternalItem.UnboundEvents);

            e.Reset();
            var f = new SolutionFolder();

            f.AddItem(e);
            Assert.AreEqual(0, e.BoundEvents);
            Assert.AreEqual(0, e.UnboundEvents);
            Assert.AreEqual(0, e.InternalItem.BoundEvents);
            Assert.AreEqual(0, e.InternalItem.UnboundEvents);

            sol.RootFolder.AddItem(f);
            Assert.AreEqual(1, e.BoundEvents);
            Assert.AreEqual(0, e.UnboundEvents);
            Assert.AreEqual(1, e.InternalItem.BoundEvents);
            Assert.AreEqual(0, e.InternalItem.UnboundEvents);

            e.Reset();
            sol.RootFolder.Items.Remove(f);
            Assert.AreEqual(0, e.BoundEvents);
            Assert.AreEqual(1, e.UnboundEvents);
            Assert.AreEqual(0, e.InternalItem.BoundEvents);
            Assert.AreEqual(1, e.InternalItem.UnboundEvents);

            f.Dispose();
            sol.Dispose();
        }
Exemplo n.º 7
0
        public async Task BuildingAndCleaning()
        {
            string solFile = Util.GetSampleProject("console-with-libs", "console-with-libs.sln");

            Solution sol = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), solFile);

            DotNetProject p    = (DotNetProject)sol.FindProjectByName("console-with-libs");
            DotNetProject lib1 = (DotNetProject)sol.FindProjectByName("library1");
            DotNetProject lib2 = (DotNetProject)sol.FindProjectByName("library2");

            SolutionFolder folder = new SolutionFolder();

            folder.Name = "subfolder";
            sol.RootFolder.Items.Add(folder);
            sol.RootFolder.Items.Remove(lib2);
            folder.Items.Add(lib2);

            Workspace ws = new Workspace();

            ws.FileName = Path.Combine(sol.BaseDirectory, "workspace");
            ws.Items.Add(sol);
            await ws.SaveAsync(Util.GetMonitor());

            // Build the project and the references

            BuildResult res = await ws.Build(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(3, res.BuildCount);

            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the workspace

            await ws.Clean(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Build the solution

            res = await ws.Build(Util.GetMonitor(), ConfigurationSelector.Default);

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(3, res.BuildCount);

            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsTrue(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the solution

            await sol.Clean(Util.GetMonitor(), "Debug");

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Build the solution folder

            res = await folder.Build(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug");

            Assert.AreEqual(0, res.ErrorCount);
            Assert.AreEqual(0, res.WarningCount);
            Assert.AreEqual(1, res.BuildCount);

            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", "console-with-libs.exe")));
            Assert.IsFalse(File.Exists(Util.Combine(p.BaseDirectory, "bin", "Debug", GetMdb(p, "console-with-libs.exe"))));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", "library1.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib1.BaseDirectory, "bin", "Debug", GetMdb(lib1, "library1.dll"))));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsTrue(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));

            // Clean the solution folder

            await folder.Clean(Util.GetMonitor(), (SolutionConfigurationSelector)"Debug");

            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", "library2.dll")));
            Assert.IsFalse(File.Exists(Util.Combine(lib2.BaseDirectory, "bin", "Debug", GetMdb(lib2, "library2.dll"))));
            sol.Dispose();
        }
Exemplo n.º 8
0
        public static async Task TestLoadSaveSolutionFolders(MSBuildFileFormat fileFormat)
        {
            List <string> ids = new List <string> ();

            Solution sol = new Solution();

            sol.ConvertToFormat(fileFormat);
            string dir = Util.CreateTmpDir("solution-folders-" + fileFormat.Name);

            sol.FileName = Path.Combine(dir, "TestSolutionFolders");
            sol.Name     = "TheSolution";

            var p1 = Services.ProjectService.CreateDotNetProject("C#");

            p1.FileName = Path.Combine(dir, "p1");
            sol.RootFolder.Items.Add(p1);
            string idp1 = p1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp1));
            Assert.IsFalse(ids.Contains(idp1));
            ids.Add(idp1);

            SolutionFolder f1 = new SolutionFolder();

            f1.Name = "f1";
            sol.RootFolder.Items.Add(f1);
            string idf1 = f1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf1));
            Assert.IsFalse(ids.Contains(idf1));
            ids.Add(idf1);

            var p2 = Services.ProjectService.CreateDotNetProject("C#");

            p2.FileName = Path.Combine(dir, "p2");
            f1.Items.Add(p2);
            string idp2 = p2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp2));
            Assert.IsFalse(ids.Contains(idp2));
            ids.Add(idp2);

            SolutionFolder f2 = new SolutionFolder();

            f2.Name = "f2";
            f1.Items.Add(f2);
            string idf2 = f2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf2));
            Assert.IsFalse(ids.Contains(idf2));
            ids.Add(idf2);

            var p3 = Services.ProjectService.CreateDotNetProject("C#");

            p3.FileName = Path.Combine(dir, "p3");
            f2.Items.Add(p3);
            string idp3 = p3.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp3));
            Assert.IsFalse(ids.Contains(idp3));
            ids.Add(idp3);

            var p4 = Services.ProjectService.CreateDotNetProject("C#");

            p4.FileName = Path.Combine(dir, "p4");
            f2.Items.Add(p4);
            string idp4 = p4.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp4));
            Assert.IsFalse(ids.Contains(idp4));
            ids.Add(idp4);

            await sol.SaveAsync(Util.GetMonitor());

            Solution sol2 = (Solution)await Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName);

            Assert.AreEqual(4, sol2.Items.Count);
            Assert.AreEqual(2, sol2.RootFolder.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", sol2.RootFolder.Items[0].GetType().FullName);
            Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType());
            Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name);
            Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name);
            Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
            Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1");

            f1 = (SolutionFolder)sol2.RootFolder.Items [1];
            Assert.AreEqual(2, f1.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f1.Items [0].GetType().FullName);
            Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType());
            Assert.AreEqual("p2", f1.Items [0].Name);
            Assert.AreEqual("f2", f1.Items [1].Name);
            Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2");
            Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2");

            f2 = (SolutionFolder)f1.Items [1];
            Assert.AreEqual(2, f2.Items.Count);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f2.Items [0].GetType().FullName);
            Assert.AreEqual("MonoDevelop.CSharp.Project.CSharpProject", f2.Items [1].GetType().FullName);
            Assert.AreEqual("p3", f2.Items [0].Name);
            Assert.AreEqual("p4", f2.Items [1].Name);
            Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4");
            Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4");

            sol.Dispose();
        }
Exemplo n.º 9
0
        public static void TestLoadSaveSolutionFolders(string fileFormat)
        {
            List <string> ids = new List <string> ();

            Solution sol = new Solution();

            sol.ConvertToFormat(Services.ProjectService.FileFormats.GetFileFormat(fileFormat), true);
            string dir = Util.CreateTmpDir("solution-folders-" + fileFormat);

            sol.FileName = Path.Combine(dir, "TestSolutionFolders");
            sol.Name     = "TheSolution";

            DotNetAssemblyProject p1 = new DotNetAssemblyProject("C#");

            p1.FileName = Path.Combine(dir, "p1");
            sol.RootFolder.Items.Add(p1);
            string idp1 = p1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp1));
            Assert.IsFalse(ids.Contains(idp1));
            ids.Add(idp1);

            SolutionFolder f1 = new SolutionFolder();

            f1.Name = "f1";
            sol.RootFolder.Items.Add(f1);
            string idf1 = f1.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf1));
            Assert.IsFalse(ids.Contains(idf1));
            ids.Add(idf1);

            DotNetAssemblyProject p2 = new DotNetAssemblyProject("C#");

            p2.FileName = Path.Combine(dir, "p2");
            f1.Items.Add(p2);
            string idp2 = p2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp2));
            Assert.IsFalse(ids.Contains(idp2));
            ids.Add(idp2);

            SolutionFolder f2 = new SolutionFolder();

            f2.Name = "f2";
            f1.Items.Add(f2);
            string idf2 = f2.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idf2));
            Assert.IsFalse(ids.Contains(idf2));
            ids.Add(idf2);

            DotNetAssemblyProject p3 = new DotNetAssemblyProject("C#");

            p3.FileName = Path.Combine(dir, "p3");
            f2.Items.Add(p3);
            string idp3 = p3.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp3));
            Assert.IsFalse(ids.Contains(idp3));
            ids.Add(idp3);

            DotNetAssemblyProject p4 = new DotNetAssemblyProject("C#");

            p4.FileName = Path.Combine(dir, "p4");
            f2.Items.Add(p4);
            string idp4 = p4.ItemId;

            Assert.IsFalse(string.IsNullOrEmpty(idp4));
            Assert.IsFalse(ids.Contains(idp4));
            ids.Add(idp4);

            sol.Save(Util.GetMonitor());

            Solution sol2 = (Solution)Services.ProjectService.ReadWorkspaceItem(Util.GetMonitor(), sol.FileName);

            Assert.AreEqual(4, sol2.Items.Count);
            Assert.AreEqual(2, sol2.RootFolder.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), sol2.RootFolder.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), sol2.RootFolder.Items [1].GetType());
            Assert.AreEqual("p1", sol2.RootFolder.Items [0].Name);
            Assert.AreEqual("f1", sol2.RootFolder.Items [1].Name);
            Assert.AreEqual(idp1, sol2.RootFolder.Items [0].ItemId, "idp1");
            Assert.AreEqual(idf1, sol2.RootFolder.Items [1].ItemId, "idf1");

            f1 = (SolutionFolder)sol2.RootFolder.Items [1];
            Assert.AreEqual(2, f1.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), f1.Items [0].GetType());
            Assert.AreEqual(typeof(SolutionFolder), f1.Items [1].GetType());
            Assert.AreEqual("p2", f1.Items [0].Name);
            Assert.AreEqual("f2", f1.Items [1].Name);
            Assert.AreEqual(idp2, f1.Items [0].ItemId, "idp2");
            Assert.AreEqual(idf2, f1.Items [1].ItemId, "idf2");

            f2 = (SolutionFolder)f1.Items [1];
            Assert.AreEqual(2, f2.Items.Count);
            Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [0].GetType());
            Assert.AreEqual(typeof(DotNetAssemblyProject), f2.Items [1].GetType());
            Assert.AreEqual("p3", f2.Items [0].Name);
            Assert.AreEqual("p4", f2.Items [1].Name);
            Assert.AreEqual(idp3, f2.Items [0].ItemId, "idp4");
            Assert.AreEqual(idp4, f2.Items [1].ItemId, "idp4");
        }
Exemplo n.º 10
0
        public static Solution CreateProjectWithFolders(string hint)
        {
            string dir = Util.CreateTmpDir(hint);

            Directory.CreateDirectory(Util.Combine(dir, "console-project"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1", "library1"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution1", "library2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "console-project2"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3", "library3"));
            Directory.CreateDirectory(Util.Combine(dir, "nested-solution2", "nested-solution3", "library4"));

            Solution sol = new Solution();

            sol.FileName = Path.Combine(dir, "nested-solutions-mdp");
            SolutionConfiguration scDebug   = sol.AddConfiguration("Debug", true);
            SolutionConfiguration scRelease = sol.AddConfiguration("Release", true);

            DotNetProject project1 = CreateProject(Util.Combine(dir, "console-project"), "C#", "console-project");

            project1.Files.Add(new ProjectFile(Path.Combine(project1.BaseDirectory, "Program.cs")));
            project1.Files.Add(new ProjectFile(Path.Combine(project1.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            sol.RootFolder.Items.Add(project1);

            // nested-solution1

            SolutionFolder folder1 = new SolutionFolder();

            sol.RootFolder.Items.Add(folder1);
            folder1.Name = "nested-solution1";

            DotNetProject projectLib1 = CreateProject(Util.Combine(dir, "nested-solution1", "library1"), "C#", "library1");

            projectLib1.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib1.Files.Add(new ProjectFile(Path.Combine(projectLib1.BaseDirectory, "MyClass.cs")));
            projectLib1.Files.Add(new ProjectFile(Path.Combine(projectLib1.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            projectLib1.CompileTarget = CompileTarget.Library;
            folder1.Items.Add(projectLib1);

            DotNetProject projectLib2 = CreateProject(Util.Combine(dir, "nested-solution1", "library2"), "C#", "library2");

            projectLib2.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib2.Files.Add(new ProjectFile(Path.Combine(projectLib2.BaseDirectory, "MyClass.cs")));
            projectLib2.Files.Add(new ProjectFile(Path.Combine(projectLib2.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            projectLib2.CompileTarget = CompileTarget.Library;
            folder1.Items.Add(projectLib2);

            // nested-solution2

            SolutionFolder folder2 = new SolutionFolder();

            folder2.Name = "nested-solution2";
            sol.RootFolder.Items.Add(folder2);

            DotNetProject project2 = CreateProject(Util.Combine(dir, "nested-solution2", "console-project2"), "C#", "console-project2");

            project2.Files.Add(new ProjectFile(Path.Combine(project2.BaseDirectory, "Program.cs")));
            project2.Files.Add(new ProjectFile(Path.Combine(project2.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            project2.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));

            // nested-solution3

            SolutionFolder folder3 = new SolutionFolder();

            folder3.Name = "nested-solution3";

            DotNetProject projectLib3 = CreateProject(Util.Combine(dir, "nested-solution2", "nested-solution3", "library3"), "C#", "library3");

            projectLib3.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib3.Files.Add(new ProjectFile(Path.Combine(projectLib3.BaseDirectory, "MyClass.cs")));
            projectLib3.Files.Add(new ProjectFile(Path.Combine(projectLib3.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            projectLib3.CompileTarget = CompileTarget.Library;
            folder3.Items.Add(projectLib3);

            DotNetProject projectLib4 = CreateProject(Util.Combine(dir, "nested-solution2", "nested-solution3", "library4"), "C#", "library4");

            projectLib4.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            projectLib4.Files.Add(new ProjectFile(Path.Combine(projectLib4.BaseDirectory, "MyClass.cs")));
            projectLib4.Files.Add(new ProjectFile(Path.Combine(projectLib4.BaseDirectory, "Properties", "AssemblyInfo.cs")));
            projectLib4.CompileTarget = CompileTarget.Library;
            folder3.Items.Add(projectLib4);

            folder2.Items.Add(folder3);
            folder2.Items.Add(project2);

            string file = Path.Combine(dir, "TestSolution.sln");

            sol.FileName = file;

            project1.References.Add(new ProjectReference(ReferenceType.Package, "System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"));
            project1.References.Add(new ProjectReference(projectLib1));
            project1.References.Add(new ProjectReference(projectLib2));
            project1.References.Add(new ProjectReference(projectLib3));
            project1.References.Add(new ProjectReference(projectLib4));

            project2.References.Add(new ProjectReference(projectLib3));
            project2.References.Add(new ProjectReference(projectLib4));

            Assert.AreEqual(2, sol.Configurations.Count);
            Assert.AreEqual(6, scDebug.Configurations.Count);
            Assert.AreEqual(6, scRelease.Configurations.Count);

            return(sol);
        }
Exemplo n.º 11
0
        public void ModelQueries()
        {
            DotNetProject     it2, it3, it4;
            DummySolutionItem it1;
            string            someFile, someId;

            Workspace ws  = new Workspace();
            Workspace cws = new Workspace();

            ws.Items.Add(cws);

            Solution sol1 = new Solution();

            cws.Items.Add(sol1);
            sol1.RootFolder.Items.Add(it1 = new DummySolutionItem());
            sol1.RootFolder.Items.Add(it2 = Services.ProjectService.CreateDotNetProject("C#"));

            Solution sol2 = new Solution();

            cws.Items.Add(sol2);
            SolutionFolder f = new SolutionFolder();

            sol2.RootFolder.Items.Add(f);
            f.Items.Add(it3 = Services.ProjectService.CreateDotNetProject("C#"));
            f.Items.Add(it4 = Services.ProjectService.CreateDotNetProject("C#"));

            it3.Name     = "it3";
            it4.FileName = "/test/it4";
            someFile     = it4.FileName;
            someId       = it3.ItemId;
            Assert.IsFalse(string.IsNullOrEmpty(someId));

            Assert.AreEqual(2, sol1.Items.Count);
            Assert.IsTrue(sol1.Items.Contains(it1));
            Assert.IsTrue(sol1.Items.Contains(it2));

            Assert.AreEqual(2, sol2.Items.Count);
            Assert.IsTrue(sol2.Items.Contains(it3));
            Assert.IsTrue(sol2.Items.Contains(it4));

            var its = ws.GetAllItems <SolutionFolderItem> ().ToList();

            Assert.AreEqual(7, its.Count);
            Assert.IsTrue(its.Contains(it1));
            Assert.IsTrue(its.Contains(it2));
            Assert.IsTrue(its.Contains(it3));
            Assert.IsTrue(its.Contains(it4));
            Assert.IsTrue(its.Contains(sol1.RootFolder));
            Assert.IsTrue(its.Contains(sol2.RootFolder));
            Assert.IsTrue(its.Contains(f));

            var its2 = ws.GetAllItems <DotNetProject> ().ToList();

            Assert.AreEqual(3, its2.Count);
            Assert.IsTrue(its2.Contains(it2));
            Assert.IsTrue(its2.Contains(it3));
            Assert.IsTrue(its2.Contains(it4));

            var its3 = ws.GetAllItems <Project> ().ToList();

            Assert.AreEqual(3, its3.Count);
            Assert.IsTrue(its3.Contains(it2));
            Assert.IsTrue(its3.Contains(it3));
            Assert.IsTrue(its3.Contains(it4));

            var its4 = ws.GetAllItems <Solution> ().ToList();

            Assert.AreEqual(2, its4.Count);
            Assert.IsTrue(its4.Contains(sol1));
            Assert.IsTrue(its4.Contains(sol2));

            var its5 = ws.GetAllItems <WorkspaceItem> ().ToList();

            Assert.AreEqual(4, its5.Count);
            Assert.IsTrue(its5.Contains(ws));
            Assert.IsTrue(its5.Contains(cws));
            Assert.IsTrue(its5.Contains(sol2));
            Assert.IsTrue(its5.Contains(sol2));

            var its6 = ws.GetAllItems <Workspace> ().ToList();

            Assert.AreEqual(2, its6.Count);
            Assert.IsTrue(its6.Contains(ws));
            Assert.IsTrue(its6.Contains(cws));

            SolutionFolderItem si = sol2.GetSolutionItem(someId);

            Assert.AreEqual(it3, si);

            SolutionItem fi = sol2.FindSolutionItem(someFile);

            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it3");
            Assert.AreEqual(it3, fi);

            fi = sol2.FindProjectByName("it4");
            Assert.AreEqual(it4, fi);

            fi = sol2.FindProjectByName("it2");
            Assert.IsNull(fi);

            ws.Dispose();
            cws.Dispose();
        }