Ejemplo n.º 1
0
        public async Task UpdatePackageSourcesTests(string testName, string[] managedFeeds)
        {
            GitFileManager gitFileManager = new GitFileManager(null, NullLogger.Instance);

            string inputNugetPath = Path.Combine(
                Environment.CurrentDirectory,
                TestInputsRootDir,
                ConfigFilesInput,
                testName,
                InputNugetConfigFile);
            string inputXmlContent = await File.ReadAllTextAsync(inputNugetPath);

            var inputNuGetConfigFile = GitFileManager.ReadXmlFile(inputXmlContent);

            XmlDocument updatedConfigFile =
                gitFileManager.UpdatePackageSources(inputNuGetConfigFile, new HashSet <string>(managedFeeds));

            var outputNugetPath = Path.Combine(
                Environment.CurrentDirectory,
                TestInputsRootDir,
                ConfigFilesInput,
                testName,
                OutputNugetConfigFile);
            string expectedOutputText = await File.ReadAllTextAsync(outputNugetPath);

            // Dump the output xml using the git file manager
            GitFile file = new GitFile(null, updatedConfigFile);

            // Normalize the \r\n newlines in the expected output to \n if they
            // exist (GitFile normalizes these before writing)
            expectedOutputText = expectedOutputText.Replace(Environment.NewLine, "\n");

            Assert.Equal(expectedOutputText, file.Content);
        }
        public async Task UpdatePackageSourcesTests(string testName, string[] managedFeeds)
        {
            GitFileManager gitFileManager = new GitFileManager(null, NullLogger.Instance);

            string inputNugetPath = Path.Combine(
                Environment.CurrentDirectory,
                TestInputsRootDir,
                ConfigFilesInput,
                testName,
                InputNugetConfigFile);
            string inputXmlContent = await File.ReadAllTextAsync(inputNugetPath);

            var inputNuGetConfigFile = GitFileManager.ReadXmlFile(inputXmlContent);

            Dictionary <string, HashSet <string> > configFileUpdateData = new Dictionary <string, HashSet <string> >();

            configFileUpdateData.Add("testKey", new HashSet <string>(managedFeeds));
            var managedFeedsForTest = gitFileManager.FlattenLocationsAndSplitIntoGroups(configFileUpdateData);

            // 'unknown' = regex failed to match and extract repo name from feed
            managedFeedsForTest.Keys.Should().NotContain("unknown");

            XmlDocument updatedConfigFile =
                gitFileManager.UpdatePackageSources(inputNuGetConfigFile, managedFeedsForTest);

            var outputNugetPath = Path.Combine(
                Environment.CurrentDirectory,
                TestInputsRootDir,
                ConfigFilesInput,
                testName,
                OutputNugetConfigFile);
            string expectedOutputText = await File.ReadAllTextAsync(outputNugetPath);

            // Dump the output xml using the git file manager
            GitFile file = new GitFile(null, updatedConfigFile);

            // Normalize the \r\n newlines in the expected output to \n if they
            // exist (GitFile normalizes these before writing)
            expectedOutputText = expectedOutputText.Replace(Environment.NewLine, "\n");

            file.Content.Should().Be(expectedOutputText);

            // When this is performed via the Maestro service instead of the Darc CLI, it seemingly can
            // be run more than once for the same XmlDocument.  This should not impact the contents of the file;
            // Validate this expectation of idempotency by running the same update on the resultant file.
            XmlDocument doubleUpdatedConfigFile = gitFileManager.UpdatePackageSources(updatedConfigFile, managedFeedsForTest);
            GitFile     doubleUpdatedfile       = new GitFile(null, doubleUpdatedConfigFile);

            doubleUpdatedfile.Content.Should().Be(expectedOutputText, "Repeated invocation of UpdatePackageSources() caused incremental changes to nuget.config");
        }
        public void VerifyNoDuplicatedPropertiesTests(string inputFileName, bool hasDuplicatedProps)
        {
            GitFileManager gitFileManager = new GitFileManager(null, NullLogger.Instance);

            string inputVersionPropsPath = Path.Combine(
                Environment.CurrentDirectory,
                TestInputsRootDir,
                VersionPropsFilesInput,
                inputFileName);

            string propsFileContent = File.ReadAllText(inputVersionPropsPath);

            XmlDocument propsFile = GitFileManager.GetXmlDocument(propsFileContent);

            gitFileManager.VerifyNoDuplicatedProperties(propsFile).Result.Should().Be(!hasDuplicatedProps);
        }