Example #1
0
        public static string GetTestArgsDisplayText(TestMethodEntity method, TestArgs args, bool withParamNames)
        {
            var methodParams = method.Parameters;

            if (methodParams == null || methodParams.Length == 0)
            {
                return(String.Empty);
            }

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < methodParams.Length && i < args.Values.Length; i++)
            {
                if (i > 0)
                {
                    sb.Append(", ");
                }

                var    param = methodParams[i];
                string arg   = args.Values[i];

                if (withParamNames)
                {
                    sb.Append(param.Name);
                    sb.Append('=');
                }
                AppendTestCaseArgument(sb, param.TypeName, arg);
            }

            return(sb.ToString());
        }
Example #2
0
        /// <summary>
        /// Gets the full name of the specified test method.
        /// i.e. full class name and method name.
        /// </summary>
        public static string GetTestMethodFullName(TestMethodEntity method)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(method.OwningClass.ClassFullName);
            sb.Append('.');
            sb.Append(method.MethodName);
            return(sb.ToString());
        }
Example #3
0
        public static string GetUnitTestCaseDisplayName(TestMethodEntity method, TestArgs args)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(method.MethodName);
            sb.Append('(');
            sb.Append(GetTestArgsDisplayText(method, args, true));
            sb.Append(')');

            return(sb.ToString());
        }
Example #4
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);
        }