//[InlineData("5.0.0.0", "5.0.0", "http://localhost/packages/5.0.0.0.5.0.0.nupkg")] -- can't determine for 100% what the correct id and version is without reaching out to the main gallery db
        public void ExtractsPackageIdAndVersionFromRequestUrl(string expectedPackageId, string expectedPackageVersion, string requestUrl)
        {
            var packageDefinition = PackageDefinition.FromRequestUrl(requestUrl);

            Assert.Equal(expectedPackageId, packageDefinition.PackageId);
            Assert.Equal(expectedPackageVersion, packageDefinition.PackageVersion);
        }
Exemplo n.º 2
0
        public void TestParsingPerformanceOnFile()
        {
            var filePath            = $"C:\\Users\\skofman\\Desktop\\allpackages.csv";
            var ambiguousResultPath = "ambiguousresult.txt";
            var wrongResult         = "wrongresult.txt";

            List <string> ambiguousPackages = new List <string>();
            List <string> wrongPackages     = new List <string>();

            string[] lines = File.ReadAllLines(filePath);

            Stopwatch watch = Stopwatch.StartNew();

            foreach (var line in lines)
            {
                string[] components = line.Split(',');
                if (components.Length != 2)
                {
                    continue;
                }

                string id      = components[0];
                string version = NuGetVersion.Parse(components[1]).ToNormalizedString();

                string url    = $"http://localhost/packages/{id}.{version}.nupkg";
                var    result = PackageDefinition.FromRequestUrl(url);

                if (result.Count() > 1)
                {
                    ambiguousPackages.Add($"[{id}][{version}]");

                    if (!(result[0].PackageId == id && result[0].PackageVersion == version))
                    {
                        wrongPackages.Add($"[{id}][{version}]");
                    }
                }

                if (!result.Any())
                {
                    throw new ArgumentException($"[{id}][{version}]");
                }
            }

            watch.Stop();

            Console.WriteLine($"Pass took: {watch.Elapsed.TotalSeconds}");

            File.WriteAllLines(ambiguousResultPath, ambiguousPackages);
            File.WriteAllLines(wrongResult, wrongPackages);
        }
        public void ReturnsNullWhenInvalidPackageRequestUrl()
        {
            var packageDefinition = PackageDefinition.FromRequestUrl("http://localhost/api/v3/index.json");

            Assert.Null(packageDefinition);
        }