Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/di3 #2200

Merged
merged 16 commits into from
Mar 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/GitVersionCore.Tests/AssemblyInfoFileUpdaterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using GitVersion.Extensions.VersionAssemblyInfoResources;
using GitVersion.Logging;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NSubstitute;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using GitVersion;
using GitVersion.Logging;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/BuildServers/CodeBuildTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using GitVersion;
using GitVersion.BuildServers;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/BuildServers/GitLabCiTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using GitVersion;
using GitVersion.BuildServers;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
Expand Down
2 changes: 1 addition & 1 deletion src/GitVersionCore.Tests/BuildServers/JenkinsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Reflection;
using GitVersion;
using GitVersion.BuildServers;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using NUnit.Framework;
Expand Down
1 change: 0 additions & 1 deletion src/GitVersionCore.Tests/CommitDateTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using GitVersion.Configuration;
using GitVersion.Extensions;
using GitVersion.VersionCalculation;
using GitVersion.VersionFilters;
using GitVersionCore.Tests.Helpers;
using NUnit.Framework;

Expand Down
1 change: 0 additions & 1 deletion src/GitVersionCore.Tests/DefaultConfigFileLocatorTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.IO;
using GitVersion;
using GitVersion.Configuration;
using GitVersion.Exceptions;
using GitVersionCore.Tests.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
Expand Down
3 changes: 2 additions & 1 deletion src/GitVersionCore.Tests/DynamicRepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ public void FindsVersionInDynamicRepo(string name, string url, string targetBran
});

var gitPreparer = sp.GetService<IGitPreparer>();
gitPreparer.Prepare();

var gitVersionCalculator = sp.GetService<IGitVersionCalculator>();

gitPreparer.Prepare();
var versionVariables = gitVersionCalculator.CalculateVersionVariables();

Assert.AreEqual(expectedFullSemVer, versionVariables.FullSemVer);
Expand Down
47 changes: 22 additions & 25 deletions src/GitVersionCore.Tests/GitRepoMetadataProviderTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using GitTools.Testing;
using GitVersion;
using GitVersion.Configuration;
using GitVersion.Extensions;
using GitVersion.Logging;
using GitVersionCore.Tests.Helpers;
Expand All @@ -16,21 +15,19 @@ namespace GitVersionCore.Tests
public class GitRepoMetadataProviderTests : TestBase
{
private readonly ILog log;
private readonly Config configuration;

public GitRepoMetadataProviderTests()
{
var sp = ConfigureServices();
log = sp.GetService<ILog>();
configuration = new Config();
}

[Test]
public void FindsCorrectMergeBaseForForwardMerge()
{
//*9dfb8b4 49 minutes ago(develop)
//*54f21b2 53 minutes ago
// |\
// |\
// | | *a219831 51 minutes ago(HEAD -> release-2.0.0)
// | |/
// | *4441531 54 minutes ago
Expand Down Expand Up @@ -61,16 +58,16 @@ public void FindsCorrectMergeBaseForForwardMerge()
// Make new commit on develop
fixture.Checkout("develop");

// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");

var develop = fixture.Repository.FindBranch("develop");
var release = fixture.Repository.FindBranch("release-2.0.0");
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(release, develop);
var gitRepoMetadataProvider = new GitRepoMetadataProvider(log, fixture.Repository);

var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(develop, release);
var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);

fixture.Repository.DumpGraph(Console.WriteLine);

Expand All @@ -83,7 +80,7 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
{
//*9dfb8b4 49 minutes ago(develop)
//*54f21b2 53 minutes ago
// |\
// |\
// | | *a219831 51 minutes ago(HEAD -> release-2.0.0)
// | |/
// | *4441531 54 minutes ago
Expand Down Expand Up @@ -113,19 +110,19 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()

// Make new commit on develop
fixture.Checkout("develop");
// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.MakeACommit("develop after merge");

// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");

var develop = fixture.Repository.FindBranch("develop");
var release = fixture.Repository.FindBranch("release-2.0.0");
var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(release, develop);
var gitRepoMetadataProvider = new GitRepoMetadataProvider(log, fixture.Repository);

var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(develop, release);
var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);

fixture.Repository.DumpGraph(Console.WriteLine);

Expand All @@ -137,13 +134,13 @@ public void FindsCorrectMergeBaseForForwardMergeMovesOn()
public void FindsCorrectMergeBaseForMultipleForwardMerges()
{
//*403b294 44 minutes ago(develop)
//|\
//|\
//| *306b243 45 minutes ago(HEAD -> release-2.0.0)
//| *4cf5969 47 minutes ago
//| *4814083 51 minutes ago
//* | cddd3cc 49 minutes ago
//* | 2b2b52a 53 minutes ago
//|\ \
//|\ \
//| |/
//| *8113776 54 minutes ago
//| *3c0235e 56 minutes ago
Expand Down Expand Up @@ -172,12 +169,12 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()

// Make new commit on develop
fixture.Checkout("develop");
// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");
fixture.Checkout("develop");
fixture.Repository.MakeACommit("develop after merge");

// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");

// Make some new commit on release
Expand All @@ -189,17 +186,17 @@ public void FindsCorrectMergeBaseForMultipleForwardMerges()
fixture.Checkout("develop");
fixture.MergeNoFF("release-2.0.0");

// Checkout to release (no new commits)
// Checkout to release (no new commits)
fixture.Checkout("release-2.0.0");

var develop = fixture.Repository.FindBranch("develop");
var release = fixture.Repository.FindBranch("release-2.0.0");

var releaseBranchMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(release, develop);
var gitRepoMetadataProvider = new GitRepoMetadataProvider(log, fixture.Repository);

var releaseBranchMergeBase = gitRepoMetadataProvider.FindMergeBase(release, develop);

var developMergeBase = new GitRepoMetadataProvider(fixture.Repository, log, configuration)
.FindMergeBase(develop, release);
var developMergeBase = gitRepoMetadataProvider.FindMergeBase(develop, release);

fixture.Repository.DumpGraph(Console.WriteLine);

Expand Down
46 changes: 26 additions & 20 deletions src/GitVersionCore.Tests/GitToolsTestingExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using GitVersion;
using GitVersion.Configuration;
using GitVersion.Extensions;
using GitVersion.Logging;
using GitVersion.OutputVariables;
using GitVersion.VersionCalculation;
using GitVersionCore.Tests.Helpers;
Expand All @@ -16,10 +15,6 @@ namespace GitVersionCore.Tests
{
public static class GitToolsTestingExtensions
{
private static readonly IServiceProvider sp;

static GitToolsTestingExtensions() => sp = ConfigureService();

public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string branch = null)
{
if (configuration == null)
Expand All @@ -28,35 +23,46 @@ public static VersionVariables GetVersion(this RepositoryFixtureBase fixture, Co
configuration.Reset();
}

var log = sp.GetService<ILog>();
repository ??= fixture.Repository;

var options = Options.Create(new Arguments
{
OverrideConfig = configuration,
TargetPath = repository.GetRepositoryDirectory(),
TargetBranch = branch,
CommitId = commitId,
OnlyTrackedBranches = onlyTrackedBranches
});

var sp = ConfigureServices(services =>
{
services.AddSingleton(options);
});

var variableProvider = sp.GetService<IVariableProvider>();
var nextVersionCalculator = sp.GetService<INextVersionCalculator>();
var contextOptions = sp.GetService<IOptions<GitVersionContext>>();

var context = contextOptions.Value;

repository ??= fixture.Repository;
var targetBranch = repository.GetTargetBranch(branch);
var gitVersionContext = new GitVersionContext(repository, log, targetBranch, configuration, onlyTrackedBranches, commitId);
try
{
var executeGitVersion = nextVersionCalculator.FindVersion(gitVersionContext);
var variables = variableProvider.GetVariablesFor(executeGitVersion, gitVersionContext.Configuration, gitVersionContext.IsCurrentCommitTagged);
var executeGitVersion = nextVersionCalculator.FindVersion();
var variables = variableProvider.GetVariablesFor(executeGitVersion, context.Configuration, context.IsCurrentCommitTagged);

return variables;
}
catch (Exception)
{
Console.WriteLine("Test failing, dumping repository graph");
gitVersionContext.Repository.DumpGraph();
repository.DumpGraph();
throw;
}
}

public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
{
fixture.AssertFullSemver(new Config(), fullSemver, repository, commitId, onlyTrackedBranches, targetBranch);
}

public static void AssertFullSemver(this RepositoryFixtureBase fixture, Config configuration, string fullSemver, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
public static void AssertFullSemver(this RepositoryFixtureBase fixture, string fullSemver, Config configuration = null, IRepository repository = null, string commitId = null, bool onlyTrackedBranches = true, string targetBranch = null)
{
configuration ??= new Config();
configuration.Reset();
Console.WriteLine("---------");

Expand Down Expand Up @@ -88,7 +94,7 @@ public static void InitializeRepo(this RemoteRepositoryFixture fixture)
};
var options = Options.Create(arguments);

var serviceProvider = ConfigureService(services =>
var serviceProvider = ConfigureServices(services =>
{
services.AddSingleton(options);
});
Expand All @@ -97,7 +103,7 @@ public static void InitializeRepo(this RemoteRepositoryFixture fixture)
gitPreparer?.PrepareInternal(true, null);
}

private static IServiceProvider ConfigureService(Action<IServiceCollection> servicesOverrides = null)
private static IServiceProvider ConfigureServices(Action<IServiceCollection> servicesOverrides = null)
{
var services = new ServiceCollection()
.AddModule(new GitVersionCoreTestModule());
Expand Down
Loading