Skip to content
Draft
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: 0 additions & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@
<NewtonsoftJsonVersion>13.0.3</NewtonsoftJsonVersion>
<NewtonsoftJsonBsonVersion>1.0.2</NewtonsoftJsonBsonVersion>
<MoqVersion>4.18.4</MoqVersion>
<AwesomeAssertionsVersion>8.0.2</AwesomeAssertionsVersion>
<FsCheckVersion>2.14.3</FsCheckVersion>
<CommandLineParserVersion>2.9.1</CommandLineParserVersion>
<CompilerPlatformTestingVersion>1.1.3-beta1.24423.1</CompilerPlatformTestingVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using FluentAssertions;
using FluentAssertions.Execution;
using System;
using System.Collections.Generic;
using System.IO;
using Xunit;

namespace Microsoft.DotNet.CoreSetup.Test.HostActivation.DependencyResolution
{
Expand All @@ -16,64 +15,62 @@ public static class DependencyResolutionCommandResultExtensions
private const string NATIVE_DLL_SEARCH_DIRECTORIES = nameof(NATIVE_DLL_SEARCH_DIRECTORIES);
private const string PLATFORM_RESOURCE_ROOTS = nameof(PLATFORM_RESOURCE_ROOTS);

public static AndConstraint<CommandResultAssertions> HaveRuntimePropertyContaining(this CommandResultAssertions assertion, string propertyName, params string[] values)
public static CommandResultAssertions HaveRuntimePropertyContaining(this CommandResultAssertions assertion, string propertyName, params string[] values)
{
string propertyValue = GetAppMockPropertyValue(assertion, propertyName);
AssertionChain assertionChain = AssertionChain.GetOrCreate();

foreach (string value in values)
{
assertionChain.ForCondition(propertyValue != null && propertyValue.Contains(value))
.FailWith($"The property {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
Assert.True(propertyValue is not null && propertyValue.Contains(value),
$"The property {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}

return new AndConstraint<CommandResultAssertions>(assertion);
return assertion;
}

public static AndConstraint<CommandResultAssertions> NotHaveRuntimePropertyContaining(this CommandResultAssertions assertion, string propertyName, params string[] values)
public static CommandResultAssertions NotHaveRuntimePropertyContaining(this CommandResultAssertions assertion, string propertyName, params string[] values)
{
string propertyValue = GetAppMockPropertyValue(assertion, propertyName);
AssertionChain assertionChain = AssertionChain.GetOrCreate();

foreach (string value in values)
{
assertionChain.ForCondition(propertyValue != null && !propertyValue.Contains(value))
.FailWith($"The property {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
Assert.True(propertyValue is not null && !propertyValue.Contains(value),
$"The property {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}

return new AndConstraint<CommandResultAssertions>(assertion);
return assertion;
}

public static AndConstraint<CommandResultAssertions> HaveResolvedAssembly(this CommandResultAssertions assertion, string assemblyPath, TestApp app = null)
public static CommandResultAssertions HaveResolvedAssembly(this CommandResultAssertions assertion, string assemblyPath, TestApp app = null)
{
return assertion.HaveRuntimePropertyContaining(TRUSTED_PLATFORM_ASSEMBLIES, RelativePathsToAbsoluteAppPaths(assemblyPath, app));
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedAssembly(this CommandResultAssertions assertion, string assemblyPath, TestApp app = null)
public static CommandResultAssertions NotHaveResolvedAssembly(this CommandResultAssertions assertion, string assemblyPath, TestApp app = null)
{
return assertion.NotHaveRuntimePropertyContaining(TRUSTED_PLATFORM_ASSEMBLIES, RelativePathsToAbsoluteAppPaths(assemblyPath, app));
}

public static AndConstraint<CommandResultAssertions> HaveResolvedNativeLibraryPath(this CommandResultAssertions assertion, string path, TestApp app = null)
public static CommandResultAssertions HaveResolvedNativeLibraryPath(this CommandResultAssertions assertion, string path, TestApp app = null)
{
return assertion.HaveRuntimePropertyContaining(NATIVE_DLL_SEARCH_DIRECTORIES, RelativePathsToAbsoluteAppPaths(path, app));
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedNativeLibraryPath(this CommandResultAssertions assertion, string path, TestApp app = null)
public static CommandResultAssertions NotHaveResolvedNativeLibraryPath(this CommandResultAssertions assertion, string path, TestApp app = null)
{
return assertion.NotHaveRuntimePropertyContaining(NATIVE_DLL_SEARCH_DIRECTORIES, RelativePathsToAbsoluteAppPaths(path, app));
}

public static AndConstraint<CommandResultAssertions> HaveResolvedResourceRootPath(this CommandResultAssertions assertion, string path, TestApp app = null)
public static CommandResultAssertions HaveResolvedResourceRootPath(this CommandResultAssertions assertion, string path, TestApp app = null)
{
return assertion.HaveRuntimePropertyContaining(PLATFORM_RESOURCE_ROOTS, RelativePathsToAbsoluteAppPaths(path, app));
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedResourceRootPath(this CommandResultAssertions assertion, string path, TestApp app = null)
public static CommandResultAssertions NotHaveResolvedResourceRootPath(this CommandResultAssertions assertion, string path, TestApp app = null)
{
return assertion.NotHaveRuntimePropertyContaining(PLATFORM_RESOURCE_ROOTS, RelativePathsToAbsoluteAppPaths(path, app));
}
Expand All @@ -82,82 +79,80 @@ public static AndConstraint<CommandResultAssertions> NotHaveResolvedResourceRoot
private const string assemblies = "assemblies";
private const string native_search_paths = "native_search_paths";

public static AndConstraint<CommandResultAssertions> HaveSuccessfullyResolvedComponentDependencies(this CommandResultAssertions assertion)
public static CommandResultAssertions HaveSuccessfullyResolvedComponentDependencies(this CommandResultAssertions assertion)
{
return assertion.HaveStdOutContaining("corehost_resolve_component_dependencies:Success");
}

public static AndConstraint<CommandResultAssertions> HaveResolvedComponentDependencyContaining(
public static CommandResultAssertions HaveResolvedComponentDependencyContaining(
this CommandResultAssertions assertion,
string propertyName,
params string[] values)
{
string propertyValue = GetComponentMockPropertyValue(assertion, propertyName);
AssertionChain assertionChain = AssertionChain.GetOrCreate();

foreach (string value in values)
{
assertionChain.ForCondition(propertyValue != null && propertyValue.Contains(value))
.FailWith($"The resolved {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
Assert.True(propertyValue is not null && propertyValue.Contains(value),
$"The resolved {propertyName} doesn't contain expected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}

return new AndConstraint<CommandResultAssertions>(assertion);
return assertion;
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedComponentDependencyContaining(
public static CommandResultAssertions NotHaveResolvedComponentDependencyContaining(
this CommandResultAssertions assertion,
string propertyName,
params string[] values)
{
string propertyValue = GetComponentMockPropertyValue(assertion, propertyName);
AssertionChain assertionChain = AssertionChain.GetOrCreate();

foreach (string value in values)
{
assertionChain.ForCondition(propertyValue != null && !propertyValue.Contains(value))
.FailWith($"The resolved {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
Assert.True(propertyValue is not null && !propertyValue.Contains(value),
$"The resolved {propertyName} contains unexpected value: '{value}'{Environment.NewLine}" +
$"{propertyName}='{propertyValue}'" +
$"{assertion.GetDiagnosticsInfo()}");
}

return new AndConstraint<CommandResultAssertions>(assertion);
return assertion;
}

public static AndConstraint<CommandResultAssertions> HaveResolvedComponentDependencyAssembly(
public static CommandResultAssertions HaveResolvedComponentDependencyAssembly(
this CommandResultAssertions assertion,
string assemblyPath,
TestApp app = null)
{
return assertion.HaveResolvedComponentDependencyContaining(assemblies, RelativePathsToAbsoluteAppPaths(assemblyPath, app));
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedComponentDependencyAssembly(
public static CommandResultAssertions NotHaveResolvedComponentDependencyAssembly(
this CommandResultAssertions assertion,
string assemblyPath,
TestApp app = null)
{
return assertion.NotHaveResolvedComponentDependencyContaining(assemblies, RelativePathsToAbsoluteAppPaths(assemblyPath, app));
}

public static AndConstraint<CommandResultAssertions> HaveResolvedComponentDependencyNativeLibraryPath(
public static CommandResultAssertions HaveResolvedComponentDependencyNativeLibraryPath(
this CommandResultAssertions assertion,
string path,
TestApp app = null)
{
return assertion.HaveResolvedComponentDependencyContaining(native_search_paths, RelativePathsToAbsoluteAppPaths(path, app));
}

public static AndConstraint<CommandResultAssertions> NotHaveResolvedComponentDependencyNativeLibraryPath(
public static CommandResultAssertions NotHaveResolvedComponentDependencyNativeLibraryPath(
this CommandResultAssertions assertion,
string path,
TestApp app = null)
{
return assertion.NotHaveResolvedComponentDependencyContaining(native_search_paths, RelativePathsToAbsoluteAppPaths(path, app));
}

public static AndConstraint<CommandResultAssertions> ErrorWithMissingAssembly(this CommandResultAssertions assertion, string depsFileName, string dependencyName, string dependencyVersion)
public static CommandResultAssertions ErrorWithMissingAssembly(this CommandResultAssertions assertion, string depsFileName, string dependencyName, string dependencyVersion)
{
return assertion.HaveStdErrContaining(
$"Error:{Environment.NewLine}" +
Expand All @@ -166,18 +161,18 @@ public static AndConstraint<CommandResultAssertions> ErrorWithMissingAssembly(th
$" path: \'{dependencyName}.dll\'");
}

public static AndConstraint<CommandResultAssertions> HaveUsedAdditionalDeps(this CommandResultAssertions assertion, string depsFilePath)
public static CommandResultAssertions HaveUsedAdditionalDeps(this CommandResultAssertions assertion, string depsFilePath)
{
return assertion.HaveStdErrContaining($"Using specified additional deps.json: '{depsFilePath}'");
}

public static AndConstraint<CommandResultAssertions> HaveUsedAdditionalProbingPath(this CommandResultAssertions assertion, string path)
public static CommandResultAssertions HaveUsedAdditionalProbingPath(this CommandResultAssertions assertion, string path)
{
return assertion.HaveStdErrContaining($"Additional probe dir: {path}")
.And.HaveStdErrContaining($"probe type=lookup dir=[{path}]");
}

public static AndConstraint<CommandResultAssertions> HaveReadRidGraph(this CommandResultAssertions assertion, bool readRidGraph)
public static CommandResultAssertions HaveReadRidGraph(this CommandResultAssertions assertion, bool readRidGraph)
{
string ridGraphMsg = "RID fallback graph =";
string hostRidsMsg = "Host RID list =";
Expand All @@ -186,18 +181,18 @@ public static AndConstraint<CommandResultAssertions> HaveReadRidGraph(this Comma
: assertion.HaveStdErrContaining(hostRidsMsg).And.NotHaveStdErrContaining(ridGraphMsg);
}

public static AndConstraint<CommandResultAssertions> HaveUsedFallbackRid(this CommandResultAssertions assertion, bool usedFallbackRid)
public static CommandResultAssertions HaveUsedFallbackRid(this CommandResultAssertions assertion, bool usedFallbackRid)
{
string msg = "Falling back to base HostRID";
return usedFallbackRid ? assertion.HaveStdErrContaining(msg) : assertion.NotHaveStdErrContaining(msg);
}

public static AndConstraint<CommandResultAssertions> HaveUsedFrameworkProbe(this CommandResultAssertions assertion, string path, int level)
public static CommandResultAssertions HaveUsedFrameworkProbe(this CommandResultAssertions assertion, string path, int level)
{
return assertion.HaveStdErrContaining($"probe type=framework dir=[{path}] fx_level={level}");
}

public static AndConstraint<CommandResultAssertions> NotHaveUsedFrameworkProbe(this CommandResultAssertions assertion, string path)
public static CommandResultAssertions NotHaveUsedFrameworkProbe(this CommandResultAssertions assertion, string path)
{
return assertion.NotHaveStdErrContaining($"probe type=framework dir=[{path}]");
}
Expand Down
Loading
Loading