public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension) { var fileSystem = new TestFileSystem(); var workingDir = Path.GetTempPath(); var assemblyInfoFiles = new HashSet <string> { "AssemblyInfo." + fileExtension, Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension) }; var version = SemanticVersion.Parse("1.0.0", "v"); var variables = version.ToVersionVariables(new TestEffectiveConfiguration()); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFiles, workingDir, variables, fileSystem, true)) { assemblyInfoFileUpdater.Update(); foreach (var item in assemblyInfoFiles) { var fullPath = Path.Combine(workingDir, item); fileSystem.ReadAllText(fullPath) .ShouldMatchApproved(c => c .NoDiff() .WithDescriminator(fileExtension)); } } }
public static void UpdateAssemblyInfo(this ICakeContext context, VersionVariables variables, DirectoryPath workingDirectory, string assemblyInfoFile = "SolutionInfo.cs") { #region Arguments check (DupFinder Exclusion) if (context == null) { throw new ArgumentNullException(nameof(context)); } if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (workingDirectory == null) { throw new ArgumentNullException(nameof(workingDirectory)); } if (assemblyInfoFile == null) { throw new ArgumentNullException(nameof(assemblyInfoFile)); } #endregion var fileSystem = new VCSVersion.Helpers.FileSystem(); using (context.AddLoggers()) using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDirectory.FullPath, variables, fileSystem, true)) { assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); } }
public void ShouldCreateAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension); var fullPath = Path.Combine(workingDir, assemblyInfoFile); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fileSystem); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFile)); fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }
public static void UpdateAssemblyInfo(this ICakeContext context, VersionVariables variables, DirectoryPath workingDirectory) { var assemblyInfoFile = "SolutionInfo.cs"; var fileSystem = new VCSVersion.Helpers.FileSystem(); using (context.AddLoggers()) using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDirectory.FullPath, variables, fileSystem, true)) { assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); } }
public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo(string fileExtension) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; var fullPath = Path.Combine(workingDir, assemblyInfoFile); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fileSystem); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); fileSystem.Exists(fullPath).ShouldBeFalse(); }
public void ShouldStartSearchFromWorkingDirectory() { fileSystem = Substitute.For <IFileSystem>(); var workingDir = Path.GetTempPath(); var assemblyInfoFiles = Array.Empty <string>(); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fileSystem); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFiles.ToArray())); fileSystem.Received().DirectoryEnumerateFiles(Arg.Is(workingDir), Arg.Any <string>(), Arg.Any <SearchOption>()); }
public void ShouldStartSearchFromWorkingDirectory() { fileSystem = Substitute.For <IFileSystem>(); var workingDir = Path.GetTempPath(); var assemblyInfoFiles = new HashSet <string>(); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFiles, workingDir, variables, fileSystem, log, false); assemblyInfoFileUpdater.Update(); fileSystem.Received().DirectoryGetFiles(Arg.Is(workingDir), Arg.Any <string>(), Arg.Any <SearchOption>()); }
public void ShouldCreateAssemblyInfoFileWhenNotExistsAndEnsureAssemblyInfo(string fileExtension) { var fileSystem = new TestFileSystem(); var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; var fullPath = Path.Combine(workingDir, assemblyInfoFile); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, log, true); assemblyInfoFileUpdater.Update(); fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }
public void UpdateAssemblyInfo(UpdateAssemblyInfo task) { FileHelper.DeleteTempFiles(); FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile); var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo"); task.AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, fileSystem, log, true); assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); }
public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssemblyInfo() { fileSystem = Substitute.For <IFileSystem>(); var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo.js"; var fullPath = Path.Combine(workingDir, assemblyInfoFile); var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fileSystem); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, true, assemblyInfoFile)); fileSystem.Received(0).WriteAllText(fullPath, Arg.Any <string>()); }
public void ShouldNotReplaceAssemblyVersionWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fileSystem, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, log, false); assemblyInfoFileUpdater.Update(); assemblyFileContent = fileSystem.ReadAllText(fileName); assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }); }
public void Issue1183ShouldAddFSharpAssemblyInformationalVersionBesideOtherAttributes(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, verify: (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); assemblyFileContent = fs.ReadAllText(fileName); assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }); }
public void ShouldAddAssemblyInformationalVersionWhenUpdatingAssemblyVersionFile(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, verify: (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fs, log, false); assemblyInfoFileUpdater.Update(); assemblyFileContent = fs.ReadAllText(fileName); assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }); }
public void ShouldNotAddAssemblyInformationalVersionWhenVersionSchemeIsNone(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.None, verify: (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); assemblyFileContent = fs.ReadAllText(fileName); assemblyFileContent.ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); }); }
public void ShouldNotCreateAssemblyInfoFileWhenNotExistsAndNotEnsureAssemblyInfo(string fileExtension) { var fileSystem = new TestFileSystem(); var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo." + fileExtension; var fullPath = Path.Combine(workingDir, assemblyInfoFile); var version = SemanticVersion.Parse("1.0.0", "v"); var variables = version.ToVersionVariables(new TestEffectiveConfiguration()); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, false)) { assemblyInfoFileUpdater.Update(); fileSystem.Exists(fullPath).ShouldBeFalse(); } }
public void ShouldAddAssemblyVersionIfMissingFromInfoFile(string fileExtension) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile("", fileName, AssemblyVersioningScheme.MajorMinor, (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); fs.Received().WriteAllText(fileName, Arg.Is <string>(s => s.Contains(@"AssemblyVersion(""2.3.0.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
public void ShouldReplaceAssemblyVersionWhenCreatingAssemblyVersionFileAndEnsureAssemblyInfo(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, verify: (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); fs.Received().WriteAllText(fileName, Arg.Is <string>(s => s.Contains(@"AssemblyVersion(""2.3.1.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
public void ShouldReplaceAssemblyVersionInRelativePathWithVariablesAndWhiteSpace(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = Path.Combine("Project", "src", "Properties", "AssemblyInfo." + fileExtension); var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.MajorMinor, (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); fs.Received().WriteAllText(fileName, Arg.Is <string>(s => s.Contains(@"AssemblyVersion(""2.3.0.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
public void ShouldReplaceAlreadySubstitutedValues(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = PathHelper.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.MajorMinor, (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(this.log, fs); assemblyInfoFileUpdater.Execute(variables, new AssemblyInfoContext(workingDir, false, assemblyInfoFile)); fs.Received().WriteAllText(fileName, Arg.Is <string>(s => s.Contains(@"AssemblyVersion(""2.3.0.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
public void ShouldReplaceAssemblyVersionWithStar(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, AssemblyVersioningScheme.MajorMinor, (fileSystem, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, log, false); assemblyInfoFileUpdater.Update(); fileSystem.Received().WriteAllText(fileName, Arg.Is <string>(s => s.Contains(@"AssemblyVersion(""2.3.0.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
private static void VerifyAssemblyInfoFile( string assemblyFileContent, string assemblyInfoFile, AssemblyVersioningScheme versioningScheme = AssemblyVersioningScheme.MajorMinorPatch, Action <string> verify = null) { var workingDir = Path.GetTempPath(); var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, versioningScheme, (mock, variables) => { using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, mock.Object, false)) { assemblyInfoFileUpdater.Update(); verify?.Invoke(mock.Object.ReadAllText(fileName)); } }); }
public void ShouldStartSearchFromWorkingDirectory() { var workingDir = Path.GetTempPath(); var assemblyInfoFiles = new HashSet <string>(); var fileSystemMock = new Mock <IFileSystem>(); var fileSystem = fileSystemMock.Object; var version = SemanticVersion.Parse("1.0.0", "v"); var variables = version.ToVersionVariables(new TestEffectiveConfiguration()); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFiles, workingDir, variables, fileSystem, false)) { assemblyInfoFileUpdater.Update(); fileSystemMock.Verify(f => f.DirectoryGetFiles(workingDir, It.IsAny <string>(), It.IsAny <SearchOption>()), Times.Once()); } }
public void ShouldNotCreateAssemblyInfoFileForUnknownSourceCodeAndEnsureAssemblyInfo() { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "VersionAssemblyInfo.js"; var fullPath = Path.Combine(workingDir, assemblyInfoFile); var fileSystemMock = new Mock <IFileSystem>(); var fileSystem = fileSystemMock.Object; var version = SemanticVersion.Parse("1.0.0", "v"); var variables = version.ToVersionVariables(new TestEffectiveConfiguration()); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, true)) { assemblyInfoFileUpdater.Update(); fileSystemMock.Verify(f => f.WriteAllText(fullPath, It.IsAny <string>()), Times.Never()); } }
public void ShouldReplaceAssemblyVersionWithAtttributeSuffix(string fileExtension, string assemblyFileContent) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, verify: (fs, variables) => { using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fs, log, false); assemblyInfoFileUpdater.Update(); fs.Received().WriteAllText(fileName, Arg.Is <string>(s => !s.Contains(@"AssemblyVersionAttribute(""1.0.0.0"")") && !s.Contains(@"AssemblyInformationalVersionAttribute(""1.0.0.0"")") && !s.Contains(@"AssemblyFileVersionAttribute(""1.0.0.0"")") && s.Contains(@"AssemblyVersion(""2.3.1.0"")") && s.Contains(@"AssemblyInformationalVersion(""2.3.1+3.Branch.foo.Sha.hash"")") && s.Contains(@"AssemblyFileVersion(""2.3.1.0"")"))); }); }
void CreateTempAssemblyInfo(VersionVariables versionVariables) { var fileExtension = GetFileExtension(); var assemblyInfoFileName = $"GitVersionTaskAssemblyInfo.g.{fileExtension}"; if (IntermediateOutputPath == null) { assemblyInfoFileName = $"AssemblyInfo_{Path.GetFileNameWithoutExtension(ProjectFile)}_{Path.GetRandomFileName()}.g.{fileExtension}"; } var workingDirectory = IntermediateOutputPath ?? TempFileTracker.TempPath; AssemblyInfoTempFilePath = Path.Combine(workingDirectory, assemblyInfoFileName); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFileName, workingDirectory, versionVariables, new FileSystem(), true)) { assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); } }
private static void VerifyAssemblyInfoFile( string assemblyFileContent, string assemblyInfoFile, AssemblyVersioningScheme versioningScheme = AssemblyVersioningScheme.MajorMinorPatch, Expression <Func <string, bool> > match = null) { var workingDir = Path.GetTempPath(); var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile(assemblyFileContent, fileName, versioningScheme, (mock, variables) => { using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, mock.Object, false)) { assemblyInfoFileUpdater.Update(); mock.Verify(f => f.WriteAllText(fileName, It.Is(match)), Times.Once()); } }); }
private static Output CreateTempAssemblyInfo(Input input, VersionVariables versionVariables) { var fileWriteInfo = input.IntermediateOutputPath.GetFileWriteInfo( input.Language, input.ProjectFile, (pf, ext) => $"GitVersionTaskAssemblyInfo.g.{ext}", (pf, ext) => $"AssemblyInfo_{Path.GetFileNameWithoutExtension(pf)}_{Path.GetRandomFileName()}.g.{ext}" ); var output = new Output() { AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName) }; using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true)) { assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); } return(output); }
public static bool UpdateAssemblyInfo(UpdateAssemblyInfo task) { return(ExecuteGitVersionTask(task, t => { FileHelper.DeleteTempFiles(); FileHelper.CheckForInvalidFiles(t.CompileFiles, t.ProjectFile); if (!GetVersionVariables(t, out var versionVariables)) { return; } var fileWriteInfo = t.IntermediateOutputPath.GetFileWriteInfo(t.Language, t.ProjectFile, "AssemblyInfo"); t.AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName); using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(fileWriteInfo.FileName, fileWriteInfo.WorkingDirectory, versionVariables, new FileSystem(), true)) { assemblyInfoFileUpdater.Update(); assemblyInfoFileUpdater.CommitChanges(); } })); }