Example #1
0
        /// <summary>
        /// Updates the versions of the projects.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="changeVersion"></param>
        /// <returns></returns>
        protected async Task <int> UpdateAsync(CommandContext context, Func <SemVersion, SemVersion> changeVersion)
        {
            context.WriteDebug("Updating versions...");
            var finder       = new ProjectFinder(context.Directory);
            var projectFiles = finder.FindProjects();

            foreach (var projectFile in projectFiles)
            {
                var project = _store.Read(projectFile);
                context.NewVesion = UpdateProject(project, changeVersion);
                _store.Save(project);
            }

            if (!string.IsNullOrEmpty(context.Message))
            {
                if (!await CommitAsync(context))
                {
                    context.WriteWarning("Failed to commit.");
                    return(projectFiles.Count);
                }
                context.WriteInfo($"Commit \"{context.Message}\" is created.");
            }

            if (context.Tag)
            {
                if (!await AddTagAsync(context))
                {
                    context.WriteWarning("Failed to add tag.");
                    return(projectFiles.Count);
                }
                context.WriteInfo($"Tag v{context.NewVesion} is added");
            }
            return(projectFiles.Count);
        }
        public void UpdateProjectTest()
        {
            string projectFile = "MyProject.csproj";

            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile(projectFile, ProjectHelper.SetVersion("1.4.0"));
                var store   = new ProjectStore();
                var project = store.Read(CreateFileInfo(fs, projectFile));
                project.Version = "2.0";

                store.Save(project);
                var newProject = store.Read(CreateFileInfo(fs, projectFile));

                Assert.Equal("2.0", project.Version);
            }
        }
Example #3
0
        public void Execute(CommandContext context)
        {
            var reader       = new ProjectStore();
            var finder       = new ProjectFinder(context.Directory);
            var projectFiles = finder.FindProjects();

            foreach (var projectFile in projectFiles)
            {
                var project = reader.Read(projectFile);
                context.WriteInfo($"\t{project.Name} -> {project.Version}");
            }
        }
Example #4
0
        public async Task ChangeVersionsTest()
        {
            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile("MySolution.sln")
                .CreateFolder("src/Services/project1")
                .CreateFile("src/Services/project1/project1.csproj", ProjectHelper.SetVersion("1.5.1"))
                .CreateFolder("src/Services/project2")
                .CreateFile("src/Services/project2/project2.csproj", ProjectHelper.SetVersion("2.1.0"));
                var store   = new ProjectStore();
                var command = new SetCommand(GitHelper.CreateDefaultGitMock().Object);
                var context = new CommandContext(_console, Verbosity.Info);
                context.Directory = fs.RootPath;

                await command.ExecuteAsync(context, "4.0.12");

                var project1 = store.Read(PathHelper.GetFile(fs, "src/Services/project1/project1.csproj"));
                var project2 = store.Read(PathHelper.GetFile(fs, "src/Services/project2/project2.csproj"));

                Assert.Equal("4.0.12", project1.Version);
                Assert.Equal("4.0.12", project2.Version);
            }
        }
        public void UpdateProjectWithBadVersionTest()
        {
            string projectFile = "MyProject.csproj";

            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile(projectFile, ProjectHelper.SetVersion("1.4.0"));
                var store   = new ProjectStore();
                var project = store.Read(CreateFileInfo(fs, projectFile));
                project.Version = "${BuildVersion}";

                Assert.Throws <ArgumentException>("version", () => store.Save(project));
            }
        }
        public void ReadProjectWithPatchTest()
        {
            string projectFile = "MyProject.csproj";

            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile(projectFile, ProjectHelper.SetVersion("1.3.5"));
                var store = new ProjectStore();

                var project = store.Read(CreateFileInfo(fs, projectFile));

                Assert.Equal("1.3.5", project.Version);
            }
        }
        public void ReadNoVersionTest()
        {
            string projectFile = "project2.csproj";

            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile(projectFile, ProjectHelper.SetVersion(string.Empty));
                var store = new ProjectStore();

                var project = store.Read(CreateFileInfo(fs, projectFile));

                Assert.Equal("0.1.0", project.Version);
            }
        }
Example #8
0
        public async Task ChangePreWithComplexPreTest()
        {
            using (var fs = new DisposableFileSystem())
            {
                fs.CreateFile("MySolution.sln");
                fs.CreateFolder("src/Services");
                fs.CreateFile("src/Services/project1.csproj", ProjectHelper.SetVersion("1.15.0-beta.119"));
                var store   = new ProjectStore();
                var command = new PreCommand(GitHelper.CreateDefaultGitMock().Object);
                var context = new CommandContext(_console, Verbosity.Info);
                context.Directory = fs.RootPath;

                await command.ExecuteAsync(context);

                var project = store.Read(PathHelper.GetFile(fs, "src/Services/project1.csproj"));

                Assert.Equal("1.15.0-beta.120", project.Version);
            }
        }