public void VerifyInvalidSchemaItself1
        (
        )
        {
            string invalidSchemaFile = null;

            try
            {
                // Create schema files in the temp folder
                invalidSchemaFile = Path.GetTempFileName();

                File.WriteAllText(invalidSchemaFile, "<this_is_invalid_schema_content/>");

                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine buildEngine = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, buildEngine.LoggingServices, @"c:\");

                try
                {
                    validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents), invalidSchemaFile);
                }
                catch (InvalidProjectFileException e)
                {
                    Console.WriteLine(e.Message);
                    Assertion.Assert(e.ErrorCode.Contains("MSB4070") || e.BaseMessage.Contains("MSB4070"));

                    throw;
                }
            }
            finally
            {
                if (invalidSchemaFile != null)
                {
                    File.Delete(invalidSchemaFile);
                }
            }
        }
        public void VerifyInvalidProjectSchema
        (
        )
        {
            string[] msbuildTempXsdFilenames = new string[] {};
            try
            {
                // Create schema files in the temp folder
                msbuildTempXsdFilenames = PrepareSchemaFiles();

                string projectContents = @"
                    <Project xmlns=`msbuildnamespace`>
                        <MyInvalidTag/>
                        <Target Name=`Build` />
                    </Project>
                    ";

                Engine buildEngine = new Engine(@"c:\");
                ProjectSchemaValidationHandler validator = new ProjectSchemaValidationHandler(null, buildEngine.LoggingServices, @"c:\");

                try
                {
                    validator.VerifyProjectSchema(ObjectModelHelpers.CleanupFileContents(projectContents),
                                                  msbuildTempXsdFilenames[0]);
                }
                catch (InvalidProjectFileException e)
                {
                    Assertion.AssertEquals(e.BaseMessage, ResourceUtilities.FormatResourceString("ProjectSchemaErrorHalt"));

                    throw;
                }
            }
            finally
            {
                CleanupSchemaFiles(msbuildTempXsdFilenames);
            }
        }
Exemple #3
0
 internal static string WriteConfigFile(string content)
 {
     return(WriteConfigFile(ObjectModelHelpers.CleanupFileContents(content), null));
 }