public TryRetrieveVersion ( string projectFile, System.Version &version ) : bool | ||
projectFile | string | |
version | System.Version | |
return | bool |
public void TryRetrieveVersion_Should_Return_False_If_File_Does_Not_Exist() { // Arrange: Version version; var repo = new MockRepository(MockBehavior.Strict); Mock<IFileSystem> fileSystem = repo.Create<IFileSystem>(); fileSystem.Setup(x => x.ReadAllText("|Dev|SomeProject|version.txt".Path())).Throws<FileNotFoundException>(); fileSystem.Setup(x => x.FileExists("|Dev|SomeProject|version.txt".Path())).Returns(false); var helper = new ProjectPathHelper(fileSystem.Object); // Act: bool success = helper.TryRetrieveVersion("|Dev|SomeProject|ProjectFile.csproj".Path(), out version); // Assert: Assert.IsFalse(success); }
public void TryRetrieveVersion_Should_Correctly_Parse_The_Provided_Version_File() { // Arrange: Version version; var repo = new MockRepository(MockBehavior.Strict); Mock<IFileSystem> fileSystem = repo.Create<IFileSystem>(); fileSystem.Setup(x => x.ReadAllText("|Dev|SomeProject|version.txt".Path())).Returns(string.Format("2.5.33{0}{0}", Environment.NewLine)); fileSystem.Setup(x => x.FileExists("|Dev|SomeProject|version.txt".Path())).Returns(true); var helper = new ProjectPathHelper(fileSystem.Object); // Act: bool success = helper.TryRetrieveVersion("|Dev|SomeProject|ProjectFile.csproj".Path(), out version); // Assert: Assert.IsTrue(success); Assert.AreEqual(new Version(2, 5, 33), version); }
private void SetVersionForProject(string projectPath, Version defaultVersion, string additionalInfo) { var helper = new ProjectPathHelper(this.fileSystem); this.output.WriteLine("Processing project '{0}'...", projectPath); this.output.WriteLine("-> Reading version..."); Version version; if (!helper.TryRetrieveVersion(projectPath, out version)) { version = defaultVersion; } this.output.WriteLine("-> Reading assembly info..."); string assemblyInfoFile = helper.GetAssemblyInfoFileName(projectPath); string assemblyInfo = this.fileSystem.FileExists(assemblyInfoFile) ? this.fileSystem.ReadAllText(assemblyInfoFile) : string.Empty; this.output.WriteLine("-> AddingReplacing version information..."); var modifier = new AssemblyInfoModifier(); assemblyInfo = modifier.ReplaceAssemblyAttribute(assemblyInfo, typeof(AssemblyVersionAttribute), version.ToString()); assemblyInfo = modifier.ReplaceAssemblyAttribute(assemblyInfo, typeof(AssemblyFileVersionAttribute), version.ToString()); if (additionalInfo != null) { this.output.WriteLine("-> Adding/Replacing additional information..."); assemblyInfo = modifier.ReplaceAssemblyAttribute(assemblyInfo, typeof(AssemblyInformationalVersionAttribute), additionalInfo); } this.output.WriteLine("-> Saving assembly info..."); this.fileSystem.WriteAllText(assemblyInfoFile, assemblyInfo); this.output.WriteLine("Processing project finished."); }