Exemple #1
0
        /// <summary>
        /// Build a remote package object from the parsed json
        /// </summary>
        /// <param name="name">name of package</param>
        /// <param name="viewObj">dictionary at root of object</param>
        /// <returns>NpmRemotePackage instance</returns>
        protected static NpmRemotePackage RemotePackageFromDictionary(string name, Dictionary<string, object> viewObj)
        {
            NpmRemotePackage remote = new NpmRemotePackage();
            remote.Name = name;
            if (viewObj.ContainsKey("dist-tags"))
            {
                Dictionary<string, object> dist = viewObj["dist-tags"] as Dictionary<string, object>;
                if (dist != null)
                {
                    if (dist.ContainsKey("stable"))
                    {
                        remote.Version = dist["stable"] as string;
                    }
                    else if (dist.ContainsKey("latest"))
                    {
                        remote.Version = dist["latest"] as string;
                    }
                }
            }

            if (viewObj.ContainsKey("description"))
            {
                remote.Description = viewObj["description"] as string;
            }

            if (viewObj.ContainsKey("homepage"))
            {
                remote.Homepage = viewObj["homepage"] as string;
            }

            if (viewObj.ContainsKey("author"))
            {
                remote.Author = viewObj["author"] as string;
            }

            if (viewObj.ContainsKey("versions"))
            {
                remote.Versions = ConvertStringArray(viewObj["versions"]);
            }

            if (viewObj.ContainsKey("maintainers"))
            {
                remote.Maintainers = ConvertStringArray(viewObj["maintainers"]);
            }

            if (viewObj.ContainsKey("contributors"))
            {
                remote.Contributors = ConvertStringArray(viewObj["contributors"]);
            }

            if (viewObj.ContainsKey("keywords"))
            {
                remote.Keywords = ConvertStringArray(viewObj["keywords"]);
            }

            if (viewObj.ContainsKey("dependencies"))
            {
                remote.Dependencies = ConvertDependencies(viewObj["dependencies"]);
            }

            if (viewObj.ContainsKey("devDependencies"))
            {
                remote.DevDependencies = ConvertDependencies(viewObj["devDependencies"]);
            }

            if (viewObj.ContainsKey("optionalDependencies"))
            {
                remote.OptionalDependencies = ConvertDependencies(viewObj["optionalDependencies"]);
            }

            if (viewObj.ContainsKey("licenses"))
            {
                remote.License = ConvertReference(viewObj["licenses"]);
            }

            if (viewObj.ContainsKey("repositories"))
            {
                remote.Repository = ConvertReference(viewObj["repositories"]);
            }

            return remote;
        }
Exemple #2
0
 /// <summary>
 /// Expected output from view
 /// </summary>
 /// <returns>Expected result for view test</returns>
 public static NpmRemotePackage View1Expected()
 {
     NpmRemotePackage expected = new NpmRemotePackage();
     expected.Name = "dateformat";
     expected.Version = "1.0.2-1.2.3";
     expected.Description = "A node.js package for Steven Levithan's excellent dateFormat()function.";
     List<string> versions = new List<string>();
     versions.Add("0.9.0-1.2.3");
     versions.Add("1.0.0-1.2.3");
     versions.Add("1.0.1-1.2.3");
     versions.Add("1.0.2-1.2.3");
     expected.Versions = versions;
     List<string> maintainers = new List<string>();
     maintainers.Add("felixge <*****@*****.**>");
     expected.Maintainers = maintainers;
     expected.Contributors = null;
     expected.Homepage = "https://github.com/felixge/node-dateformat";
     expected.Author = "Steven Levithan";
     expected.Dependencies = new List<NpmPackageDependency>();
     expected.DevDependencies = new List<NpmPackageDependency>();
     expected.OptionalDependencies = null;
     expected.License = null;
     expected.Repository = null;
     return expected;
 }