public void TestMultipleManifestPathLoading()
        {
            string assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string otherManifestFile = Path.GetTempFileName();

            Assert.IsTrue(File.Exists(manifestFile), "Manifest file that is required for the test was not found.");
            Assert.IsTrue(File.Exists(otherManifestFile), "Failed to create the temporary file that is required for the test.");

            string inputString = $"{manifestFile};{otherManifestFile}";

            List <string> parsedPaths = InputLoading.LoadManifestPaths(inputString, out int invalidPathCount);

            Assert.IsNotNull(parsedPaths);
            Assert.AreEqual(2, parsedPaths.Count, "Unexpected number of paths were extracted from the input string.");
            Assert.AreEqual(0, invalidPathCount, "No invalid path was expected.");
            Assert.IsTrue(File.Exists(parsedPaths[0]), $"Parsed path doesn't point to a valid file:{parsedPaths[0]}");
            Assert.IsTrue(File.Exists(parsedPaths[1]), $"Parsed path doesn't point to a valid file:{parsedPaths[1]}");

            FileInfo[] inputFiles = new []
            {
                new FileInfo(manifestFile),
                new FileInfo(otherManifestFile)
            };

            List <FileInfo> parsedFiles = parsedPaths.Select(p => new FileInfo(p)).ToList();

            // Path strings may be different, but they both should point to the same file.
            bool pathsPointToSameFiles = inputFiles.All(p => parsedFiles.Any(i => i.FullName == p.FullName));

            Assert.IsTrue(pathsPointToSameFiles, "Input files and the resulting files do not match.");
        }
Esempio n. 2
0
        public void TestLoadedIgnoredPackages()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults       results;
            string              assetsDirectory     = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string              manifestFile        = Path.Combine(assetsDirectory, "manifest.json");
            string              defaultConfigFile   = Path.Combine(assetsDirectory, "default.config");
            IEnumerable <Regex> whitelistedPackages = Enumerable.Empty <Regex>();

            ImmutableHashSet <string> ignoredPackages = InputLoading.LoadPackagesToIgnore(Path.Combine(assetsDirectory, "ignored.txt"));

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null,
                null);

            Assert.IsTrue(ignoredPackages.SetEquals(results.IgnoredNuGets), $"Mismatched ignore packages");
            Assert.IsFalse(results.UpdatedPackages.Any(n => ignoredPackages.Contains(n.PackageId)), "Packages that shouldn't have been updated were updated.");
        }
        public void TestEmptyManifestPathLoading(string inputString)
        {
            List <string> parsedPaths = InputLoading.LoadManifestPaths(inputString, out int invalidPathCount);

            Assert.IsNotNull(parsedPaths);
            Assert.AreEqual(0, parsedPaths.Count, "Unexpected number of paths were extracted from the input string.");
            Assert.AreEqual(0, invalidPathCount, "No invalid path was expected.");
        }
        public void TestWhitelistLoading()
        {
            string whitelistFilePath = Path.Combine(Directory.GetCurrentDirectory(), "Assets", "whitelist.txt");
            IEnumerable <Regex> whitelistedPackages = InputLoading.LoadWhitelistedPackages(whitelistFilePath);

            Assert.IsTrue(whitelistedPackages.Any(pattern => pattern.IsMatch("VS.Redist.Common.NetCore.Toolset.x64")));
            Assert.IsTrue(whitelistedPackages.Any(pattern => pattern.IsMatch("VS.Redist.Common.NetCore.AppHostPack.x86_x64.3.1")));
            Assert.IsFalse(whitelistedPackages.Any(pattern => pattern.IsMatch("some.package.that.doesnt.exist")));
        }
        public void TestIgnoreFileLoading()
        {
            string assetsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Assets");

            Assert.IsTrue(File.Exists(Path.Combine(assetsDirectory, "ignored.txt")), "Required test file \"ignored.txt\" is missing");

            ImmutableHashSet <string> ignoredPackages = InputLoading.LoadPackagesToIgnore(Path.Combine(assetsDirectory, "ignored.txt"));

            Assert.IsTrue(ignoredPackages.Contains("VS.ExternalAPIs.MSBuild"), "Ignored packages is missing an package.");
            Assert.IsFalse(ignoredPackages.Contains("Microsoft.NETCore.Runtime.CoreCLR"), "Ignored packages has a package it shouldn't have.");
        }
        public void TestManifestPathLoadingFolders()
        {
            string assetsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Assets");

            List <string> parsedPaths = InputLoading.LoadManifestPaths(assetsDirectory, out int invalidPathCount);

            Assert.IsNotNull(parsedPaths);
            Assert.AreEqual(1, parsedPaths.Count, "Unexpected number of paths were extracted from the input string.");
            Assert.AreEqual(0, invalidPathCount, "No invalid path was expected.");

            Assert.IsTrue(File.Exists(parsedPaths[0]), $"Parsed path doesn't point to a valid file:{parsedPaths[0]}");

            DirectoryInfo inputDirectory  = new DirectoryInfo(assetsDirectory);
            DirectoryInfo parsedDirectory = new FileInfo(parsedPaths[0]).Directory;

            Assert.AreEqual(inputDirectory.FullName, parsedDirectory.FullName, "Resulting path is not residing under the given folder.");
        }
        public void TestManifestPathLoading()
        {
            string assetsDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string manifestFile    = Path.Combine(assetsDirectory, "manifest.json");

            Assert.IsTrue(File.Exists(manifestFile), "Manifest file that is required for the test was not found.");

            List <string> parsedPaths = InputLoading.LoadManifestPaths(manifestFile, out int invalidPathCount);

            Assert.IsNotNull(parsedPaths);
            Assert.AreEqual(1, parsedPaths.Count, "Unexpected number of paths were extracted from the input string.");
            Assert.AreEqual(0, invalidPathCount, "No invalid path was expected.");
            Assert.IsTrue(File.Exists(parsedPaths[0]), $"Parsed path doesn't point to a valid file:{parsedPaths[0]}");

            // Path strings may be different, but they both should point to the same file.
            FileInfo inputFile  = new FileInfo(manifestFile);
            FileInfo parsedFile = new FileInfo(parsedPaths[0]);

            Assert.AreEqual(inputFile.FullName, parsedFile.FullName, "Parsed file is not the same file given as input.");
        }
        public void TestLoadedWhitelist()
        {
            IInsertionApiFactory apiFactory = new InsertionApiFactory();
            IInsertionApi        api        = apiFactory.Create(TimeSpan.FromSeconds(75), TimeSpan.FromSeconds(4));

            UpdateResults             results;
            string                    assetsDirectory   = Path.Combine(Directory.GetCurrentDirectory(), "Assets");
            string                    manifestFile      = Path.Combine(assetsDirectory, "manifest.json");
            string                    defaultConfigFile = Path.Combine(assetsDirectory, "default.config");
            ImmutableHashSet <string> ignoredPackages   = ImmutableHashSet <string> .Empty;

            IEnumerable <Regex> whitelistedPackages = InputLoading.LoadWhitelistedPackages(Path.Combine(assetsDirectory, "whitelist.txt"));

            results = api.UpdateVersions(
                manifestFile,
                defaultConfigFile,
                whitelistedPackages,
                ignoredPackages,
                null,
                null);

            Assert.IsFalse(results.UpdatedNuGets.Any(n => whitelistedPackages.All(pattern => !pattern.IsMatch(n.PackageId))), "Packages that shouldn't have been updated were updated.");
        }