Exemplo n.º 1
0
        /// <param name="expected">        the expected value </param>
        /// <param name="typeAdapter">     the body type adaptor </param>
        /// <param name="formatter">       the formatter
        ///                        the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <param name="minLenForToggle"> the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <returns> the formatted content for a cell with a right expectation </returns>
        public static string makeContentForRightCell <T1>(string expected, RestDataTypeAdapter typeAdapter,
                                                          ICellFormatter <T1> formatter, int minLenForToggle)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(HtmlTools.toHtml(expected));
            string actual = typeAdapter.ToString();

            if (formatter.DisplayActual && !expected.Equals(actual))
            {
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("expected"));
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                if (minLenForToggle >= 0 && actual.Length > minLenForToggle)
                {
                    sb.Append(makeToggleCollapseable("toggle actual", HtmlTools.toHtml(actual)));
                }
                else
                {
                    sb.Append(HtmlTools.toHtml(actual));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("actual"));
            }
            return(sb.ToString());
        }
Exemplo n.º 2
0
        /// <summary>
        /// parses a map from a string.
        /// </summary>
        /// <param name="expStr">    the string with the serialised map. </param>
        /// <param name="nvSep">     the separator for keys and values. </param>
        /// <param name="entrySep">  the separator for entries in the map. </param>
        /// <param name="cleanTags"> if true the value is cleaned from any present html tag. </param>
        /// <returns> the parsed map. </returns>
        public static IDictionary <string, string> convertStringToMap(string expStr, string nvSep,
                                                                      string entrySep, bool cleanTags)
        {
            string sanitisedExpStr = expStr.Trim();

            sanitisedExpStr = removeOpenEscape(sanitisedExpStr);
            sanitisedExpStr = removeCloseEscape(sanitisedExpStr);
            sanitisedExpStr = sanitisedExpStr.Trim();
            string[] nvpArray = sanitisedExpStr.Split(new string[] { entrySep },
                                                      StringSplitOptions.None);

            IDictionary <string, string> ret = new Dictionary <string, string>();

            foreach (string nvp in nvpArray)
            {
                try
                {
                    string keyValueText = nvp.Trim();
                    if (string.IsNullOrEmpty(keyValueText))
                    {
                        continue;
                    }
                    keyValueText = removeOpenEscape(keyValueText).Trim();
                    keyValueText = removeCloseEscape(keyValueText).Trim();
                    string[] nvpArr = keyValueText.Split(new string[] { nvSep },
                                                         StringSplitOptions.None);
                    string k, v;
                    k = nvpArr[0].Trim();
                    v = "";
                    if (nvpArr.Length == 2)
                    {
                        v = nvpArr[1].Trim();
                    }
                    else if (nvpArr.Length > 2)
                    {
                        int pos = keyValueText.IndexOf(nvSep, StringComparison.Ordinal) + nvSep.Length;
                        v = keyValueText.Substring(pos).Trim();
                    }
                    if (cleanTags)
                    {
                        ret[k] = HtmlTools.fromSimpleTag(v);
                    }
                    else
                    {
                        ret[k] = v;
                    }
                }
                catch (Exception ex)
                {
                    string errorMessage =
                        string.Format("Each entry in the must be separated by '{0}' and "
                                      + "each entry must be expressed as a name{1}value",
                                      entrySep, nvSep);
                    throw new System.ArgumentException(errorMessage, ex);
                }
            }
            return(ret);
        }
Exemplo n.º 3
0
        /// <param name="expected">        the expected value </param>
        /// <param name="typeAdapter">     the body adapter for the cell </param>
        /// <param name="formatter">       the formatter </param>
        /// <param name="minLenForToggle"> the value determining whether the content should be rendered
        ///                        as a collapseable section. </param>
        /// <returns> the formatted content for a cell with a wrong expectation </returns>
        public static string makeContentForWrongCell <T1>(string expected, RestDataTypeAdapter typeAdapter,
                                                          ICellFormatter <T1> formatter, int minLenForToggle)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(HtmlTools.toHtml(expected));
            if (formatter.DisplayActual)
            {
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("expected"));
                string actual = typeAdapter.ToString();
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                if (minLenForToggle >= 0 && actual.Length > minLenForToggle)
                {
                    sb.Append(makeToggleCollapseable("toggle actual", HtmlTools.toHtml(actual)));
                }
                else
                {
                    sb.Append(HtmlTools.toHtml(actual));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("actual"));
            }
            IReadOnlyList <string> errors = typeAdapter.Errors;

            if (errors.Count > 0)
            {
                sb.Append(HtmlTools.toHtml("-----"));
                sb.Append(HtmlTools.toHtml("\n"));
                foreach (string e in errors)
                {
                    sb.Append(HtmlTools.toHtml(e + "\n"));
                }
                sb.Append(HtmlTools.toHtml("\n"));
                sb.Append(formatter.label("errors"));
            }
            return(sb.ToString());
        }