예제 #1
0
        public void TestPerfLogDirectoryDoesNotExist()
        {
            using (TestEnvironment testEnv = TestEnvironment.Create(_output))
            {
                // Setup invalid perf log directory.
                TransientTestFolder perfLogFolder = testEnv.CreateFolder(createFolder: true);
                string perfLogPath = Path.Combine(perfLogFolder.Path, "logs");
                testEnv.SetEnvironmentVariable("DOTNET_PERFLOG_DIR", perfLogPath);

                // Setup project directory.
                TransientTestFolder projectFolder = testEnv.CreateFolder(createFolder: true);
                TransientTestFile   classLibrary  = testEnv.CreateFile(projectFolder, "ClassLibrary.csproj",
                                                                       @"<Project>
                  <Target Name=""ClassLibraryTarget"">
                      <Message Text=""ClassLibraryBuilt""/>
                  </Target>
                  </Project>
                    ");

                string projectPath       = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
                string msbuildParameters = "\"" + projectPath + "\"";

                Directory.Exists(perfLogPath).ShouldBeFalse();

                RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
                successfulExit.ShouldBeTrue();

                Directory.Exists(perfLogPath).ShouldBeFalse();
            }
        }
예제 #2
0
        [Trait("Category", "mono-osx-failing")] // Disable on Mono OSX, since Mono doesn't implement EventSource.
        public void TestPerfLogEnabledProducedLogFile()
        {
            using (TestEnvironment testEnv = TestEnvironment.Create(_output))
            {
                // Setup perf log.
                TransientTestFolder perfLogFolder = testEnv.CreateFolder(createFolder: true);
                testEnv.SetEnvironmentVariable("DOTNET_PERFLOG_DIR", perfLogFolder.Path);

                // Setup project directory.
                TransientTestFolder projectFolder = testEnv.CreateFolder(createFolder: true);
                TransientTestFile   classLibrary  = testEnv.CreateFile(projectFolder, "ClassLibrary.csproj",
                                                                       @"<Project>
                  <Target Name=""ClassLibraryTarget"">
                      <Message Text=""ClassLibraryBuilt""/>
                  </Target>
                  </Project>
                    ");

                string projectPath       = Path.Combine(projectFolder.Path, "ClassLibrary.csproj");
                string msbuildParameters = "\"" + projectPath + "\"";

                RunnerUtilities.ExecMSBuild(msbuildParameters, out bool successfulExit);
                successfulExit.ShouldBeTrue();

                // Look for the file.
                // NOTE: We don't explicitly look for one file because it's possible that more components will add files that will show up here.
                // It's most important to ensure that at least one file shows up because any others that show up will be there because MSBuild properly
                // enabled this functionality.
                string[] files = Directory.GetFiles(perfLogFolder.Path, "perf-*.log");
                files.ShouldNotBeEmpty();
                files.ShouldAllBe(f => new FileInfo(f).Length > 0);
            }
        }
예제 #3
0
        public TransientTestFile CreateFile(TransientTestFolder transientTestFolder, string fileName, string contents = "")
        {
            var file = WithTransientTestState(new TransientTestFile(transientTestFolder.FolderPath, Path.GetFileNameWithoutExtension(fileName), Path.GetExtension(fileName)));

            File.WriteAllText(file.Path, contents);

            return(file);
        }
예제 #4
0
        public static TransientZipArchive Create(TransientTestFolder source, TransientTestFolder destination, string filename = "test.zip")
        {
            Directory.CreateDirectory(destination.Path);

            string path = System.IO.Path.Combine(destination.Path, filename);

            ZipFile.CreateFromDirectory(source.Path, path);

            return(new TransientZipArchive
            {
                Path = path
            });
        }
예제 #5
0
        public TransientTestProjectWithFiles(string projectContents, string[] files,
                                             string relativePathFromRootToProject = ".")
        {
            _folder = new TransientTestFolder();

            var projectDir = Path.GetFullPath(Path.Combine(TestRoot, relativePathFromRootToProject));

            Directory.CreateDirectory(projectDir);

            ProjectFile = Path.GetFullPath(Path.Combine(projectDir, "build.proj"));
            File.WriteAllText(ProjectFile, ObjectModelHelpers.CleanupFileContents(projectContents));

            CreatedFiles = Helpers.CreateFilesInDirectory(TestRoot, files);
        }
예제 #6
0
 /// <summary>
 /// Create a temp file name under a specific temporary folder. The file is expected to exist when the test completes.
 /// </summary>
 /// <param name="transientTestFolder">Temp folder</param>
 /// <param name="extension">Extension of the file (defaults to '.tmp')</param>
 /// <returns></returns>
 public TransientTestFile ExpectFile(TransientTestFolder transientTestFolder, string extension = ".tmp")
 {
     return(WithTransientTestState(new TransientTestFile(transientTestFolder.Path, extension, createFile: false, expectedAsOutput: true)));
 }
예제 #7
0
 public TransientTestFile CreateFile(TransientTestFolder transientTestFolder, string fileName, string contents = "")
 {
     return(WithTransientTestState(new TransientTestFile(transientTestFolder.Path, fileName, contents)));
 }
예제 #8
0
 /// <summary>
 ///     Creates a test variant that corresponds to a temporary file under a specific temporary folder. File will
 ///     be cleaned up when the test completes.
 /// </summary>
 /// <param name="transientTestFolder"></param>
 /// <param name="extension">Extension of the file (defaults to '.tmp')</param>
 public TransientTestFile CreateFile(TransientTestFolder transientTestFolder, string extension = ".tmp")
 {
     return(WithTransientTestState(new TransientTestFile(transientTestFolder.FolderPath, extension)));
 }