Esempio n. 1
0
        public void RemoveExistingImport()
        {
            ObjectModelHelpers.DeleteTempProjectDirectory();

            ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.proj", @"
                    <Project xmlns=`msbuildnamespace`>
                    </Project>
                ");

            ObjectModelHelpers.CreateFileInTempProjectDirectory("import2.proj", @"
                    <Project xmlns=`msbuildnamespace`>
                    </Project>
                ");

            ObjectModelHelpers.CreateFileInTempProjectDirectory("main.proj", @"

                    <Project xmlns=`msbuildnamespace`>

                        <Import Project=`import1.proj` />
                        <Import Project=`import2.proj` />

                        <Target Name=`Build`>
                            <WashCar/>
                        </Target>

                    </Project>

                ");

            Project project = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main.proj", null);

            ImportCollection imports = project.Imports;

            Assertion.AssertEquals(2, imports.Count);

            imports.RemoveImport(imports[Path.Combine(ObjectModelHelpers.TempProjectDir, "import1.proj")]);

            // First validate that the ImportCollection only contains a single Import
            Assertion.AssertEquals(1, imports.Count);

            // Now validate that the ImportCollection properly updated its parent Project (by inspecting the
            // project's in-memory Xml)
            int importCount = 0;

            foreach (XmlNode childNode in project.ProjectElement)
            {
                if (childNode.Name == XMakeElements.import)
                {
                    importCount++;
                }
            }

            Assertion.AssertEquals(1, importCount);
        }
Esempio n. 2
0
        public void AttemptToRemoveImportFromAnotherProjectShouldThrowException()
        {
            ObjectModelHelpers.DeleteTempProjectDirectory();

            ObjectModelHelpers.CreateFileInTempProjectDirectory("import1.proj", @"
                    <Project xmlns=`msbuildnamespace`>
                    </Project>
                ");

            ObjectModelHelpers.CreateFileInTempProjectDirectory("main1.proj", @"

                    <Project xmlns=`msbuildnamespace`>

                        <Import Project=`import1.proj` />
            
                        <Target Name=`Build`>
                            <WashCar/>
                        </Target>

                    </Project>

                ");

            ObjectModelHelpers.CreateFileInTempProjectDirectory("main2.proj", @"

                    <Project xmlns=`msbuildnamespace`>

                        <Import Project=`import1.proj` />
            
                        <Target Name=`Build`>
                            <WashCar/>
                        </Target>

                    </Project>

                ");

            Project project1 = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main1.proj", null);
            Project project2 = ObjectModelHelpers.LoadProjectFileInTempProjectDirectory("main2.proj", null);

            ImportCollection imports1 = project1.Imports;
            ImportCollection imports2 = project2.Imports;

            // Should throw an InvalidOperationException
            imports1.RemoveImport(imports2[Path.Combine(ObjectModelHelpers.TempProjectDir, "import1.proj")]);
        }