Exemplo n.º 1
0
        // This method includes policy for copying a logged file over to the
        // test log directory for archival.
        public void LogFile(string fileName)
        {
            FileInfo fileInfo = new FileInfo(fileName);

            if (!fileInfo.Exists)
            {
                LogMessage("Test attempted to log the file " + fileInfo.FullName + ", which doesn't exist.");
                return;
            }

            // This logic will need to be revised when we add ExecutionGroups, likely by having
            // another level of hierarchy for test name. For now the algorithm is simple
            // enough I'll leave it here - it may make sense to break it out into a separate
            // method if it becomes notably more complex.

            // Determine the directory into which logged files should be copied.
            // We start with the test log directory were are given for the test,
            // where a logged file will go by default. If there is a current
            // variation, however, we'll log the file to a subfolder named based
            // on the variation index. This allows per-variation logged file
            // isolation. For example, each variation in a test may log some
            // result evidence file with the same name, and we don't want those
            // overwriting each other.
            string computedDirectoryPath = Path.Combine(testLogDirectory.FullName, ("T" + currentTestIndex.ToString()));

            if (LoggingState == LoggingState.HasVariation)
            {
                computedDirectoryPath = Path.Combine(computedDirectoryPath, ("V" + currentVariationIndex.ToString()));
            }

            if (!Directory.Exists(computedDirectoryPath))
            {
                Directory.CreateDirectory(computedDirectoryPath);
            }

            FileInfo newFile = fileInfo.CopyTo(Path.Combine(computedDirectoryPath, fileInfo.Name), true);

            Loggers.LogFile(newFile.FullName);
        }