示例#1
0
        /// <summary>
        /// Composes the filename for an observation file for the test
        /// </summary>
        /// <param name="testMethod">The test method that's running either as a generator or an observation test.</param>
        /// <param name="fileIdentity">The base fileIdentity of the observation file.</param>
        /// <param name="contextName"></param>
        /// <param name="args">The arguments being passed into the test method.</param>
        /// <returns></returns>
        public static string ComposeObservationFilename(TestMethodEntity testMethod, string fileIdentity, string contextName, TestArgs args)
        {
            string argsNamePart = null;

            if (args != null)
            {
                argsNamePart = UnitTestsUtil.GetTestArgsDisplayText(testMethod, args, false);
                // For now, lets just keep the text the same, just escape any special chars
                var invalidChars = System.IO.Path.GetInvalidFileNameChars()
                                   .Concat(new[] { '.', '$', '#' })
                                   .Where(c => argsNamePart.IndexOf(c) != -1)
                                   .ToArray();
                foreach (var c in invalidChars)
                {
                    argsNamePart = argsNamePart.Replace(c, '_');
                }
            }

            string filename;

            // If there's no context name or args, then just return the fileIdentity w/o annotating it
            if (String.IsNullOrEmpty(contextName) && String.IsNullOrEmpty(argsNamePart))
            {
                filename = fileIdentity;
            }
            else
            {
                // Annotate the file identity with the context name and arguments
                if (String.IsNullOrEmpty(argsNamePart))
                {
                    filename = String.Concat(fileIdentity, ObservationFilenamePartSeparator, contextName);
                }
                else
                {
                    filename = String.Concat(fileIdentity, ObservationFilenamePartSeparator, contextName, ObservationFilenamePartSeparator, args);
                }
            }

            // And finally, append the extension
            return(filename + ObservationFileExtension);
        }
示例#2
0
 private string GetDefaultObservationFileIdentity()
 {
     // Use the full name of the test method
     return(UnitTestsUtil.GetTestMethodFullName(OwningTestMethod));
 }