Example #1
0
    public void StandardExecutionMode_LackOfAValidGitDirectoryDoesNotPreventExecution()
    {
        var task = new UpdateAssemblyInfo
        {
            BuildEngine       = new MockBuildEngine(),
            SolutionDirectory = Path.GetTempPath(),
        };

        task.InnerExecute();
    }
Example #2
0
    public void StandardExecutionMode_CanDetermineTheVersionFromALocalFeature()
    {
        var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/feature/one");
        var task     = new UpdateAssemblyInfo
        {
            BuildEngine       = new MockBuildEngine(),
            SolutionDirectory = repoPath,
        };

        task.InnerExecute();
    }
        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();
        }
Example #4
0
    public void StandardExecutionMode_CanAcceptAssemblyVersioningSchemes(string assemblyVersioningScheme)
    {
        var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/master");

        var task = new UpdateAssemblyInfo
        {
            BuildEngine              = new MockBuildEngine(),
            SolutionDirectory        = repoPath,
            AssemblyVersioningScheme = assemblyVersioningScheme
        };

        task.InnerExecute();
    }
    public void UpdateAssemblyInfoTaskShouldCreateFileInBuildServer()
    {
        var task = new UpdateAssemblyInfo();

        using var result = ExecuteMsBuildTaskInAzurePipeline(task);

        result.Success.ShouldBe(true);
        result.Errors.ShouldBe(0);
        result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();

        var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);

        fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
    }
Example #6
0
    public void StandardExecutionMode_DoesNotRequireARemoteToOperate()
    {
        using (var repo = new Repository(ASBMTestRepoWorkingDirPath))
        {
            Assert.AreEqual(0, repo.Network.Remotes.Count());
        }

        var task = new UpdateAssemblyInfo
        {
            BuildEngine       = new MockBuildEngine(),
            SolutionDirectory = ASBMTestRepoWorkingDirPath,
        };

        task.InnerExecute();
    }
Example #7
0
    public void StandardExecutionMode_ThrowsUponUnexpectedAssemblyVersioningSchemes()
    {
        var repoPath = CheckoutLocal(ASBMTestRepoWorkingDirPath, "refs/heads/master");

        var task = new UpdateAssemblyInfo
        {
            BuildEngine              = new MockBuildEngine(),
            SolutionDirectory        = repoPath,
            AssemblyVersioningScheme = "Boom"
        };

        var exception = Assert.Throws <WarningException>(() => task.InnerExecute());

        Assert.AreEqual("Unexpected assembly versioning scheme 'Boom'.", exception.Message);
    }
        public void UpdateAssemblyInfo(UpdateAssemblyInfo task)
        {
            FileHelper.DeleteTempFiles();
            if (task.CompileFiles != null)
            {
                FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile);
            }

            var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo");

            task.AssemblyInfoTempFilePath = Path.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);

            var arguments = options.Value;

            arguments.UpdateAssemblyInfo = true;
            arguments.EnsureAssemblyInfo = true;
            arguments.TargetPath         = fileWriteInfo.WorkingDirectory;
            arguments.AddAssemblyInfoFileName(fileWriteInfo.FileName);
            gitVersionTool.UpdateAssemblyInfo(versionVariables);
        }
        public void UpdateAssemblyInfoTaskShouldCreateFileWhenRunningInBuildServer()
        {
            using var fixture = CreateRemoteRepositoryFixture();

            var task = new UpdateAssemblyInfo
            {
                SolutionDirectory = fixture.LocalRepositoryFixture.RepositoryPath,
                ProjectFile       = fixture.LocalRepositoryFixture.RepositoryPath,
            };

            var result = ExecuteMsBuildTaskInBuildServer(task);

            result.Success.ShouldBe(true);
            result.Errors.ShouldBe(0);
            result.Task.AssemblyInfoTempFilePath.ShouldNotBeNull();

            var fileContent = File.ReadAllText(result.Task.AssemblyInfoTempFilePath);

            fileContent.ShouldContain(@"[assembly: AssemblyVersion(""1.0.1.0"")]");
        }
Example #10
0
    public void StandardExecutionMode_CannotDetermineTheVersionFromADetachedHead()
    {
        var repoPath = Clone(ASBMTestRepoWorkingDirPath);

        using (var repo = new Repository(repoPath))
        {
            repo.Checkout("469f851");
            Assert.IsTrue(repo.Info.IsHeadDetached);
        }

        var task = new UpdateAssemblyInfo
        {
            BuildEngine       = new MockBuildEngine(),
            SolutionDirectory = repoPath,
        };

        var exception = Assert.Throws <ErrorException>(task.InnerExecute);

        Assert.AreEqual("It looks like the branch being examined is a detached Head pointing to commit '469f851'. Without a proper branch name GitVersion cannot determine the build version.", exception.Message);
    }
    public void UpdateAssemblyInfo(UpdateAssemblyInfo task)
    {
        var versionVariables = VersionVariables.FromFile(task.VersionFile, fileSystem);

        FileHelper.DeleteTempFiles();
        FileHelper.CheckForInvalidFiles(task.CompileFiles, task.ProjectFile);

        var fileWriteInfo = task.IntermediateOutputPath.GetFileWriteInfo(task.Language, task.ProjectFile, "AssemblyInfo");

        task.AssemblyInfoTempFilePath = PathHelper.Combine(fileWriteInfo.WorkingDirectory, fileWriteInfo.FileName);

        var gitVersionOptions = this.options.Value;

        gitVersionOptions.AssemblyInfo.UpdateAssemblyInfo = true;
        gitVersionOptions.AssemblyInfo.EnsureAssemblyInfo = true;
        gitVersionOptions.WorkingDirectory = fileWriteInfo.WorkingDirectory;
        gitVersionOptions.AssemblyInfo.Files.Add(fileWriteInfo.FileName);

        gitVersionOutputTool.UpdateAssemblyInfo(versionVariables);
    }
Example #12
0
 public static bool UpdateAssemblyInfo(UpdateAssemblyInfo task) => ExecuteGitVersionTask(task, executor => executor.UpdateAssemblyInfo(task));