-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create interfaces for workers to make testing more direct (#10910)
create interfaces for workers to make testing more direct (#10910)
- Loading branch information
Showing
15 changed files
with
643 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
374 changes: 329 additions & 45 deletions
374
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/Run/RunWorkerTests.cs
Large diffs are not rendered by default.
Oops, something went wrong.
37 changes: 37 additions & 0 deletions
37
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestAnalyzeWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using NuGetUpdater.Core.Analyze; | ||
using NuGetUpdater.Core.Discover; | ||
|
||
namespace NuGetUpdater.Core.Test; | ||
|
||
internal class TestAnalyzeWorker : IAnalyzeWorker | ||
{ | ||
private readonly Func<(string, WorkspaceDiscoveryResult, DependencyInfo), Task<AnalysisResult>> _getResult; | ||
|
||
public TestAnalyzeWorker(Func<(string, WorkspaceDiscoveryResult, DependencyInfo), Task<AnalysisResult>> getResult) | ||
{ | ||
_getResult = getResult; | ||
} | ||
|
||
public Task<AnalysisResult> RunAsync(string repoRoot, WorkspaceDiscoveryResult discovery, DependencyInfo dependencyInfo) | ||
{ | ||
return _getResult((repoRoot, discovery, dependencyInfo)); | ||
} | ||
|
||
public static TestAnalyzeWorker FromResults(params (string RepoRoot, WorkspaceDiscoveryResult Discovery, DependencyInfo DependencyInfo, AnalysisResult Result)[] results) | ||
{ | ||
return new TestAnalyzeWorker(((string RepoRoot, WorkspaceDiscoveryResult Discovery, DependencyInfo DependencyInfo) input) => | ||
{ | ||
foreach (var set in results) | ||
{ | ||
if (set.RepoRoot == input.RepoRoot && | ||
set.Discovery == input.Discovery && | ||
set.DependencyInfo == input.DependencyInfo) | ||
{ | ||
return Task.FromResult(set.Result); | ||
} | ||
} | ||
throw new NotImplementedException($"No saved response for {input}"); | ||
}); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestDiscoveryWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using NuGetUpdater.Core.Discover; | ||
|
||
namespace NuGetUpdater.Core.Test; | ||
|
||
internal class TestDiscoveryWorker : IDiscoveryWorker | ||
{ | ||
private readonly Func<(string, string), Task<WorkspaceDiscoveryResult>> _getResult; | ||
|
||
public TestDiscoveryWorker(Func<(string, string), Task<WorkspaceDiscoveryResult>> getResult) | ||
{ | ||
_getResult = getResult; | ||
} | ||
|
||
public Task<WorkspaceDiscoveryResult> RunAsync(string repoRootPath, string workspacePath) | ||
{ | ||
return _getResult((repoRootPath, workspacePath)); | ||
} | ||
|
||
public static TestDiscoveryWorker FromResults(params (string RepoRootPath, string WorkspacePath, WorkspaceDiscoveryResult Result)[] results) | ||
{ | ||
return new TestDiscoveryWorker(((string RepoRootPath, string WorkspacePath) input) => | ||
{ | ||
foreach (var set in results) | ||
{ | ||
if (set.RepoRootPath == input.RepoRootPath && | ||
set.WorkspacePath == input.WorkspacePath) | ||
{ | ||
return Task.FromResult(set.Result); | ||
} | ||
} | ||
throw new NotImplementedException($"No saved response for {input}"); | ||
}); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core.Test/TestUpdaterWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using NuGetUpdater.Core.Updater; | ||
|
||
namespace NuGetUpdater.Core.Test; | ||
|
||
internal class TestUpdaterWorker : IUpdaterWorker | ||
{ | ||
private readonly Func<(string, string, string, string, string, bool), Task<UpdateOperationResult>> _getResult; | ||
|
||
public TestUpdaterWorker(Func<(string, string, string, string, string, bool), Task<UpdateOperationResult>> getResult) | ||
{ | ||
_getResult = getResult; | ||
} | ||
|
||
public Task<UpdateOperationResult> RunAsync(string repoRootPath, string workspacePath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, bool isTransitive) | ||
{ | ||
return _getResult((repoRootPath, workspacePath, dependencyName, previousDependencyVersion, newDependencyVersion, isTransitive)); | ||
} | ||
|
||
public static TestUpdaterWorker FromResults(params (string RepoRootPath, string WorkspacePath, string DependencyName, string PreviousDependencyVersion, string NewDependencyVersion, bool IsTransitive, UpdateOperationResult Result)[] results) | ||
{ | ||
return new TestUpdaterWorker(((string RepoRootPath, string WorkspacePath, string DependencyName, string PreviousDependencyVersion, string NewDependencyVersion, bool IsTransitive) input) => | ||
{ | ||
foreach (var set in results) | ||
{ | ||
if (set.RepoRootPath == input.RepoRootPath && | ||
set.WorkspacePath == input.WorkspacePath && | ||
set.DependencyName == input.DependencyName && | ||
set.PreviousDependencyVersion == input.PreviousDependencyVersion && | ||
set.NewDependencyVersion == input.NewDependencyVersion && | ||
set.IsTransitive == input.IsTransitive) | ||
{ | ||
return Task.FromResult(set.Result); | ||
} | ||
} | ||
throw new NotImplementedException($"No saved response for {input}"); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IAnalyzeWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using NuGetUpdater.Core.Analyze; | ||
using NuGetUpdater.Core.Discover; | ||
|
||
namespace NuGetUpdater.Core; | ||
|
||
public interface IAnalyzeWorker | ||
{ | ||
Task<AnalysisResult> RunAsync(string repoRoot, WorkspaceDiscoveryResult discovery, DependencyInfo dependencyInfo); | ||
} |
8 changes: 8 additions & 0 deletions
8
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IDiscoveryWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using NuGetUpdater.Core.Discover; | ||
|
||
namespace NuGetUpdater.Core; | ||
|
||
public interface IDiscoveryWorker | ||
{ | ||
Task<WorkspaceDiscoveryResult> RunAsync(string repoRootPath, string workspacePath); | ||
} |
9 changes: 9 additions & 0 deletions
9
nuget/helpers/lib/NuGetUpdater/NuGetUpdater.Core/IUpdaterWorker.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
using NuGetUpdater.Core.Updater; | ||
|
||
namespace NuGetUpdater.Core; | ||
|
||
public interface IUpdaterWorker | ||
{ | ||
Task<UpdateOperationResult> RunAsync(string repoRootPath, string workspacePath, string dependencyName, string previousDependencyVersion, string newDependencyVersion, bool isTransitive); | ||
} |
Oops, something went wrong.