public void ShouldReplaceAssemblyVersionInRelativePathWithVariables(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, (fileSystem, variables) => { using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, 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"")"))); } }); }
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: (fileSystem, variables) => { using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, false)) { assemblyInfoFileUpdater.Update(); fileSystem.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 ShouldAddAssemblyVersionIfMissingFromInfoFile(string fileExtension) { var workingDir = Path.GetTempPath(); var assemblyInfoFile = "AssemblyInfo." + fileExtension; var fileName = Path.Combine(workingDir, assemblyInfoFile); VerifyAssemblyInfoFile("", fileName, AssemblyVersioningScheme.MajorMinor, (fileSystem, variables) => { using (var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFile, workingDir, variables, fileSystem, 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"")"))); } }); }
public void ShouldCreateAssemblyInfoFilesAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension) { var workingDir = Path.GetTempPath(); var assemblyInfoFiles = new HashSet <string> { "AssemblyInfo." + fileExtension, Path.Combine("src", "Project", "Properties", "VersionAssemblyInfo." + fileExtension) }; var variables = variableProvider.GetVariablesFor(SemanticVersion.Parse("1.0.0", "v"), new TestEffectiveConfiguration(), false); using var assemblyInfoFileUpdater = new AssemblyInfoFileUpdater(assemblyInfoFiles, workingDir, variables, fileSystem, log, true); assemblyInfoFileUpdater.Update(); foreach (var item in assemblyInfoFiles) { var fullPath = Path.Combine(workingDir, item); fileSystem.ReadAllText(fullPath).ShouldMatchApproved(c => c.SubFolder(Path.Combine("Approved", fileExtension))); } }
public void ShouldCreateAssemblyInfoFileAtPathWhenNotExistsAndEnsureAssemblyInfo(string fileExtension) { var fileSystem = new TestFileSystem(); var workingDir = Path.GetTempPath(); var assemblyInfoFile = Path.Combine("src", "Project", "Properties", "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, true)) { assemblyInfoFileUpdater.Update(); fileSystem.ReadAllText(fullPath) .ShouldMatchApproved(c => c .NoDiff() .WithDescriminator(fileExtension)); } }
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()); } }); }
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()); } }
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(); } }
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"")"))); }); }
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(); } })); }