Skip to content

Commit

Permalink
GitTools#3334 - fix nullable warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
arturcic committed Jan 9, 2023
1 parent cdcbdcd commit 7316e03
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public void ConfigNextVersionTest(string nextVersion, string expectedVersion)
var branchMock = GitToolsTestingExtensions.CreateMockBranch("main", GitToolsTestingExtensions.CreateMockCommit());
var branchConfiguration = context.Configuration.GetBranchConfiguration(branchMock);
var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration);

strategy.ShouldNotBeNull();
return strategy.GetBaseVersions(new(branchMock, effectiveConfiguration)).SingleOrDefault();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public void ShouldNotAllowIncrementOfVersion()
var context = contextBuilder.ServicesProvider.GetRequiredService<Lazy<GitVersionContext>>().Value;
var branchConfiguration = context.Configuration.GetBranchConfiguration(mockBranch);
var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration);

strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(new(mockBranch, effectiveConfiguration)).Single();

baseVersion.ShouldIncrement.ShouldBe(false);
Expand Down Expand Up @@ -173,6 +175,8 @@ private static void AssertMergeMessage(string message, string? expectedVersion,
var context = contextBuilder.ServicesProvider.GetRequiredService<Lazy<GitVersionContext>>().Value;
var branchConfiguration = context.Configuration.GetBranchConfiguration(mockBranch);
var effectiveConfiguration = new EffectiveConfiguration(context.Configuration, branchConfiguration);

strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(new(mockBranch, effectiveConfiguration)).SingleOrDefault();

if (expectedVersion == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public void CanTakeVersionFromNameOfReleaseBranch(string branchName, string expe
var configuration = GitFlowConfigurationBuilder.New.Build();
var branchConfiguration = configuration.GetBranchConfiguration(branchName);
var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);

strategy.ShouldNotBeNull();
var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single();

baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
Expand All @@ -45,6 +47,8 @@ public void ShouldNotTakeVersionFromNameOfNonReleaseBranch(string branchName)
var configuration = GitFlowConfigurationBuilder.New.Build();
var branchConfiguration = configuration.GetBranchConfiguration(branchName);
var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);

strategy.ShouldNotBeNull();
var baseVersions = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration));

baseVersions.ShouldBeEmpty();
Expand All @@ -67,6 +71,9 @@ public void CanTakeVersionFromNameOfConfiguredReleaseBranch(string branchName, s
var configuration = GitFlowConfigurationBuilder.New.Build();
var branchConfiguration = configuration.GetBranchConfiguration(branchName);
var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);

strategy.ShouldNotBeNull();

var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single();

baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
Expand All @@ -90,12 +97,15 @@ public void CanTakeVersionFromNameOfRemoteReleaseBranch(string branchName, strin
var configuration = GitFlowConfigurationBuilder.New.Build();
var branchConfiguration = configuration.GetBranchConfiguration(branchName);
var effectiveConfiguration = new EffectiveConfiguration(configuration, branchConfiguration);

strategy.ShouldNotBeNull();

var baseVersion = strategy.GetBaseVersions(new(gitRepository.FindBranch(branchName)!, effectiveConfiguration)).Single();

baseVersion.SemanticVersion.ToString().ShouldBe(expectedBaseVersion);
}

private static IVersionStrategy GetVersionStrategy(string workingDirectory, IGitRepository repository, string branch, GitVersionConfiguration? configuration = null)
private static IVersionStrategy? GetVersionStrategy(string workingDirectory, IGitRepository repository, string branch, GitVersionConfiguration? configuration = null)
{
var sp = BuildServiceProvider(workingDirectory, repository, branch, configuration);
return sp.GetServiceForType<IVersionStrategy, VersionInBranchNameVersionStrategy>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public static IServiceCollection AddModule(this IServiceCollection serviceCollec
return serviceCollection;
}

public static TService GetServiceForType<TService, TType>(this IServiceProvider serviceProvider) =>
public static TService? GetServiceForType<TService, TType>(this IServiceProvider serviceProvider) =>
serviceProvider.GetServices<TService>().SingleOrDefault(t => t?.GetType() == typeof(TType));
}

0 comments on commit 7316e03

Please sign in to comment.