public void IncludingProjectAddedAfterShared()
        {
            var sol = new Solution ();
            var shared = new SharedAssetsProject ("C#");
            shared.AddFile ("Foo.cs");

            sol.RootFolder.AddItem (shared);

            // Reference to shared is added before adding project to solution
            var main = new DotNetAssemblyProject ("C#");
            main.References.Add (new ProjectReference (shared));
            sol.RootFolder.AddItem (main);

            Assert.IsNotNull (main.Files.GetFile ("Foo.cs"));
        }
		public void SaveSharedProject ()
		{
			Solution sol = TestProjectsChecks.CreateConsoleSolution ("shared-project");
			sol.ConvertToFormat (Util.FileFormatMSBuild12, true);
			sol.Save (Util.GetMonitor ());

			var pc = (DotNetProject) sol.Items [0];

			// Add shared project

			var sp = new SharedAssetsProject () {
				LanguageName = "C#",
				DefaultNamespace = "TestNamespace"
			};

			sp.AddFile (sol.ItemDirectory.Combine ("Test.cs"));
			sp.Save (sol.ItemDirectory.Combine ("Shared"), Util.GetMonitor ());

			sol.RootFolder.AddItem (sp);
			sol.Save (Util.GetMonitor ());

			// Make sure we compare using the same guid

			string solXml = File.ReadAllText (sol.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			string projectXml = Util.GetXmlFileInfoset (pc.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
			string sharedProjectXml = Util.GetXmlFileInfoset (sp.FileName).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			string sharedProjectItemsXml = Util.GetXmlFileInfoset (sp.FileName.ChangeExtension (".projitems")).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

			string refSolXml = Util.ToWindowsEndings (File.ReadAllText (Util.GetSampleProjectPath ("generated-shared-project", "TestSolution.sln")));
			string refProjectXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "TestProject.csproj")));
			string refSharedProjectXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "Shared.shproj")));
			string refSharedProjectItemsXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "Shared.projitems")));

			Assert.AreEqual (refSolXml, solXml);
			Assert.AreEqual (refProjectXml, projectXml);
			Assert.AreEqual (refSharedProjectXml, sharedProjectXml);
			Assert.AreEqual (refSharedProjectItemsXml, sharedProjectItemsXml);

			// Add a reference

			var r = new ProjectReference (sp);
			pc.References.Add (r);
			sol.Save (Util.GetMonitor ());

			solXml = File.ReadAllText (sol.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			projectXml = Util.GetXmlFileInfoset (pc.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
			sharedProjectXml = Util.GetXmlFileInfoset (sp.FileName).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			sharedProjectItemsXml = Util.GetXmlFileInfoset (sp.FileName.ChangeExtension (".projitems")).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

			refProjectXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "TestProject.csproj.saved1")));

			Assert.AreEqual (refSolXml, solXml);
			Assert.AreEqual (refProjectXml, projectXml);
			Assert.AreEqual (refSharedProjectXml, sharedProjectXml);
			Assert.AreEqual (refSharedProjectItemsXml, sharedProjectItemsXml);

			// Add a file and change the default namespace

			sp.DefaultNamespace = "TestNamespace2";
			var file = sp.AddFile (sol.ItemDirectory.Combine ("Test2.cs"));
			sol.Save (Util.GetMonitor ());

			solXml = File.ReadAllText (sol.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			projectXml = Util.GetXmlFileInfoset (pc.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
			sharedProjectXml = Util.GetXmlFileInfoset (sp.FileName).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			sharedProjectItemsXml = Util.GetXmlFileInfoset (sp.FileName.ChangeExtension (".projitems")).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

			refSharedProjectItemsXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "Shared.projitems.saved1")));

			Assert.AreEqual (refSolXml, solXml);
			Assert.AreEqual (refProjectXml, projectXml);
			Assert.AreEqual (refSharedProjectXml, sharedProjectXml);
			Assert.AreEqual (refSharedProjectItemsXml, sharedProjectItemsXml);

			// Remove a file and restore the namespace

			sp.DefaultNamespace = "TestNamespace";
			sp.Files.Remove (file);
			sol.Save (Util.GetMonitor ());

			solXml = File.ReadAllText (sol.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			projectXml = Util.GetXmlFileInfoset (pc.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
			sharedProjectXml = Util.GetXmlFileInfoset (sp.FileName).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			sharedProjectItemsXml = Util.GetXmlFileInfoset (sp.FileName.ChangeExtension (".projitems")).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

			refSharedProjectItemsXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "Shared.projitems")));

			Assert.AreEqual (refSolXml, solXml);
			Assert.AreEqual (refProjectXml, projectXml);
			Assert.AreEqual (refSharedProjectXml, sharedProjectXml);
			Assert.AreEqual (refSharedProjectItemsXml, sharedProjectItemsXml);

			// Remove reference

			pc.References.Remove (r);
			sol.Save (Util.GetMonitor ());

			solXml = File.ReadAllText (sol.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}").Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			projectXml = Util.GetXmlFileInfoset (pc.FileName).Replace (pc.ItemId, "{7DE4B613-BAB6-49DE-83FA-707D4E120306}");
			sharedProjectXml = Util.GetXmlFileInfoset (sp.FileName).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");
			sharedProjectItemsXml = Util.GetXmlFileInfoset (sp.FileName.ChangeExtension (".projitems")).Replace (sp.ItemId, "{8DD793BE-42C3-4D66-8359-460CEE75980D}");

			refProjectXml = Util.ToWindowsEndings (Util.GetXmlFileInfoset (Util.GetSampleProjectPath ("generated-shared-project", "TestProject.csproj")));

			Assert.AreEqual (refSolXml, solXml);
			Assert.AreEqual (refProjectXml, projectXml);
			Assert.AreEqual (refSharedProjectXml, sharedProjectXml);
			Assert.AreEqual (refSharedProjectItemsXml, sharedProjectItemsXml);
		}
        public void RemoveSharedProjectFromSolution()
        {
            var sol = new Solution ();

            var shared = new SharedAssetsProject ("C#");
            shared.AddFile ("Foo.cs");

            var main = new DotNetAssemblyProject ("C#");
            var pref = new ProjectReference (shared);
            main.References.Add (pref);

            sol.RootFolder.AddItem (main);
            sol.RootFolder.AddItem (shared);

            Assert.IsNotNull (main.Files.GetFile ("Foo.cs"));
            Assert.IsTrue (main.References.Contains (pref));

            sol.RootFolder.Items.Remove (shared);

            // The shared file and the reference must be gone.

            Assert.IsNull (main.Files.GetFile ("Foo.cs"));
            Assert.IsFalse (main.References.Contains (pref));
        }
		public void SharedProjectAddedAfterIncluder ()
		{
			var sol = new Solution ();
			var shared = new SharedAssetsProject ("C#");
			shared.AddFile ("Foo.cs");

			// Reference to shared is added before adding project to solution
			var main = Services.ProjectService.CreateDotNetProject ("C#");
			main.References.Add (ProjectReference.CreateProjectReference (shared));
			sol.RootFolder.AddItem (main);

			sol.RootFolder.AddItem (shared);

			Assert.IsNotNull (main.Files.GetFile ("Foo.cs"));
		}