Exemple #1
0
        private string UpdateFilenameWithPostId(string documentFilename, int documentId)
        {
            string newFilename    = null;
            var    filenameHelper = new FilenameHelper();

            if (filenameHelper.HasId(documentFilename))
            {
                // We have an ID so let's see what it is
                var id = int.Parse(filenameHelper.GetId(documentFilename));

                if (id != documentId)
                {
                    // ID has been set but does not match the current ID in the filename so let's change it
                    newFilename = filenameHelper.SetId(documentFilename, documentId.ToString());
                }
            }
            else
            {
                // The filename does not currently contain an ID so let's set it
                newFilename = filenameHelper.SetId(documentFilename, documentId.ToString());
            }

            // Now let's rename the file in version control
            if (newFilename == null)
            {
                return(documentFilename);
            }

            vstsHelper.RenameFile(vstsAuthentication, project, repoName, branch, documentFilename, newFilename, "Renaming file to include Post ID. ***NO_CI***");

            return(newFilename);
        }
Exemple #2
0
        public void RenameFileTest()
        {
            var originalFilename = Guid.NewGuid() + ".txt";
            var newFilename      = Guid.NewGuid() + ".md";
            var expectedContents = "Hello, World!";

            // Create file
            _vstsHelper.SaveTextFile(_authentication, _projectName, _repoName, _branchName, originalFilename, expectedContents,
                                     "Creating integration test file. ***NO_CI***", true);

            // Rename file
            _vstsHelper.RenameFile(_authentication, _projectName, _repoName, _branchName, originalFilename, newFilename,
                                   "Renaming integration test file. ***NO_CI***");

            // Pull file contents of renamed file (assuming it was renamed)
            var actualContents = _vstsHelper.GetFileContents(_authentication, _projectName, _repoName, _branchName, newFilename);

            // Compare contents
            Assert.AreEqual(expectedContents, actualContents);

            // Delete test file
            _vstsHelper.DeleteFile(_authentication, _projectName, _repoName, _branchName, newFilename, "Deleting integration test file. ***NO_CI***");
        }