Beispiel #1
0
 /// <summary>
 /// Expected output from search
 /// </summary>
 /// <returns>Expected result for search test</returns>
 public static List<NpmSearchResultPackage> SearchResult2Expected()
 {
     List<NpmSearchResultPackage> expected = new List<NpmSearchResultPackage>();
     NpmSearchResultPackage res = new NpmSearchResultPackage(
         "azure",
         null,
         "Windows Azure Client Library for node",
         "andrerod",
         new DateTime(2012, 2, 16, 5, 16, 0),
         new string[] { "node", "azure" });
     NpmSearchResultPackage res2 = new NpmSearchResultPackage(
         "node-swt",
         null,
         "A library to validate and parse swt tokens",
         "dario.renzulli",
         new DateTime(2012, 1, 18, 1, 7, 0),
         new string[] { "swt", "acs", "security", "azure" });
     NpmSearchResultPackage res3 = new NpmSearchResultPackage(
         "node_in_windows_azure",
         null,
         "An NPM module for the Windows Azure t-shirts handed out at #NodeSummit 2012",
         "tomgallacher",
         new DateTime(2012, 1, 25, 15, 19, 0),
         new string[] { });
     NpmSearchResultPackage res4 = new NpmSearchResultPackage(
         "video",
         null,
         "A C++ module for node.js that creates Theora/Ogg videos from RGB frames.",
         "pkrumins",
         new DateTime(2012, 4, 1, 17, 9, 0),
         new string[] { "video", "videos", "theora", "rgb" });
     expected.Add(res);
     expected.Add(res2);
     expected.Add(res3);
     expected.Add(res4);
     return expected;
 }
Beispiel #2
0
        /// <summary>
        /// convert npm search output to INpmSearchResultPackage enumeration
        /// </summary>
        /// <param name="output">text output</param>
        /// <returns>enumerable INpmSearchResultPackage properties</returns>
        public IEnumerable<INpmSearchResultPackage> FromSearchResult(string output)
        {
            List<INpmSearchResultPackage> results = new List<INpmSearchResultPackage>();
            if (output == null)
            {
                return results;
            }

            string[] lines = output.Split('\n');
            int count = lines.Length;

            if (searchRegex == null)
            {
                searchRegex = new Regex(SearchPattern, RegexOptions.Compiled);
            }

            // skip first line - header
            for (int ix = 1; ix < count; ix++)
            {
                string desc = null;
                string name = null;
                string author = null;
                string date = null;
                string keywordlist = null;
                DateTime dateParsed = DateTime.Now;
                string[] keywords = null;

                Match m = searchRegex.Match(lines[ix]);
                if (m.Success && m.Groups.Count > 1)
                {
                    name = m.Groups[1].ToString();
                    if (m.Groups.Count > 2)
                    {
                        desc = m.Groups[2].ToString().Trim();
                    }

                    if (m.Groups.Count > 3)
                    {
                        author = m.Groups[3].ToString().Trim();
                    }

                    if (m.Groups.Count > 4)
                    {
                        date = m.Groups[4].ToString();
                        if (!DateTime.TryParse(date, out dateParsed))
                        {
                            dateParsed = DateTime.Now;
                        }
                    }

                    if (m.Groups.Count > 5)
                    {
                        keywordlist = m.Groups[5].ToString();
                        keywords = keywordlist.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    NpmSearchResultPackage result = new NpmSearchResultPackage(
                                                                            name,
                                                                            null,
                                                                            desc,
                                                                            author,
                                                                            dateParsed,
                                                                            keywords);
                    results.Add(result);
                }
            }

            return (IEnumerable<INpmSearchResultPackage>)results;
        }
Beispiel #3
0
 /// <summary>
 /// Expected output from search
 /// </summary>
 /// <returns>Expected result for search test</returns>
 public static List<NpmSearchResultPackage> SearchResult1Expected()
 {
     List<NpmSearchResultPackage> expected = new List<NpmSearchResultPackage>();
     NpmSearchResultPackage res = new NpmSearchResultPackage(
         "azure",
         null,
         "Windows Azure Client Library for node",
         "andrerod",
         new DateTime(2012, 2, 16, 5, 16, 0),
         new string[] { "node", "azure" });
     NpmSearchResultPackage res2 = new NpmSearchResultPackage(
         "node-swt",
         null,
         "A library to validate and parse swt tokens",
         "dario.renzulli",
         new DateTime(2012, 1, 18, 1, 7, 0),
         new string[] { "swt", "acs", "security", "azure" });
     NpmSearchResultPackage res3 = new NpmSearchResultPackage(
         "node_in_windows_azure",
         null,
         "An NPM module for the Windows Azure t-shirts handed out at #NodeSummit 2012",
         "tomgallacher",
         new DateTime(2012, 1, 25, 15, 19, 0),
         new string[] { });
     expected.Add(res);
     expected.Add(res2);
     expected.Add(res3);
     return expected;
 }