fix analyzer warnings: SA1210, SA1414, VSTHRD002, CA1849, VSTHRD103, VSTHRD104 (#341)
This commit is contained in:
Родитель
06d906ac44
Коммит
2a128f69f0
|
@ -463,14 +463,6 @@ dotnet_naming_rule.parameters_rule.severity = warning
|
|||
# Using directive should appear within a namespace declaration
|
||||
dotnet_diagnostic.SA1200.severity = suggestion
|
||||
|
||||
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1210.md
|
||||
# Using directives should be ordered alphabetically by the namespaces
|
||||
dotnet_diagnostic.SA1210.severity = suggestion
|
||||
|
||||
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1414.md
|
||||
# Tuple types in signatures should have element names
|
||||
dotnet_diagnostic.SA1414.severity = suggestion
|
||||
|
||||
# https://github.com/DotNetAnalyzers/StyleCopAnalyzers/blob/master/documentation/SA1600.md
|
||||
# Elements should be documented
|
||||
dotnet_diagnostic.SA1600.severity = suggestion
|
||||
|
@ -500,22 +492,10 @@ dotnet_diagnostic.SA1642.severity = suggestion
|
|||
# https://github.com/Microsoft/vs-threading
|
||||
##########################################
|
||||
|
||||
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD002.md
|
||||
# Synchronously waiting on tasks or awaiters may cause deadlocks. Use await or JoinableTaskFactory.Run instead.
|
||||
dotnet_diagnostic.VSTHRD002.severity = suggestion
|
||||
|
||||
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD103.md
|
||||
# Result synchronously blocks. Use await instead.
|
||||
dotnet_diagnostic.VSTHRD103.severity = suggestion
|
||||
|
||||
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD101.md
|
||||
# Avoid using async lambda for a void returning delegate type, because any exceptions not handled by the delegate will crash the process
|
||||
dotnet_diagnostic.VSTHRD101.severity = suggestion
|
||||
|
||||
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD104.md
|
||||
# Expose an async version of this method that does not synchronously block. Then simplify this method to call that async method within a JoinableTaskFactory.Run delegate.
|
||||
dotnet_diagnostic.VSTHRD104.severity = suggestion
|
||||
|
||||
# https://github.com/microsoft/vs-threading/blob/main/doc/analyzers/VSTHRD111.md
|
||||
# Add .ConfigureAwait(bool) to your await expression
|
||||
dotnet_diagnostic.VSTHRD111.severity = suggestion
|
||||
|
@ -660,9 +640,6 @@ dotnet_diagnostic.CA1056.severity = suggestion
|
|||
# CA1838: Avoid 'StringBuilder' parameters for P/Invokes
|
||||
dotnet_diagnostic.CA1838.severity = suggestion
|
||||
|
||||
# CA1849: Call async methods when in an async method
|
||||
dotnet_diagnostic.CA1849.severity = suggestion
|
||||
|
||||
# CA2000: Dispose objects before losing scope
|
||||
dotnet_diagnostic.CA2000.severity = suggestion
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.ComponentDetection.Common
|
|||
throw new TimeoutException($"The execution did not complete in the alotted time ({timeout.TotalSeconds} seconds) and has been terminated prior to completion");
|
||||
}
|
||||
|
||||
return work.Result;
|
||||
return await work;
|
||||
}
|
||||
|
||||
public static async Task ExecuteVoidWithTimeoutAsync(Action toExecute, TimeSpan timeout, CancellationToken cancellationToken)
|
||||
|
|
|
@ -87,10 +87,10 @@ namespace Microsoft.ComponentDetection.Common
|
|||
return CreateDockerReference(reference);
|
||||
}
|
||||
|
||||
public static (string, string) SplitDockerDomain(string name)
|
||||
public static (string Domain, string Remainder) SplitDockerDomain(string name)
|
||||
{
|
||||
string domain;
|
||||
string reminder;
|
||||
string remainder;
|
||||
|
||||
var indexOfSlash = name.IndexOf('/');
|
||||
if (indexOfSlash == -1 || !(
|
||||
|
@ -99,12 +99,12 @@ namespace Microsoft.ComponentDetection.Common
|
|||
name.StartsWith("localhost/")))
|
||||
{
|
||||
domain = DEFAULTDOMAIN;
|
||||
reminder = name;
|
||||
remainder = name;
|
||||
}
|
||||
else
|
||||
{
|
||||
domain = name[..indexOfSlash];
|
||||
reminder = name[(indexOfSlash + 1)..];
|
||||
remainder = name[(indexOfSlash + 1)..];
|
||||
}
|
||||
|
||||
if (domain == LEGACYDEFAULTDOMAIN)
|
||||
|
@ -112,12 +112,12 @@ namespace Microsoft.ComponentDetection.Common
|
|||
domain = DEFAULTDOMAIN;
|
||||
}
|
||||
|
||||
if (domain == DEFAULTDOMAIN && reminder.IndexOf('/') == -1)
|
||||
if (domain == DEFAULTDOMAIN && remainder.IndexOf('/') == -1)
|
||||
{
|
||||
reminder = $"{OFFICIALREPOSITORYNAME}/{reminder}";
|
||||
remainder = $"{OFFICIALREPOSITORYNAME}/{remainder}";
|
||||
}
|
||||
|
||||
return (domain, reminder);
|
||||
return (domain, remainder);
|
||||
}
|
||||
|
||||
public static DockerReference ParseFamiliarName(string name)
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Microsoft.ComponentDetection.Common.Telemetry.Records
|
|||
record.Dispose();
|
||||
if (terminalRecord && !(record.Command?.Equals("help", StringComparison.InvariantCultureIgnoreCase) ?? false))
|
||||
{
|
||||
TelemetryRelay.Instance.Shutdown();
|
||||
await TelemetryRelay.Instance.ShutdownAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.Composition;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.ComponentDetection.Common.Telemetry.Records;
|
||||
|
||||
namespace Microsoft.ComponentDetection.Common.Telemetry
|
||||
|
@ -51,7 +52,8 @@ namespace Microsoft.ComponentDetection.Common.Telemetry
|
|||
/// <summary>
|
||||
/// Disables the sending of telemetry and flushes any messages out of the queue for each service.
|
||||
/// </summary>
|
||||
public void Shutdown()
|
||||
/// <returns><see cref="Task"/> representing the asynchronous operation.</returns>
|
||||
public async Task ShutdownAsync()
|
||||
{
|
||||
Active = false;
|
||||
|
||||
|
@ -60,10 +62,10 @@ namespace Microsoft.ComponentDetection.Common.Telemetry
|
|||
try
|
||||
{
|
||||
// Set a timeout for services that flush synchronously.
|
||||
AsyncExecution.ExecuteVoidWithTimeoutAsync(
|
||||
await AsyncExecution.ExecuteVoidWithTimeoutAsync(
|
||||
() => service.Flush(),
|
||||
TimeSpan.FromSeconds(20),
|
||||
CancellationToken.None).Wait();
|
||||
CancellationToken.None);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
|
|
@ -252,7 +252,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
|
|||
}
|
||||
}
|
||||
|
||||
private void TraverseRequirementAndDependencyTree(IEnumerable<(JProperty, TypedComponent)> topLevelDependencies, IDictionary<string, JProperty> dependencyLookup, ISingleFileComponentRecorder singleFileComponentRecorder)
|
||||
private void TraverseRequirementAndDependencyTree(IEnumerable<(JProperty Dependency, TypedComponent ParentComponent)> topLevelDependencies, IDictionary<string, JProperty> dependencyLookup, ISingleFileComponentRecorder singleFileComponentRecorder)
|
||||
{
|
||||
// iterate through everything for a top level dependency with a single explicitReferencedDependency value
|
||||
foreach (var (currentDependency, _) in topLevelDependencies)
|
||||
|
@ -292,7 +292,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
|
|||
}
|
||||
}
|
||||
|
||||
private void EnqueueDependencies(Queue<(JProperty, TypedComponent)> queue, JToken dependencies, TypedComponent parentComponent)
|
||||
private void EnqueueDependencies(Queue<(JProperty Dependency, TypedComponent ParentComponent)> queue, JToken dependencies, TypedComponent parentComponent)
|
||||
{
|
||||
if (dependencies != null)
|
||||
{
|
||||
|
@ -306,7 +306,7 @@ namespace Microsoft.ComponentDetection.Detectors.Npm
|
|||
}
|
||||
}
|
||||
|
||||
private bool TryEnqueueFirstLevelDependencies(Queue<(JProperty, TypedComponent)> queue, JToken dependencies, IDictionary<string, JProperty> dependencyLookup, Queue<TypedComponent> parentComponentQueue = null, TypedComponent parentComponent = null, bool skipValidation = false)
|
||||
private bool TryEnqueueFirstLevelDependencies(Queue<(JProperty DependencyProperty, TypedComponent ParentComponent)> queue, JToken dependencies, IDictionary<string, JProperty> dependencyLookup, Queue<TypedComponent> parentComponentQueue = null, TypedComponent parentComponent = null, bool skipValidation = false)
|
||||
{
|
||||
var isValid = true;
|
||||
if (dependencies != null)
|
||||
|
|
|
@ -8,6 +8,6 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
{
|
||||
Task<bool> PythonExists(string pythonPath = null);
|
||||
|
||||
Task<IList<(string, GitComponent)>> ParseFile(string path, string pythonPath = null);
|
||||
Task<IList<(string PackageString, GitComponent Component)>> ParseFile(string path, string pythonPath = null);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,8 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
try
|
||||
{
|
||||
var initialPackages = await this.PythonCommandService.ParseFile(file.Location, pythonExePath);
|
||||
var listedPackage = initialPackages.Where(tuple => tuple.Item1 != null)
|
||||
.Select(tuple => tuple.Item1)
|
||||
var listedPackage = initialPackages.Where(tuple => tuple.PackageString != null)
|
||||
.Select(tuple => tuple.PackageString)
|
||||
.Where(x => !string.IsNullOrWhiteSpace(x))
|
||||
.Select(x => new PipDependencySpecification(x))
|
||||
.Where(x => !x.PackageIsUnsafe())
|
||||
|
@ -64,8 +64,8 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
singleFileComponentRecorder,
|
||||
roots);
|
||||
|
||||
initialPackages.Where(tuple => tuple.Item2 != null)
|
||||
.Select(tuple => new DetectedComponent(tuple.Item2))
|
||||
initialPackages.Where(tuple => tuple.Component != null)
|
||||
.Select(tuple => new DetectedComponent(tuple.Component))
|
||||
.ToList()
|
||||
.ForEach(gitComponent => singleFileComponentRecorder.RegisterUsage(gitComponent, isExplicitReferencedDependency: true));
|
||||
}
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
return !string.IsNullOrEmpty(await this.ResolvePython(pythonPath));
|
||||
}
|
||||
|
||||
public async Task<IList<(string, GitComponent)>> ParseFile(string filePath, string pythonPath = null)
|
||||
public async Task<IList<(string PackageString, GitComponent Component)>> ParseFile(string filePath, string pythonPath = null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(filePath))
|
||||
{
|
||||
|
@ -69,7 +69,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
return result.Split(new string[] { "'," }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim().Trim('\'').Trim()).ToList();
|
||||
}
|
||||
|
||||
private IList<(string, GitComponent)> ParseRequirementsTextFile(string path)
|
||||
private IList<(string PackageString, GitComponent Component)> ParseRequirementsTextFile(string path)
|
||||
{
|
||||
var items = new List<(string, GitComponent)>();
|
||||
foreach (var line in File.ReadAllLines(path).Select(x => x.Trim().TrimEnd('\\')).Where(x => !x.StartsWith("#") && !x.StartsWith("-") && !string.IsNullOrWhiteSpace(x)))
|
||||
|
|
|
@ -211,7 +211,7 @@ namespace Microsoft.ComponentDetection.Detectors.Pip
|
|||
public IDictionary<string, SortedDictionary<string, IList<PythonProjectRelease>>> ValidVersionMap { get; }
|
||||
= new Dictionary<string, SortedDictionary<string, IList<PythonProjectRelease>>>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public Queue<(string, PipDependencySpecification)> ProcessingQueue { get; } = new Queue<(string, PipDependencySpecification)>();
|
||||
public Queue<(string PackageName, PipDependencySpecification Package)> ProcessingQueue { get; } = new Queue<(string, PipDependencySpecification)>();
|
||||
|
||||
public IDictionary<string, PipGraphNode> NodeReferences { get; } = new Dictionary<string, PipGraphNode>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Composition;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
using Tomlyn;
|
||||
using Microsoft.ComponentDetection.Contracts;
|
||||
using Microsoft.ComponentDetection.Contracts.Internal;
|
||||
using Microsoft.ComponentDetection.Contracts.TypedComponent;
|
||||
using Microsoft.ComponentDetection.Detectors.Poetry.Contracts;
|
||||
using Tomlyn;
|
||||
|
||||
namespace Microsoft.ComponentDetection.Detectors.Poetry
|
||||
{
|
||||
|
@ -25,7 +25,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry
|
|||
|
||||
public override IEnumerable<string> Categories => new List<string> { "Python" };
|
||||
|
||||
protected override Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
|
||||
protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
|
||||
{
|
||||
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
|
||||
var poetryLockFile = processRequest.ComponentStream;
|
||||
|
@ -36,7 +36,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry
|
|||
{
|
||||
IgnoreMissingProperties = true,
|
||||
};
|
||||
var poetryLock = Toml.ToModel<PoetryLock>(reader.ReadToEnd(), options: options);
|
||||
var poetryLock = Toml.ToModel<PoetryLock>(await reader.ReadToEndAsync(), options: options);
|
||||
poetryLock.Package.ToList().ForEach(package =>
|
||||
{
|
||||
var isDevelopmentDependency = package.Category != "main";
|
||||
|
@ -52,7 +52,7 @@ namespace Microsoft.ComponentDetection.Detectors.Poetry
|
|||
singleFileComponentRecorder.RegisterUsage(component, isDevelopmentDependency: isDevelopmentDependency);
|
||||
}
|
||||
});
|
||||
return Task.CompletedTask;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
|
|||
|
||||
private static bool IsLocalPackage(CargoPackage package) => package.Source == null;
|
||||
|
||||
protected override Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
|
||||
protected override async Task OnFileFound(ProcessRequest processRequest, IDictionary<string, string> detectorArgs)
|
||||
{
|
||||
var singleFileComponentRecorder = processRequest.SingleFileComponentRecorder;
|
||||
var cargoLockFile = processRequest.ComponentStream;
|
||||
|
@ -67,7 +67,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
|
|||
{
|
||||
IgnoreMissingProperties = true,
|
||||
};
|
||||
var cargoLock = Toml.ToModel<CargoLock>(reader.ReadToEnd(), options: options);
|
||||
var cargoLock = Toml.ToModel<CargoLock>(await reader.ReadToEndAsync(), options: options);
|
||||
|
||||
var seenAsDependency = new HashSet<CargoPackage>();
|
||||
|
||||
|
@ -143,7 +143,7 @@ namespace Microsoft.ComponentDetection.Detectors.Rust
|
|||
this.Logger.LogFailedReadingFile(cargoLockFile.Location, e);
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
await Task.CompletedTask;
|
||||
}
|
||||
|
||||
private void ProcessDependency(
|
||||
|
|
|
@ -202,11 +202,7 @@ namespace Microsoft.ComponentDetection.Orchestrator
|
|||
|
||||
return string.Join(Environment.NewLine, aptListResult.Split(Environment.NewLine).Where(x => x.Contains("libssl")));
|
||||
});
|
||||
|
||||
if (!getLibSslPackages.Wait(taskTimeout))
|
||||
{
|
||||
throw new TimeoutException($"The execution did not complete in the alotted time ({taskTimeout} seconds) and has been terminated prior to completion");
|
||||
}
|
||||
await getLibSslPackages.WaitAsync(taskTimeout);
|
||||
|
||||
agentOSMeaningfulDetails[LibSslDetailsKey] = await getLibSslPackages;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
@ -73,7 +73,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return mock;
|
||||
}
|
||||
|
||||
public static (string, string, string) GetPackageJsonOneRoot(string componentName0, string version0)
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetPackageJsonOneRoot(string componentName0, string version0)
|
||||
{
|
||||
var packagejson = @"{{
|
||||
""name"": ""test"",
|
||||
|
@ -88,7 +88,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return ("package.json", packageJsonTemplate, Path.Combine(Path.GetTempPath(), "package.json"));
|
||||
}
|
||||
|
||||
public static (string, string, string) GetPackageJsonNoDependenciesForNameAndVersion(string packageName, string packageVersion)
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetPackageJsonNoDependenciesForNameAndVersion(string packageName, string packageVersion)
|
||||
{
|
||||
var packagejson = @"{{
|
||||
""name"": ""{0}"",
|
||||
|
@ -98,7 +98,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return ("package.json", packageJsonTemplate, Path.Combine(Path.GetTempPath(), "package.json"));
|
||||
}
|
||||
|
||||
public static (string, string, string) GetPackageJsonNoDependenciesForAuthorAndEmailInJsonFormat(
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetPackageJsonNoDependenciesForAuthorAndEmailInJsonFormat(
|
||||
string authorName, string authorEmail = null)
|
||||
{
|
||||
string packagejson;
|
||||
|
@ -128,7 +128,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return ("package.json", packageJsonTemplate, Path.Combine(Path.GetTempPath(), "package.json"));
|
||||
}
|
||||
|
||||
public static (string, string, string) GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetPackageJsonNoDependenciesForAuthorAndEmailAsSingleString(
|
||||
string authorName, string authorEmail = null, string authorUrl = null)
|
||||
{
|
||||
var packagejson = @"{{{{
|
||||
|
@ -159,7 +159,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return ("package.json", packageJsonTemplate, Path.Combine(Path.GetTempPath(), "package.json"));
|
||||
}
|
||||
|
||||
public static (string, string, string) GetPackageJsonNoDependenciesMalformedAuthorAsSingleString(
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetPackageJsonNoDependenciesMalformedAuthorAsSingleString(
|
||||
string authorName, string authorEmail = null, string authorUrl = null)
|
||||
{
|
||||
var packagejson = @"{{{{
|
||||
|
@ -190,7 +190,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
return ("package.json", packageJsonTemplate, Path.Combine(Path.GetTempPath(), "package.json"));
|
||||
}
|
||||
|
||||
public static (string, string, string) GetWellFormedPackageLock2(string lockFileName, string rootName0 = null, string rootVersion0 = null, string rootName2 = null, string rootVersion2 = null, string packageName0 = "test", string packageName1 = null, string packageName3 = null)
|
||||
public static (string PackageJsonName, string PackageJsonContents, string PackageJsonPath) GetWellFormedPackageLock2(string lockFileName, string rootName0 = null, string rootVersion0 = null, string rootName2 = null, string rootVersion2 = null, string packageName0 = "test", string packageName1 = null, string packageName3 = null)
|
||||
{
|
||||
var packageLockJson = @"{{
|
||||
""name"": ""{10}"",
|
||||
|
|
|
@ -313,7 +313,7 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
parentIds.Select(parentId => new Func<PipComponent, bool>(x => x.Id == parentId)).ToArray());
|
||||
}
|
||||
|
||||
private List<(string, GitComponent)> ToGitTuple(IList<string> components)
|
||||
private List<(string PackageString, GitComponent Component)> ToGitTuple(IList<string> components)
|
||||
{
|
||||
return components.Select<string, (string, GitComponent)>(dep => (dep, null)).ToList();
|
||||
}
|
||||
|
|
|
@ -147,10 +147,10 @@ other=2.1";
|
|||
{
|
||||
using (var writer = File.CreateText(testPath))
|
||||
{
|
||||
writer.WriteLine("knack==0.4.1");
|
||||
writer.WriteLine("vsts-cli-common==0.1.3 \\ ");
|
||||
writer.WriteLine(" --hash=sha256:856476331f3e26598017290fd65bebe81c960e806776f324093a46b76fb2d1c0");
|
||||
writer.Flush();
|
||||
await writer.WriteLineAsync("knack==0.4.1");
|
||||
await writer.WriteLineAsync("vsts-cli-common==0.1.3 \\ ");
|
||||
await writer.WriteLineAsync(" --hash=sha256:856476331f3e26598017290fd65bebe81c960e806776f324093a46b76fb2d1c0");
|
||||
await writer.FlushAsync();
|
||||
}
|
||||
|
||||
var result = await service.ParseFile(testPath);
|
||||
|
@ -184,9 +184,9 @@ other=2.1";
|
|||
{
|
||||
using (var writer = File.CreateText(testPath))
|
||||
{
|
||||
writer.WriteLine("#this is a comment");
|
||||
writer.WriteLine("knack==0.4.1 #this is another comment");
|
||||
writer.Flush();
|
||||
await writer.WriteLineAsync("#this is a comment");
|
||||
await writer.WriteLineAsync("knack==0.4.1 #this is another comment");
|
||||
await writer.FlushAsync();
|
||||
}
|
||||
|
||||
var result = await service.ParseFile(testPath);
|
||||
|
@ -211,11 +211,11 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(1);
|
||||
|
||||
var tuple = parseResult.Single();
|
||||
tuple.Item1.Should().BeNull();
|
||||
tuple.Item2.Should().NotBeNull();
|
||||
var (packageString, component) = parseResult.Single();
|
||||
packageString.Should().BeNull();
|
||||
component.Should().NotBeNull();
|
||||
|
||||
var gitComponent = tuple.Item2;
|
||||
var gitComponent = component;
|
||||
gitComponent.RepositoryUrl.Should().Be("https://github.com/vscode-python/jedi-language-server");
|
||||
gitComponent.CommitHash.Should().Be("42823a2598d4b6369e9273c5ad237a48c5d67553");
|
||||
});
|
||||
|
@ -228,11 +228,11 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(1);
|
||||
|
||||
var tuple = parseResult.Single();
|
||||
tuple.Item1.Should().BeNull();
|
||||
tuple.Item2.Should().NotBeNull();
|
||||
var (packageString, component) = parseResult.Single();
|
||||
packageString.Should().BeNull();
|
||||
component.Should().NotBeNull();
|
||||
|
||||
var gitComponent = tuple.Item2;
|
||||
var gitComponent = component;
|
||||
gitComponent.RepositoryUrl.Should().Be("https://github.com/vscode-python/jedi-language-server");
|
||||
gitComponent.CommitHash.Should().Be("42823a2598d4b6369e9273c5ad237a48c5d67553");
|
||||
});
|
||||
|
@ -245,11 +245,11 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(1);
|
||||
|
||||
var tuple = parseResult.Single();
|
||||
tuple.Item1.Should().BeNull();
|
||||
tuple.Item2.Should().NotBeNull();
|
||||
var (packageString, component) = parseResult.Single();
|
||||
packageString.Should().BeNull();
|
||||
component.Should().NotBeNull();
|
||||
|
||||
var gitComponent = tuple.Item2;
|
||||
var gitComponent = component;
|
||||
gitComponent.RepositoryUrl.Should().Be("https://github.com/vscode-python/jedi-language-server");
|
||||
gitComponent.CommitHash.Should().Be("42823a2598d4b6369e9273c5ad237a48c5d67553");
|
||||
});
|
||||
|
@ -262,11 +262,11 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(1);
|
||||
|
||||
var tuple = parseResult.Single();
|
||||
tuple.Item1.Should().BeNull();
|
||||
tuple.Item2.Should().NotBeNull();
|
||||
var (packageString, component) = parseResult.Single();
|
||||
packageString.Should().BeNull();
|
||||
component.Should().NotBeNull();
|
||||
|
||||
var gitComponent = tuple.Item2;
|
||||
var gitComponent = component;
|
||||
gitComponent.RepositoryUrl.Should().Be("https://github.com/vscode-python/jedi-language-server");
|
||||
gitComponent.CommitHash.Should().Be("42823a2598d4b6369e9273c5ad237a48c5d67553");
|
||||
});
|
||||
|
@ -306,19 +306,19 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(2);
|
||||
|
||||
var tuple1 = parseResult.First();
|
||||
tuple1.Item1.Should().BeNull();
|
||||
tuple1.Item2.Should().NotBeNull();
|
||||
var (packageString, component) = parseResult.First();
|
||||
packageString.Should().BeNull();
|
||||
component.Should().NotBeNull();
|
||||
|
||||
var gitComponent1 = tuple1.Item2;
|
||||
var gitComponent1 = component;
|
||||
gitComponent1.RepositoryUrl.Should().Be("https://github.com/vscode-python/jedi-language-server");
|
||||
gitComponent1.CommitHash.Should().Be("42823a2598d4b6369e9273c5ad237a48c5d67553");
|
||||
|
||||
var tuple2 = parseResult.Skip(1).First();
|
||||
tuple2.Item1.Should().BeNull();
|
||||
tuple2.Item2.Should().NotBeNull();
|
||||
var (packageString2, component2) = parseResult.Skip(1).First();
|
||||
packageString2.Should().BeNull();
|
||||
component2.Should().NotBeNull();
|
||||
|
||||
var gitComponent2 = tuple2.Item2;
|
||||
var gitComponent2 = component2;
|
||||
gitComponent2.RepositoryUrl.Should().Be("https://github.com/path/to/package-two");
|
||||
gitComponent2.CommitHash.Should().Be("41b95ec");
|
||||
});
|
||||
|
@ -331,31 +331,31 @@ other=2.1";
|
|||
{
|
||||
parseResult.Count.Should().Be(3);
|
||||
|
||||
var tuple1 = parseResult.First();
|
||||
tuple1.Item1.Should().NotBeNull();
|
||||
tuple1.Item2.Should().BeNull();
|
||||
var (packageString, component) = parseResult.First();
|
||||
packageString.Should().NotBeNull();
|
||||
component.Should().BeNull();
|
||||
|
||||
var regularComponent1 = tuple1.Item1;
|
||||
var regularComponent1 = packageString;
|
||||
regularComponent1.Should().Be("something=1.3");
|
||||
|
||||
var tuple2 = parseResult.Skip(1).First();
|
||||
tuple2.Item1.Should().BeNull();
|
||||
tuple2.Item2.Should().NotBeNull();
|
||||
var (packageString2, component2) = parseResult.Skip(1).First();
|
||||
packageString2.Should().BeNull();
|
||||
component2.Should().NotBeNull();
|
||||
|
||||
var gitComponent = tuple2.Item2;
|
||||
var gitComponent = component2;
|
||||
gitComponent.RepositoryUrl.Should().Be("https://github.com/path/to/package-two");
|
||||
gitComponent.CommitHash.Should().Be("41b95ec");
|
||||
|
||||
var tuple3 = parseResult.ToArray()[2];
|
||||
tuple3.Item1.Should().NotBeNull();
|
||||
tuple3.Item2.Should().BeNull();
|
||||
var (packageString3, component3) = parseResult.ToArray()[2];
|
||||
packageString3.Should().NotBeNull();
|
||||
component3.Should().BeNull();
|
||||
|
||||
var regularComponent2 = tuple3.Item1;
|
||||
var regularComponent2 = packageString3;
|
||||
regularComponent2.Should().Be("other=2.1");
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<int> SetupAndParseReqsTxt(string fileToParse, Action<IList<(string, GitComponent)>> verificationFunction)
|
||||
private async Task<int> SetupAndParseReqsTxt(string fileToParse, Action<IList<(string PackageString, GitComponent Component)>> verificationFunction)
|
||||
{
|
||||
var testPath = Path.Join(Directory.GetCurrentDirectory(), string.Join(Guid.NewGuid().ToString(), ".txt"));
|
||||
|
||||
|
@ -364,8 +364,8 @@ other=2.1";
|
|||
|
||||
using (var writer = File.CreateText(testPath))
|
||||
{
|
||||
writer.WriteLine(fileToParse);
|
||||
writer.Flush();
|
||||
await writer.WriteLineAsync(fileToParse);
|
||||
await writer.FlushAsync();
|
||||
}
|
||||
|
||||
var result = await service.ParseFile(testPath);
|
||||
|
|
|
@ -56,8 +56,8 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine(yarnLockFileVersionString);
|
||||
writer.Flush();
|
||||
await writer.WriteLineAsync(yarnLockFileVersionString);
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -76,14 +76,14 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine(yarnLockFileVersionString);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("block1:");
|
||||
writer.WriteLine(" property \"value\"");
|
||||
writer.WriteLine(" block2:");
|
||||
writer.WriteLine(" otherProperty \"otherValue\"");
|
||||
await writer.WriteLineAsync(yarnLockFileVersionString);
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("block1:");
|
||||
await writer.WriteLineAsync(" property \"value\"");
|
||||
await writer.WriteLineAsync(" block2:");
|
||||
await writer.WriteLineAsync(" otherProperty \"otherValue\"");
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -107,32 +107,32 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine(yarnLockFileVersionString);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("block1:");
|
||||
writer.WriteLine(" property \"value\"");
|
||||
writer.WriteLine(" childblock1:");
|
||||
writer.WriteLine(" otherProperty \"otherValue\"");
|
||||
await writer.WriteLineAsync(yarnLockFileVersionString);
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("block1:");
|
||||
await writer.WriteLineAsync(" property \"value\"");
|
||||
await writer.WriteLineAsync(" childblock1:");
|
||||
await writer.WriteLineAsync(" otherProperty \"otherValue\"");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine(yarnLockFileVersionString);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("block2:");
|
||||
writer.WriteLine(" property \"value\"");
|
||||
writer.WriteLine(" childBlock2:");
|
||||
writer.WriteLine(" otherProperty \"otherValue\"");
|
||||
await writer.WriteLineAsync(yarnLockFileVersionString);
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("block2:");
|
||||
await writer.WriteLineAsync(" property \"value\"");
|
||||
await writer.WriteLineAsync(" childBlock2:");
|
||||
await writer.WriteLineAsync(" otherProperty \"otherValue\"");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine(yarnLockFileVersionString);
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("block3:");
|
||||
writer.WriteLine(" property \"value\"");
|
||||
writer.WriteLine(" childBlock3:");
|
||||
writer.WriteLine(" otherProperty \"otherValue\"");
|
||||
await writer.WriteLineAsync(yarnLockFileVersionString);
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("block3:");
|
||||
await writer.WriteLineAsync(" property \"value\"");
|
||||
await writer.WriteLineAsync(" childBlock3:");
|
||||
await writer.WriteLineAsync(" otherProperty \"otherValue\"");
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -151,15 +151,15 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("# This file is generated by running \"yarn install\" inside your project.");
|
||||
writer.WriteLine("# Manual changes might be lost - proceed with caution!");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("__metadata:");
|
||||
writer.WriteLine(" version: 4");
|
||||
writer.WriteLine(" cacheKey: 7");
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync("# This file is generated by running \"yarn install\" inside your project.");
|
||||
await writer.WriteLineAsync("# Manual changes might be lost - proceed with caution!");
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("__metadata:");
|
||||
await writer.WriteLineAsync(" version: 4");
|
||||
await writer.WriteLineAsync(" cacheKey: 7");
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -178,21 +178,21 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("# This file is generated by running \"yarn install\" inside your project.");
|
||||
writer.WriteLine("# Manual changes might be lost - proceed with caution!");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("__metadata:");
|
||||
writer.WriteLine(" version: 4");
|
||||
writer.WriteLine(" cacheKey: 7");
|
||||
await writer.WriteLineAsync("# This file is generated by running \"yarn install\" inside your project.");
|
||||
await writer.WriteLineAsync("# Manual changes might be lost - proceed with caution!");
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("__metadata:");
|
||||
await writer.WriteLineAsync(" version: 4");
|
||||
await writer.WriteLineAsync(" cacheKey: 7");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine("block1:");
|
||||
writer.WriteLine(" property: value");
|
||||
writer.WriteLine(" block2:");
|
||||
writer.WriteLine(" otherProperty: otherValue");
|
||||
await writer.WriteLineAsync("block1:");
|
||||
await writer.WriteLineAsync(" property: value");
|
||||
await writer.WriteLineAsync(" block2:");
|
||||
await writer.WriteLineAsync(" otherProperty: otherValue");
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -216,21 +216,21 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("# This file is generated by running \"yarn install\" inside your project.");
|
||||
writer.WriteLine("# Manual changes might be lost - proceed with caution!");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("__metadata:");
|
||||
writer.WriteLine(" version: 4");
|
||||
writer.WriteLine(" cacheKey: 7");
|
||||
await writer.WriteLineAsync("# This file is generated by running \"yarn install\" inside your project.");
|
||||
await writer.WriteLineAsync("# Manual changes might be lost - proceed with caution!");
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("__metadata:");
|
||||
await writer.WriteLineAsync(" version: 4");
|
||||
await writer.WriteLineAsync(" cacheKey: 7");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine("block1:");
|
||||
writer.WriteLine(" property: \"value\"");
|
||||
writer.WriteLine(" block2:");
|
||||
writer.WriteLine(" \"otherProperty\": otherValue");
|
||||
await writer.WriteLineAsync("block1:");
|
||||
await writer.WriteLineAsync(" property: \"value\"");
|
||||
await writer.WriteLineAsync(" block2:");
|
||||
await writer.WriteLineAsync(" \"otherProperty\": otherValue");
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
@ -254,35 +254,35 @@ namespace Microsoft.ComponentDetection.Detectors.Tests
|
|||
|
||||
using var writer = new StreamWriter(stream);
|
||||
|
||||
writer.WriteLine("# This file is generated by running \"yarn install\" inside your project.");
|
||||
writer.WriteLine("# Manual changes might be lost - proceed with caution!");
|
||||
writer.WriteLine();
|
||||
writer.WriteLine("__metadata:");
|
||||
writer.WriteLine(" version: 4");
|
||||
writer.WriteLine(" cacheKey: 7");
|
||||
await writer.WriteLineAsync("# This file is generated by running \"yarn install\" inside your project.");
|
||||
await writer.WriteLineAsync("# Manual changes might be lost - proceed with caution!");
|
||||
await writer.WriteLineAsync();
|
||||
await writer.WriteLineAsync("__metadata:");
|
||||
await writer.WriteLineAsync(" version: 4");
|
||||
await writer.WriteLineAsync(" cacheKey: 7");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine("block1:");
|
||||
writer.WriteLine(" property: value");
|
||||
writer.WriteLine(" childblock1:");
|
||||
writer.WriteLine(" otherProperty: otherValue");
|
||||
await writer.WriteLineAsync("block1:");
|
||||
await writer.WriteLineAsync(" property: value");
|
||||
await writer.WriteLineAsync(" childblock1:");
|
||||
await writer.WriteLineAsync(" otherProperty: otherValue");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine("block2:");
|
||||
writer.WriteLine(" property: value");
|
||||
writer.WriteLine(" childblock2:");
|
||||
writer.WriteLine(" otherProperty: otherValue");
|
||||
await writer.WriteLineAsync("block2:");
|
||||
await writer.WriteLineAsync(" property: value");
|
||||
await writer.WriteLineAsync(" childblock2:");
|
||||
await writer.WriteLineAsync(" otherProperty: otherValue");
|
||||
|
||||
writer.WriteLine();
|
||||
await writer.WriteLineAsync();
|
||||
|
||||
writer.WriteLine("block3:");
|
||||
writer.WriteLine(" property: value");
|
||||
writer.WriteLine(" childblock3:");
|
||||
writer.WriteLine(" otherProperty: otherValue");
|
||||
await writer.WriteLineAsync("block3:");
|
||||
await writer.WriteLineAsync(" property: value");
|
||||
await writer.WriteLineAsync(" childblock3:");
|
||||
await writer.WriteLineAsync(" otherProperty: otherValue");
|
||||
|
||||
writer.Flush();
|
||||
await writer.FlushAsync();
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
|
||||
var file = await YarnBlockFile.CreateBlockFileAsync(stream);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.ComponentDetection.Contracts;
|
||||
using Microsoft.ComponentDetection.Contracts.BcdeModels;
|
||||
|
@ -50,7 +51,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void RunComponentDetection()
|
||||
public async Task RunComponentDetection()
|
||||
{
|
||||
var args = new BcdeArguments();
|
||||
|
||||
|
@ -59,9 +60,9 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
BcdeScanExecutionService = this.scanExecutionServiceMock.Object,
|
||||
};
|
||||
|
||||
var result = this.serviceUnderTest.Handle(args);
|
||||
result.Result.ResultCode.Should().Be(ProcessingResultCode.Success);
|
||||
result.Result.SourceDirectory.Should().Be("D:\\test\\directory");
|
||||
var result = await this.serviceUnderTest.Handle(args);
|
||||
result.ResultCode.Should().Be(ProcessingResultCode.Success);
|
||||
result.SourceDirectory.Should().Be("D:\\test\\directory");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ using System;
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.ComponentDetection.Common.DependencyGraph;
|
||||
using Microsoft.ComponentDetection.Contracts;
|
||||
|
@ -93,7 +94,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_HappyPath()
|
||||
public async Task DetectComponents_HappyPath()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var singleFileComponentRecorder = componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, "/some/file/path"));
|
||||
|
@ -121,7 +122,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
AdditionalPluginDirectories = Enumerable.Empty<DirectoryInfo>(),
|
||||
SourceDirectory = this.sourceDirectory,
|
||||
};
|
||||
var result = this.DetectComponentsHappyPath(
|
||||
var result = await this.DetectComponentsHappyPathAsync(
|
||||
args,
|
||||
restrictions =>
|
||||
{
|
||||
|
@ -151,7 +152,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_DetectOnlyWithIdAndCategoryRestrictions()
|
||||
public async Task DetectComponents_DetectOnlyWithIdAndCategoryRestrictions()
|
||||
{
|
||||
var args = new BcdeArguments
|
||||
{
|
||||
|
@ -166,7 +167,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[0]);
|
||||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[1]);
|
||||
|
||||
var result = this.DetectComponentsHappyPath(
|
||||
var result = await this.DetectComponentsHappyPathAsync(
|
||||
args,
|
||||
restrictions =>
|
||||
{
|
||||
|
@ -180,7 +181,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_DetectOnlyWithNoUrl()
|
||||
public async Task DetectComponents_DetectOnlyWithNoUrl()
|
||||
{
|
||||
var args = new BcdeArguments
|
||||
{
|
||||
|
@ -193,7 +194,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[0]);
|
||||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[1]);
|
||||
|
||||
var result = this.DetectComponentsHappyPath(
|
||||
var result = await this.DetectComponentsHappyPathAsync(
|
||||
args,
|
||||
restrictions =>
|
||||
{
|
||||
|
@ -205,7 +206,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_ReturnsExperimentalDetectorInformation()
|
||||
public async Task DetectComponents_ReturnsExperimentalDetectorInformation()
|
||||
{
|
||||
this.componentDetector2Mock.As<IExperimentalDetector>();
|
||||
this.componentDetector3Mock.As<IExperimentalDetector>();
|
||||
|
@ -221,7 +222,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[0]);
|
||||
singleFileComponentRecorder.RegisterUsage(this.detectedComponents[1]);
|
||||
|
||||
var result = this.DetectComponentsHappyPath(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
var result = await this.DetectComponentsHappyPathAsync(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
result.Result.Should().Be(ProcessingResultCode.Success);
|
||||
this.ValidateDetectedComponents(result.DetectedComponents);
|
||||
|
@ -229,7 +230,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_Graph_Happy_Path()
|
||||
public async Task DetectComponents_Graph_Happy_Path()
|
||||
{
|
||||
var mockGraphLocation = "/some/dependency/graph";
|
||||
|
||||
|
@ -260,7 +261,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
mockDependencyGraphA.Setup(x => x.IsDevelopmentDependency(this.detectedComponents[0].Component.Id)).Returns(true);
|
||||
mockDependencyGraphA.Setup(x => x.IsDevelopmentDependency(this.detectedComponents[1].Component.Id)).Returns(false);
|
||||
|
||||
var result = this.DetectComponentsHappyPath(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
var result = await this.DetectComponentsHappyPathAsync(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
result.SourceDirectory.Should().NotBeNull();
|
||||
result.SourceDirectory.Should().Be(this.sourceDirectory.ToString());
|
||||
|
@ -287,7 +288,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void DetectComponents_Graph_AccumulatesGraphsOnSameLocation()
|
||||
public async Task DetectComponents_Graph_AccumulatesGraphsOnSameLocation()
|
||||
{
|
||||
var mockGraphLocation = "/some/dependency/graph";
|
||||
|
||||
|
@ -335,7 +336,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorderB.RegisterUsage(this.detectedComponents[1], isExplicitReferencedDependency: true);
|
||||
singleFileComponentRecorderB.RegisterUsage(this.detectedComponents[0], parentComponentId: this.detectedComponents[1].Component.Id);
|
||||
|
||||
var result = this.DetectComponentsHappyPath(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
var result = await this.DetectComponentsHappyPathAsync(args, restrictions => { }, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
result.SourceDirectory.Should().NotBeNull();
|
||||
result.SourceDirectory.Should().Be(this.sourceDirectory.ToString());
|
||||
|
@ -358,7 +359,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_ComponentsAreReturnedWithDevDependencyInfo()
|
||||
public async Task VerifyTranslation_ComponentsAreReturnedWithDevDependencyInfo()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -377,7 +378,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorder.RegisterUsage(detectedComponent2, isDevelopmentDependency: false);
|
||||
singleFileComponentRecorder.RegisterUsage(detectedComponent3);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var detectedComponents = results.ComponentsFound;
|
||||
|
||||
|
@ -392,7 +393,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_RootsFromMultipleLocationsAreAgregated()
|
||||
public async Task VerifyTranslation_RootsFromMultipleLocationsAreAgregated()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -413,7 +414,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
var detectedComponent2NewLocation = new DetectedComponent(new NpmComponent("test", "2.0.0"), detector: npmDetector);
|
||||
singleFileComponentRecorder.RegisterUsage(detectedComponent2NewLocation, isExplicitReferencedDependency: true);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var detectedComponents = results.ComponentsFound;
|
||||
|
||||
|
@ -428,7 +429,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_ComponentsAreReturnedWithRoots()
|
||||
public async Task VerifyTranslation_ComponentsAreReturnedWithRoots()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -445,7 +446,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
singleFileComponentRecorder.RegisterUsage(detectedComponent1, isExplicitReferencedDependency: true);
|
||||
singleFileComponentRecorder.RegisterUsage(detectedComponent2, parentComponentId: detectedComponent1.Component.Id);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var detectedComponents = results.ComponentsFound;
|
||||
|
||||
|
@ -459,7 +460,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_DevDependenciesAreMergedWhenSameComponentInDifferentFiles()
|
||||
public async Task VerifyTranslation_DevDependenciesAreMergedWhenSameComponentInDifferentFiles()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -500,7 +501,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
firstRecorder.RegisterUsage(component, isDevelopmentDependency: isDevDep);
|
||||
}
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var components = results.ComponentsFound;
|
||||
|
||||
|
@ -511,7 +512,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_LocationsAreMergedWhenSameComponentInDifferentFiles()
|
||||
public async Task VerifyTranslation_LocationsAreMergedWhenSameComponentInDifferentFiles()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -532,7 +533,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
firstRecorder.RegisterUsage(firstComponent);
|
||||
secondRecorder.RegisterUsage(secondComponent);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var actualComponent = results.ComponentsFound.Single();
|
||||
|
||||
|
@ -552,7 +553,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_RootsAreMergedWhenSameComponentInDifferentFiles()
|
||||
public async Task VerifyTranslation_RootsAreMergedWhenSameComponentInDifferentFiles()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -577,7 +578,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
secondRecorder.RegisterUsage(root2, isExplicitReferencedDependency: true);
|
||||
secondRecorder.RegisterUsage(secondComponent, parentComponentId: root2.Component.Id);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
|
||||
var actualComponent = results.ComponentsFound.First(c => c.Component.Id == firstComponent.Component.Id);
|
||||
actualComponent.TopLevelReferrers.Count().Should().Be(2);
|
||||
|
@ -590,7 +591,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void VerifyTranslation_DetectedComponentExist_UpdateFunctionIsApplied()
|
||||
public async Task VerifyTranslation_DetectedComponentExist_UpdateFunctionIsApplied()
|
||||
{
|
||||
var componentRecorder = new ComponentRecorder();
|
||||
var npmDetector = new NpmComponentDetectorWithRoots();
|
||||
|
@ -605,16 +606,16 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
|
||||
singleFileComponentRecorder.RegisterUsage(detectedComponent, isDevelopmentDependency: true);
|
||||
|
||||
var results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
var results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
results.ComponentsFound.Single(component => component.Component.Id == detectedComponent.Component.Id).IsDevelopmentDependency.Should().BeTrue();
|
||||
|
||||
singleFileComponentRecorder.RegisterUsage(detectedComponent, isDevelopmentDependency: false);
|
||||
|
||||
results = this.SetupRecorderBasedScanning(args, new List<ComponentRecorder> { componentRecorder });
|
||||
results = await this.SetupRecorderBasedScanningAsync(args, new List<ComponentRecorder> { componentRecorder });
|
||||
results.ComponentsFound.Single(component => component.Component.Id == detectedComponent.Component.Id).IsDevelopmentDependency.Should().BeFalse();
|
||||
}
|
||||
|
||||
private TestOutput DetectComponentsHappyPath(
|
||||
private async Task<TestOutput> DetectComponentsHappyPathAsync(
|
||||
BcdeArguments args,
|
||||
Action<DetectorRestrictions> restrictionAsserter = null,
|
||||
IEnumerable<ComponentRecorder> componentRecorders = null)
|
||||
|
@ -663,7 +664,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
Match.Create<DetectorRestrictions>(restriction => true)))
|
||||
.ReturnsAsync(processingResult);
|
||||
|
||||
var result = this.serviceUnderTest.ExecuteScanAsync(args).Result;
|
||||
var result = await this.serviceUnderTest.ExecuteScanAsync(args);
|
||||
result.ResultCode.Should().Be(ProcessingResultCode.Success);
|
||||
result.SourceDirectory.Should().NotBeNull();
|
||||
result.SourceDirectory.Should().Be(args.SourceDirectorySerialized);
|
||||
|
@ -673,7 +674,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
return testOutput;
|
||||
}
|
||||
|
||||
private ScanResult SetupRecorderBasedScanning(
|
||||
private async Task<ScanResult> SetupRecorderBasedScanningAsync(
|
||||
BcdeArguments args,
|
||||
IEnumerable<ComponentRecorder> componentRecorders)
|
||||
{
|
||||
|
@ -719,7 +720,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
Match.Create<DetectorRestrictions>(restriction => true)))
|
||||
.ReturnsAsync(processingResult);
|
||||
|
||||
var result = this.serviceUnderTest.ExecuteScanAsync(args).Result;
|
||||
var result = await this.serviceUnderTest.ExecuteScanAsync(args);
|
||||
result.ResultCode.Should().Be(ProcessingResultCode.Success);
|
||||
result.SourceDirectory.Should().NotBeNull();
|
||||
result.SourceDirectory.Should().Be(args.SourceDirectorySerialized);
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading.Tasks;
|
||||
using FluentAssertions;
|
||||
using Microsoft.ComponentDetection.Common;
|
||||
using Microsoft.ComponentDetection.Common.Telemetry.Records;
|
||||
|
@ -84,14 +86,14 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_HappyPathReturnsDetectedComponents()
|
||||
public async Task ProcessDetectorsAsync_HappyPathReturnsDetectedComponents()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
{
|
||||
this.firstFileComponentDetectorMock.Object, this.secondFileComponentDetectorMock.Object,
|
||||
};
|
||||
|
||||
var results = this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()).Result;
|
||||
var results = await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
this.firstFileComponentDetectorMock.Verify(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory)));
|
||||
this.secondFileComponentDetectorMock.Verify(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory)));
|
||||
|
@ -106,7 +108,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_NullDetectedComponentsReturnIsCoalesced()
|
||||
public async Task ProcessDetectorsAsync_NullDetectedComponentsReturnIsCoalesced()
|
||||
{
|
||||
var mockComponentDetector = new Mock<IComponentDetector>();
|
||||
mockComponentDetector.Setup(d => d.Id).Returns("test");
|
||||
|
@ -123,20 +125,20 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
});
|
||||
|
||||
this.detectorsToUse = new[] { mockComponentDetector.Object };
|
||||
var results = this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()).Result;
|
||||
var results = await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
results.ResultCode.Should().Be(ProcessingResultCode.Success);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_HappyPathReturns_DependencyGraph()
|
||||
public async Task ProcessDetectorsAsync_HappyPathReturns_DependencyGraph()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
{
|
||||
this.firstFileComponentDetectorMock.Object, this.secondFileComponentDetectorMock.Object,
|
||||
};
|
||||
|
||||
var results = this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()).Result;
|
||||
var results = await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
this.firstFileComponentDetectorMock.Verify(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory)));
|
||||
this.secondFileComponentDetectorMock.Verify(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory)));
|
||||
|
@ -162,9 +164,9 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
this.firstFileComponentDetectorMock.Object, this.secondFileComponentDetectorMock.Object,
|
||||
};
|
||||
|
||||
var records = TelemetryHelper.ExecuteWhileCapturingTelemetry<DetectorExecutionTelemetryRecord>(() =>
|
||||
var records = TelemetryHelper.ExecuteWhileCapturingTelemetry<DetectorExecutionTelemetryRecord>(async () =>
|
||||
{
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()).Wait();
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());
|
||||
});
|
||||
|
||||
foreach (var record in records)
|
||||
|
@ -175,6 +177,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Need to Wait for Async lambda to execute.")]
|
||||
public void ProcessDetectorsAsync_ExperimentalDetectorsDoNotReturnComponents()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
|
@ -212,6 +215,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Need to Wait for Async lambda to execute.")]
|
||||
public void ProcessDetectorsAsync_ExperimentalDetectorsDoNormalStuffIfExplicitlyEnabled()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
|
@ -240,6 +244,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Need to Wait for Async lambda to execute.")]
|
||||
public void ProcessDetectorsAsync_ExperimentalDetectorsThrowingDoesntKillDetection()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
|
@ -273,7 +278,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_DirectoryExclusionPredicateWorksAsExpected()
|
||||
public async Task ProcessDetectorsAsync_DirectoryExclusionPredicateWorksAsExpected()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
{
|
||||
|
@ -293,7 +298,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
.ReturnsAsync(this.ExpectedResultForDetector(this.firstFileComponentDetectorMock.Object.Id))
|
||||
.Callback<ScanRequest>(request => capturedRequest = request);
|
||||
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions()).Wait();
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
this.directoryWalkerFactory.Reset();
|
||||
|
||||
|
@ -309,7 +314,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
};
|
||||
|
||||
// Now exercise the exclusion code
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(argsWithExclusion, this.detectorsToUse, new DetectorRestrictions()).Wait();
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(argsWithExclusion, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
this.directoryWalkerFactory.Reset();
|
||||
|
||||
|
@ -381,7 +386,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_DirectoryExclusionPredicateWorksAsExpectedForObsolete()
|
||||
public async Task ProcessDetectorsAsync_DirectoryExclusionPredicateWorksAsExpectedForObsolete()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
{
|
||||
|
@ -409,7 +414,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
.ReturnsAsync(this.ExpectedResultForDetector(this.firstFileComponentDetectorMock.Object.Id))
|
||||
.Callback<ScanRequest>(request => capturedRequest = request);
|
||||
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(args, this.detectorsToUse, new DetectorRestrictions()).Wait();
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(args, this.detectorsToUse, new DetectorRestrictions());
|
||||
|
||||
this.directoryWalkerFactory.Reset();
|
||||
|
||||
|
@ -419,10 +424,10 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
|
||||
// Now exercise the exclusion code
|
||||
args.DirectoryExclusionListObsolete = new[] { Path.Combine("Child"), Path.Combine("..", "bin") };
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(
|
||||
args,
|
||||
new[] { this.firstFileComponentDetectorMock.Object },
|
||||
new DetectorRestrictions()).Wait();
|
||||
new DetectorRestrictions());
|
||||
|
||||
this.directoryWalkerFactory.Reset();
|
||||
|
||||
|
@ -434,6 +439,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
capturedRequest.DirectoryExclusionPredicate(d3.Name.AsSpan(), d3.Parent.FullName.AsSpan()).Should().BeFalse();
|
||||
}
|
||||
|
||||
[SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Need to Wait for Async lambda to execute.")]
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_CapturesTelemetry()
|
||||
{
|
||||
|
@ -464,6 +470,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
[SuppressMessage("Usage", "VSTHRD002:Avoid problematic synchronous waits", Justification = "Need to Wait for Async lambda to execute.")]
|
||||
public void ProcessDetectorsAsync_ExecutesMixedCommandAndFileDetectors()
|
||||
{
|
||||
this.detectorsToUse = new[]
|
||||
|
@ -496,7 +503,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
}
|
||||
|
||||
[TestMethod]
|
||||
public void ProcessDetectorsAsync_HandlesDetectorArgs()
|
||||
public async Task ProcessDetectorsAsync_HandlesDetectorArgs()
|
||||
{
|
||||
ScanRequest capturedRequest = null;
|
||||
this.firstFileComponentDetectorMock.Setup(x => x.ExecuteDetectorAsync(It.IsAny<ScanRequest>()))
|
||||
|
@ -506,7 +513,7 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
var args = DefaultArgs;
|
||||
args.DetectorArgs = new string[] { "arg1=val1", "arg2", "arg3=val3" };
|
||||
|
||||
this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, new[] { this.firstFileComponentDetectorMock.Object }, new DetectorRestrictions()).Wait();
|
||||
await this.serviceUnderTest.ProcessDetectorsAsync(DefaultArgs, new[] { this.firstFileComponentDetectorMock.Object }, new DetectorRestrictions());
|
||||
|
||||
capturedRequest.DetectorArgs
|
||||
.Should().Contain("arg1", "val1")
|
||||
|
@ -525,10 +532,10 @@ namespace Microsoft.ComponentDetection.Orchestrator.Tests.Services
|
|||
|
||||
var expectedResult = this.ExpectedResultForDetector(id);
|
||||
|
||||
mockFileDetector.Setup(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory && request.ComponentRecorder != null))).ReturnsAsync(
|
||||
mockFileDetector.Setup(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory && request.ComponentRecorder != null))).Returns(
|
||||
(ScanRequest request) =>
|
||||
{
|
||||
return mockFileDetector.Object.ExecuteDetectorAsync(request).Result;
|
||||
return mockFileDetector.Object.ExecuteDetectorAsync(request);
|
||||
}).Verifiable();
|
||||
mockFileDetector.Setup(x => x.ExecuteDetectorAsync(It.Is<ScanRequest>(request => request.SourceDirectory == DefaultArgs.SourceDirectory && request.ComponentRecorder != null))).ReturnsAsync(
|
||||
(ScanRequest request) =>
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace Microsoft.ComponentDetection.TestsUtilities
|
|||
|
||||
private T detector;
|
||||
|
||||
public async Task<(IndividualDetectorScanResult, IComponentRecorder)> ExecuteDetector()
|
||||
public async Task<(IndividualDetectorScanResult ScanResult, IComponentRecorder ComponentRecorder)> ExecuteDetector()
|
||||
{
|
||||
if (this.scanRequest == null)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче