diff --git a/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt new file mode 100644 index 0000000000..effba7df8e --- /dev/null +++ b/src/GitVersionCore.Tests/VersionConverters/Approved/WixFileTests.UpdateWixVersionFileWhenFileAlreadyExists.approved.txt @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/GitVersionCore.Tests/VersionConverters/WixFileTests.cs b/src/GitVersionCore.Tests/VersionConverters/WixFileTests.cs index 82e4f394ac..551dd6ed63 100644 --- a/src/GitVersionCore.Tests/VersionConverters/WixFileTests.cs +++ b/src/GitVersionCore.Tests/VersionConverters/WixFileTests.cs @@ -67,5 +67,55 @@ public void UpdateWixVersionFile() .ReadAllText(file) .ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved"))); } + + [Test] + [Category(NoMono)] + [Description(NoMonoDescription)] + public void UpdateWixVersionFileWhenFileAlreadyExists() + { + var workingDir = Path.GetTempPath(); + var semVer = new SemanticVersion + { + Major = 1, + Minor = 2, + Patch = 3, + BuildMetaData = "5.Branch.develop" + }; + + semVer.BuildMetaData.VersionSourceSha = "versionSourceSha"; + semVer.BuildMetaData.Sha = "commitSha"; + semVer.BuildMetaData.ShortSha = "commitShortSha"; + semVer.BuildMetaData.CommitDate = DateTimeOffset.Parse("2019-02-20 23:59:59Z"); + + var config = new TestEffectiveConfiguration(buildMetaDataPadding: 2, legacySemVerPadding: 5); + + var stringBuilder = new StringBuilder(); + void Action(string s) => stringBuilder.AppendLine(s); + + var logAppender = new TestLogAppender(Action); + var log = new Log(logAppender); + + var sp = ConfigureServices(service => + { + service.AddSingleton(log); + }); + + var fileSystem = sp.GetService(); + var variableProvider = sp.GetService(); + var versionVariables = variableProvider.GetVariablesFor(semVer, config, false); + + using var wixVersionFileUpdater = sp.GetService(); + + // fake an already existing file + var file = Path.Combine(workingDir, WixVersionFileUpdater.WixVersionFileName); + fileSystem.WriteAllText(file, new string('x', 1024 * 1024)); + + wixVersionFileUpdater.Execute(versionVariables, new WixVersionContext(workingDir)); + + fileSystem + .ReadAllText(file) + .ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved"))); + } + } } diff --git a/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs b/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs index ca2808a7e9..238779f084 100644 --- a/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs +++ b/src/GitVersionCore/VersionConverters/WixUpdater/WixVersionFileUpdater.cs @@ -35,6 +35,7 @@ public void Execute(VersionVariables variables, WixVersionContext context) var root = doc.DocumentElement; doc.InsertBefore(xmlDecl, root); + fileSystem.Delete(wixVersionFile); using var fs = fileSystem.OpenWrite(wixVersionFile); doc.Save(fs); }