public void VersionCli_can_bump_versions() { // Configure A.CallTo(() => _vcsTool.IsRepositoryClean()).Returns(true); A.CallTo(() => _vcsTool.IsVcsToolPresent()).Returns(true); A.CallTo(() => _vcsTool.Commit(A <string> ._, A <string> ._)).DoesNothing(); A.CallTo(() => _vcsTool.Tag(A <string> ._)).DoesNothing(); A.CallTo(() => _fileDetector.FindAndLoadCsProj(A <string> ._)).Returns("<Project/>"); const string csProjFilePath = "/unit-test/test.csproj"; A.CallTo(() => _fileDetector.ResolvedCsProjFile).Returns(csProjFilePath); A.CallTo(() => _fileParser.Load(A <string> ._)).DoesNothing(); A.CallTo(() => _fileParser.Version).Returns("1.2.1"); // Act _cli.Execute(new VersionCliArgs { VersionBump = VersionBump.Major, DoVcs = true, DryRun = false }); // Verify A.CallTo(() => _filePatcher.Patch( A <string> .That.Matches(str => str == "<Project/>"), A <string> .That.Matches(ver => ver == "1.2.1"), A <string> .That.Matches(newVer => newVer == "2.0.0") )) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _filePatcher.Flush( A <string> ._, A <string> .That.Matches(path => path == csProjFilePath))) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _vcsTool.Commit( A <string> .That.Matches(path => path == csProjFilePath), A <string> .That.Matches(ver => ver == "v2.0.0"))) .MustHaveHappened(Repeated.Exactly.Once); A.CallTo(() => _vcsTool.Tag( A <string> .That.Matches(tag => tag == "v2.0.0"))) .MustHaveHappened(Repeated.Exactly.Once); }
public VersionInfo Execute(VersionCliArgs args) { if (!args.DryRun && args.DoVcs && !_vcsTool.IsVcsToolPresent()) { throw new OperationCanceledException( $"Unable to find the vcs tool {_vcsTool.ToolName()} in your path"); } if (!args.DryRun && args.DoVcs && !_vcsTool.IsRepositoryClean()) { throw new OperationCanceledException( "You currently have uncomitted changes in your repository, please commit these and try again"); } var csProjXml = _fileDetector.FindAndLoadCsProj(args.CsProjFilePath); _fileParser.Load(csProjXml); var semVer = SemVer.FromString(_fileParser.Version); semVer.Bump(args.VersionBump, args.SpecificVersionToApply); var newVersion = semVer.ToVersionString(); if (!args.DryRun) // if we are not in dry run mode, then we should go ahead { var patchedCsProjXml = _fileVersionPatcher.Patch( csProjXml, _fileParser.Version, newVersion ); _fileVersionPatcher.Flush( patchedCsProjXml, _fileDetector.ResolvedCsProjFile ); if (args.DoVcs) { // Run git commands _vcsTool.Commit(_fileDetector.ResolvedCsProjFile, $"v{newVersion}"); _vcsTool.Tag($"v{newVersion}"); } } var theOutput = new VersionInfo { Product = new ProductOutputInfo { Name = ProductInfo.Name, Version = ProductInfo.Version }, OldVersion = _fileParser.Version, NewVersion = newVersion, ProjectFile = _fileDetector.ResolvedCsProjFile, VersionStrategy = args.VersionBump.ToString().ToLowerInvariant() }; if (args.OutputFormat == OutputFormat.Json) { WriteJsonToStdout(theOutput); } else { Console.WriteLine($"Bumped {_fileDetector.ResolvedCsProjFile} to version {newVersion}"); } return(theOutput); }