Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@

<!-- Polyfill config -->
<PropertyGroup>
<PolyEnsure>true</PolyEnsure>
<!-- PolyGuard is temporary until the binary compat with VSTestBridge
https://github.com/microsoft/testfx/pull/7064#issuecomment-3623472023
https://github.com/microsoft/testfx/pull/6977 -->
<PolyGuard>true</PolyGuard>
<PolyStringInterpolation>true</PolyStringInterpolation>
<PolyUseEmbeddedAttribute>true</PolyUseEmbeddedAttribute>
Expand Down
2 changes: 1 addition & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
<PackageVersion Include="Microsoft.Win32.Registry" Version="5.0.0" />
<PackageVersion Include="Microsoft.WindowsAppSDK" Version="1.8.251003001" />
<PackageVersion Include="OpenTelemetry" Version="1.14.0" />
<PackageVersion Include="Polyfill" Version="9.0.0-beta.19" />
<PackageVersion Include="Polyfill" Version="9.7.0" />
<PackageVersion Include="System.Threading.Tasks.Extensions" Version="$(SystemThreadingTasksExtensionsVersion)" />
</ItemGroup>
<ItemGroup Label="Test dependencies">
Expand Down
4 changes: 2 additions & 2 deletions src/Adapter/MSTest.Engine/Engine/TestFixtureManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void TryRegisterFixture<TFixture>(string fixtureId, Func<Task<TFixture>>
public async Task<TFixture> GetFixtureAsync<TFixture>(string fixtureId)
where TFixture : notnull
{
Guard.NotNullOrWhiteSpace(fixtureId);
Ensure.NotNullOrWhiteSpace(fixtureId);
if (!_fixtureInstancesByFixtureId.TryGetValue(fixtureId, out Dictionary<Type, AsyncLazy<object>>? fixtureInstancesPerType))
{
throw new InvalidOperationException($"Fixture with ID '{fixtureId}' is not registered");
Expand Down Expand Up @@ -148,7 +148,7 @@ internal async Task CleanUnusedFixturesAsync(TestNode testNode)
private void TryRegisterFixture<TFixture>(string fixtureId, Func<Task<TFixture>> asyncFactory, Action onTypeExist)
where TFixture : notnull
{
Guard.NotNullOrWhiteSpace(fixtureId);
Ensure.NotNullOrWhiteSpace(fixtureId);

if (_isRegistrationFrozen)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ public static void AddTestFramework(
TestFrameworkConfiguration? testFrameworkConfiguration = null,
params ITestNodesBuilder[] testNodesBuilder)
{
Guard.NotNull(testApplicationBuilder);
Guard.NotNull(testNodesBuilder);
Ensure.NotNull(testApplicationBuilder);
Ensure.NotNull(testNodesBuilder);
ArgumentGuard.Ensure(testNodesBuilder.Length != 0, nameof(testNodesBuilder),
"At least one test node builder must be provided.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discove

internal void DiscoverTests(IEnumerable<string> sources, IDiscoveryContext discoveryContext, IMessageLogger logger, ITestCaseDiscoverySink discoverySink, IConfiguration? configuration)
{
Guard.NotNull(sources);
Guard.NotNull(logger);
Guard.NotNull(discoverySink);
Ensure.NotNull(sources);
Ensure.NotNull(logger);
Ensure.NotNull(discoverySink);

if (MSTestDiscovererHelpers.InitializeDiscovery(sources, discoveryContext, logger, configuration, _testSourceHandler))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ public void RunTests(IEnumerable<string>? sources, IRunContext? runContext, IFra
internal async Task RunTestsAsync(IEnumerable<TestCase>? tests, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from testcases.");
Guard.NotNull(frameworkHandle);
Guard.NotNullOrEmpty(tests);
Ensure.NotNull(frameworkHandle);
Ensure.NotNullOrEmpty(tests);

if (!MSTestDiscovererHelpers.InitializeDiscovery(from test in tests select test.Source, runContext, frameworkHandle, configuration, new TestSourceHandler()))
{
Expand All @@ -100,8 +100,8 @@ internal async Task RunTestsAsync(IEnumerable<TestCase>? tests, IRunContext? run
internal async Task RunTestsAsync(IEnumerable<string>? sources, IRunContext? runContext, IFrameworkHandle? frameworkHandle, IConfiguration? configuration)
{
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo("MSTestExecutor.RunTests: Running tests from sources.");
Guard.NotNull(frameworkHandle);
Guard.NotNullOrEmpty(sources);
Ensure.NotNull(frameworkHandle);
Ensure.NotNullOrEmpty(sources);

TestSourceHandler testSourceHandler = new();
if (!MSTestDiscovererHelpers.InitializeDiscovery(sources, runContext, frameworkHandle, configuration, testSourceHandler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class AssemblyResolver :
/// </remarks>
public AssemblyResolver(IList<string> directories)
{
Guard.NotNullOrEmpty(directories);
Ensure.NotNullOrEmpty(directories);

_searchDirectories = [.. directories];
_directoryList = new Queue<RecursiveDirectoryPath>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ public IEnumerable<TestAssemblyInfo> AssemblyInfoListWithExecutableCleanupMethod
/// <returns> The <see cref="TestMethodInfo"/>. </returns>
public TestMethodInfo? GetTestMethodInfo(TestMethod testMethod, ITestContext testContext)
{
Guard.NotNull(testMethod);
Guard.NotNull(testContext);
Ensure.NotNull(testMethod);
Ensure.NotNull(testContext);

// Get the classInfo (This may throw as GetType calls assembly.GetType(..,true);)
TestClassInfo? testClassInfo = GetClassInfo(testMethod);
Expand All @@ -105,7 +105,7 @@ public IEnumerable<TestAssemblyInfo> AssemblyInfoListWithExecutableCleanupMethod
/// <returns> The <see cref="TestMethodInfo"/>. </returns>
public DiscoveryTestMethodInfo? GetTestMethodInfoForDiscovery(TestMethod testMethod)
{
Guard.NotNull(testMethod);
Ensure.NotNull(testMethod);

// Get the classInfo (This may throw as GetType calls assembly.GetType(..,true);)
TestClassInfo? testClassInfo = GetClassInfo(testMethod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ internal TestResult[] RunSingleTest(TestMethod testMethod, IDictionary<string, o
/// <returns> The <see cref="TestResult"/>. </returns>
internal async Task<TestResult[]> RunSingleTestAsync(TestMethod testMethod, IDictionary<string, object?> testContextProperties, IMessageLogger messageLogger)
{
Guard.NotNull(testMethod);
Guard.NotNull(testContextProperties);
Ensure.NotNull(testMethod);
Ensure.NotNull(testContextProperties);

ITestContext? testContextForTestExecution = null;
ITestContext? testContextForAssemblyInit = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal class ReflectHelper : MarshalByRefObject
public virtual /* for testing */ bool IsAttributeDefined<TAttribute>(MemberInfo memberInfo)
where TAttribute : Attribute
{
Guard.NotNull(memberInfo);
Ensure.NotNull(memberInfo);

// Get all attributes on the member.
Attribute[] attributes = GetCustomAttributesCached(memberInfo);
Expand Down Expand Up @@ -95,8 +95,8 @@ internal class ReflectHelper : MarshalByRefObject
/// <returns>True if there is a match.</returns>
internal static bool MatchReturnType(MethodInfo method, Type returnType)
{
Guard.NotNull(method);
Guard.NotNull(returnType);
Ensure.NotNull(method);
Ensure.NotNull(returnType);
return method.ReturnType.Equals(returnType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ internal static void Reset()
/// <returns>An instance of the <see cref="MSTestSettings"/> class.</returns>
private static MSTestSettings ToSettings(XmlReader reader, IMessageLogger? logger)
{
Guard.NotNull(reader);
Ensure.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ internal TestMethod(
string? displayName,
string? parameterTypes)
{
Guard.NotNullOrWhiteSpace(assemblyName);
Ensure.NotNullOrWhiteSpace(assemblyName);

Name = name;
DisplayName = displayName ?? name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class UnitTestElement
/// <exception cref="ArgumentNullException"> Thrown when method is null. </exception>
public UnitTestElement(TestMethod testMethod)
{
Guard.NotNull(testMethod);
Ensure.NotNull(testMethod);

DebugEx.Assert(testMethod.FullClassName != null, "Full className cannot be empty");
TestMethod = testMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public static RunConfigurationSettings PopulateSettings([StringSyntax(StringSynt
/// <returns>An instance of the <see cref="MSTestSettings"/> class.</returns>
private static RunConfigurationSettings ToSettings(XmlReader reader)
{
Guard.NotNull(reader);
Ensure.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public MSTestAdapterSettings()
/// <returns>An instance of the <see cref="MSTestAdapterSettings"/> class.</returns>
public static MSTestAdapterSettings ToSettings(XmlReader reader)
{
Guard.NotNull(reader);
Ensure.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down Expand Up @@ -342,7 +342,7 @@ public List<RecursiveDirectoryPath> GetDirectoryListWithRecursiveProperty(string

private void ReadAssemblyResolutionPath(XmlReader reader)
{
Guard.NotNull(reader);
Ensure.NotNull(reader);

// Expected format of the xml is: -
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ internal static void Load(IConfiguration configuration)
public void Load(XmlReader reader)
{
#if !WINDOWS_UWP
Guard.NotNull(reader);
Ensure.NotNull(reader);
var settings = MSTestAdapterSettings.ToSettings(reader);
if (!ReferenceEquals(settings, Settings))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ public static string GetTestResultsDirectory(IRunContext? runContext) => !String
/// <returns>Returns a list of deployment warnings.</returns>
protected IEnumerable<string> Deploy(IList<DeploymentItem> deploymentItems, string testSourceHandler, string deploymentDirectory, string resultsDirectory)
{
Guard.NotNullOrWhiteSpace(deploymentDirectory);
Guard.NotNullOrWhiteSpace(testSourceHandler);
Ensure.NotNullOrWhiteSpace(deploymentDirectory);
Ensure.NotNullOrWhiteSpace(testSourceHandler);
ApplicationStateGuard.Ensure(FileUtility.DoesDirectoryExist(deploymentDirectory), $"Deployment directory {deploymentDirectory} does not exist");
ApplicationStateGuard.Ensure(FileUtility.DoesFileExist(testSourceHandler), $"TestSource {testSourceHandler} does not exist.");

Expand All @@ -153,7 +153,7 @@ protected IEnumerable<string> Deploy(IList<DeploymentItem> deploymentItems, stri
// Copy the deployment items. (As deployment item can correspond to directories as well, so each deployment item may map to n files)
foreach (DeploymentItem deploymentItem in deploymentItems)
{
Guard.NotNull(deploymentItem);
Ensure.NotNull(deploymentItem);

// Validate the output directory.
if (!IsOutputDirectoryValid(deploymentItem, deploymentDirectory, warnings))
Expand Down Expand Up @@ -411,7 +411,7 @@ private static void LogWarnings(ITestExecutionRecorder testExecutionRecorder, IE

private bool Deploy(string source, IRunContext? runContext, ITestExecutionRecorder testExecutionRecorder, IList<DeploymentItem> deploymentItems, TestRunDirectories runDirectories)
{
Guard.NotNull(runDirectories);
Ensure.NotNull(runDirectories);
if (EqtTrace.IsInfoEnabled)
{
EqtTrace.Info("MSTestExecutor: Found that deployment items for source {0} are: ", source);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public static string TryConvertPathToRelative(string path, string rootDir)
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")]
public virtual void DeleteDirectories(string filePath)
{
Guard.NotNullOrWhiteSpace(filePath);
Ensure.NotNullOrWhiteSpace(filePath);
try
{
var root = new DirectoryInfo(filePath);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ private static void AddAssemblyBindingRedirect(
string fromVersion,
string toVersion)
{
Guard.NotNull(assemblyName);
Ensure.NotNull(assemblyName);

// Convert the public key token into a string.
StringBuilder? publicKeyTokenString = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ internal static Document ApplyFix(
}
else
{
Guard.NotNull(testContextMemberName);
Ensure.NotNull(testContextMemberName);
AddCancellationTokenArgument(editor, invocationExpression, testContextMemberName, cancellationTokenParameterName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public async Task BeforeRunAsync(CancellationToken cancellationToken)

ILogger<RetryLifecycleCallbacks> logger = _serviceProvider.GetLoggerFactory().CreateLogger<RetryLifecycleCallbacks>();

Guard.NotNull(pipeName);
Ensure.NotNull(pipeName);
ArgumentGuard.Ensure(pipeName.Length == 1, nameof(pipeName), "Pipe name expected");
logger.LogDebug($"Connecting to pipe '{pipeName[0]}'");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ internal Condition(string name, Operation operation, string value)
/// </summary>
internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
Guard.NotNull(propertyValueProvider);
Ensure.NotNull(propertyValueProvider);
bool result = false;
string[]? multiValue = GetPropertyValue(propertyValueProvider);
switch (Operation)
Expand Down Expand Up @@ -272,7 +272,7 @@ private bool ValidForContainsOperation(Func<string, TestProperty?>? propertyProv

internal static IEnumerable<string> TokenizeFilterConditionString(string str)
{
return TokenizeFilterConditionStringWorker(Guard.NotNull(str));
return TokenizeFilterConditionStringWorker(Ensure.NotNull(str));

static IEnumerable<string> TokenizeFilterConditionStringWorker(string s)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal sealed class FastFilter
{
internal FastFilter(ImmutableDictionary<string, ISet<string>> filterProperties, Operation filterOperation, Operator filterOperator)
{
Guard.NotNullOrEmpty(filterProperties);
Ensure.NotNullOrEmpty(filterProperties);

FilterProperties = filterProperties;

Expand Down Expand Up @@ -41,7 +41,7 @@ internal FastFilter(ImmutableDictionary<string, ISet<string>> filterProperties,

internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
Guard.NotNull(propertyValueProvider);
Ensure.NotNull(propertyValueProvider);

bool matched = false;
foreach (string name in FilterProperties.Keys)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ internal sealed partial class FilterExpression

private FilterExpression(FilterExpression left, FilterExpression right, bool areJoinedByAnd)
{
Guard.NotNull(left);
Guard.NotNull(right);
Ensure.NotNull(left);
Ensure.NotNull(right);
_left = left;
_right = right;
_areJoinedByAnd = areJoinedByAnd;
}

private FilterExpression(Condition condition)
{
Guard.NotNull(condition);
Ensure.NotNull(condition);
_condition = condition;
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private static void ProcessOperator(Stack<FilterExpression> filterStack, Operato
/// </summary>
internal static FilterExpression Parse(string filterString, out FastFilter? fastFilter)
{
Guard.NotNull(filterString);
Ensure.NotNull(filterString);

// Below parsing doesn't error out on pattern (), so explicitly search for that (empty parenthesis).
Match invalidInput = GetEmptyParenthesisPattern().Match(filterString);
Expand Down Expand Up @@ -312,7 +312,7 @@ private T IterateFilterExpression<T>(Func<FilterExpression, Stack<T>, T> getNode
/// <returns> True if evaluation is successful. </returns>
internal bool Evaluate(Func<string, object?> propertyValueProvider)
{
Guard.NotNull(propertyValueProvider);
Ensure.NotNull(propertyValueProvider);

return IterateFilterExpression<bool>((current, result) =>
{
Expand All @@ -335,7 +335,7 @@ internal bool Evaluate(Func<string, object?> propertyValueProvider)

internal static IEnumerable<string> TokenizeFilterExpressionString(string str)
{
Guard.NotNull(str);
Ensure.NotNull(str);
return TokenizeFilterExpressionStringHelper(str);

static IEnumerable<string> TokenizeFilterExpressionStringHelper(string s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal sealed class FilterExpressionWrapper
/// </summary>
public FilterExpressionWrapper(string filterString, FilterOptions? options)
{
Guard.NotNullOrEmpty(filterString);
Ensure.NotNullOrEmpty(filterString);

FilterString = filterString;
FilterOptions = options;
Expand Down Expand Up @@ -109,7 +109,7 @@ public FilterExpressionWrapper(string filterString)
/// </summary>
public bool Evaluate(Func<string, object?> propertyValueProvider)
{
Guard.NotNull(propertyValueProvider);
Ensure.NotNull(propertyValueProvider);

return UseFastFilter
? _fastFilter.Evaluate(propertyValueProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal sealed class TestCaseFilterExpression : ITestCaseFilterExpression
/// </summary>
public TestCaseFilterExpression(FilterExpressionWrapper filterWrapper)
{
Guard.NotNull(filterWrapper);
Ensure.NotNull(filterWrapper);
_filterWrapper = filterWrapper;
_validForMatch = RoslynString.IsNullOrEmpty(filterWrapper.ParseError);
}
Expand Down Expand Up @@ -56,8 +56,8 @@ public TestCaseFilterExpression(FilterExpressionWrapper filterWrapper)
/// </summary>
public bool MatchTestCase(TestCase testCase, Func<string, object?> propertyValueProvider)
{
Guard.NotNull(testCase);
Guard.NotNull(propertyValueProvider);
Ensure.NotNull(testCase);
Ensure.NotNull(propertyValueProvider);

return _validForMatch && _filterWrapper.Evaluate(propertyValueProvider);
}
Expand Down
Loading
Loading