public void ResolveProjectRelativePath_Should_Resolve_Paths_Above_The_Project_Root()
        {
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());

            var result = helper.ResolveProjectRelativePath("|dev|projects|test-project.csproj".Path(), "..|externals|external-file.txt".Path());
            Assert.AreEqual("|dev|externals|external-file.txt".Path(), result);
        }
Ejemplo n.º 2
0
        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.");
        }
        public void ResolveProjectRelativePath_Should_Resolve_Paths_Beneath_The_Project_Root_Using_Dot_Notation()
        {
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());
            var result = helper.ResolveProjectRelativePath("|dev|projects|test-project.csproj".Path(), ".|subdir-1|text-file.txt".Path());

            Assert.AreEqual("|dev|projects|subdir-1|text-file.txt".Path(), result);
        }
Ejemplo n.º 4
0
        public void SetVersion(string projectPath, string defaultVersion, string additionalInfo)
        {
            // Validate project path:
            var helper = new ProjectPathHelper(this.fileSystem);
            projectPath = helper.ConsolidateProjectFilePath(projectPath);
            if (!helper.ValidateProjectFilePath(projectPath))
            {
                throw new ArgumentException("The project file is not a valid solution or project file path.", "projectPath");
            }

            // Validate default version:
            Version parsedDefaultVersion;
            if (!Version.TryParse(defaultVersion, out parsedDefaultVersion))
            {
                throw new ArgumentException("The default version has an invalid format.", "defaultVersion");
            }

            // Consolidate additional info:
            if (string.IsNullOrWhiteSpace(additionalInfo))
            {
                additionalInfo = null;
            }

            // Execute:
            if (projectPath.ToLowerInvariant().EndsWith(".sln"))
            {
                SetVersionForSolution(projectPath, parsedDefaultVersion, additionalInfo);
            }
            else
            {
                SetVersionForProject(projectPath, parsedDefaultVersion, additionalInfo);
            }
        }
        public void GetVersionFileName_Should_Return_Correct_Result()
        {
            // Arrange:
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());

            // Act:
            var result = helper.GetVersionFileName("|Dev|SomeProject|ProjectFile.csproj".Path());

            // Assert:
            Assert.AreEqual("|Dev|SomeProject|version.txt".Path(), result);
        }
Ejemplo n.º 6
0
        private void SetVersionForSolution(string projectPath, Version defaultVersion, string additionalInfo)
        {
            var helper = new ProjectPathHelper(this.fileSystem);
            var solutionParser = new SolutionParser(this.fileSystem);

            List<string> projectPaths = solutionParser
                .GetProjectPaths(projectPath)
                .Select(x => helper.ResolveProjectRelativePath(projectPath, x))
                .ToList();

            foreach (string path in projectPaths)
            {
                SetVersionForProject(path, defaultVersion, additionalInfo);
            }
        }
        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);
        }
        public void ValidateProjectFilePath_Should_Return_False_In_Case_Of_Invalid_Paths()
        {
            // Arrange:
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());

            // Act:
            var result = helper.ValidateProjectFilePath(@"ABC!§$%&()");

            // Assert:
            Assert.IsFalse(result);
        }
Ejemplo n.º 10
0
        public void ConsolidateProjectFilePath_Should_Convert_Relative_Paths_To_Absolute_Paths()
        {
            // Arrange:
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());

            // Act:
            string result = helper.ConsolidateProjectFilePath("dev|test.sln".Path());

            // Assert:
            Assert.AreEqual(Path.Combine(Environment.CurrentDirectory, "dev|test.sln".Path()), result);
        }
Ejemplo n.º 11
0
        public void ConsolidateProjectFilePath_Should_Not_Alter_Absolute_Paths()
        {
            // Arrange:
            var helper = new ProjectPathHelper(Mock.Of<IFileSystem>());

            // Act:
            string result = helper.ConsolidateProjectFilePath("|dev|test.sln".Path());

            // Assert:
            Assert.AreEqual("|dev|test.sln".Path(), result);
        }