This commit is contained in:
Amaury Levé 2023-11-29 07:42:33 +01:00 коммит произвёл GitHub
Родитель 539b0c1fcd
Коммит 3c8703ae5e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
237 изменённых файлов: 678 добавлений и 1499 удалений

Просмотреть файл

@ -65,6 +65,8 @@ csharp_using_directive_placement = outside_namespace
## License header
# IDE0073: File header
dotnet_diagnostic.IDE0073.severity = warning
file_header_template = Copyright (c) Microsoft Corporation. All rights reserved.\nLicensed under the MIT license. See LICENSE file in the project root for full license information.
## Styling conventions
@ -136,36 +138,182 @@ dotnet_style_qualification_for_field = false:warning
dotnet_style_qualification_for_method = false:warning
dotnet_style_qualification_for_property = false:warning
# IDE0019: Use pattern matching
# IDE0004: Remove unnecessary cast
dotnet_diagnostic.IDE0004.severity = warning
# IDE0005: Remove unnecessary using directives
dotnet_diagnostic.IDE0005.severity = warning
# IDE0011: Add braces
dotnet_diagnostic.IDE0011.severity = warning
# IDE0017: Simplify object initialization
dotnet_diagnostic.IDE0017.severity = warning
# IDE0018: Inline variable declaration
dotnet_diagnostic.IDE0018.severity = warning
# IDE0019: Use pattern matching to avoid 'as' followed by a 'null' check
dotnet_diagnostic.IDE0019.severity = warning
# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = warning
# IDE0020: IDE0038: Use pattern matching to avoid 'is' check followed by a cast
dotnet_diagnostic.IDE0020.severity = warning
# IDE0054: Use compound assignment
dotnet_diagnostic.IDE0054.severity = warning
# IDE0074: Use coalesce compound assignment
dotnet_diagnostic.IDE0074.severity = warning
# IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0028.severity = warning
# IDE0031: Use null propagation
dotnet_diagnostic.IDE0031.severity = warning
dotnet_style_null_propagation = true
# IDE0032: Use auto-implemented property
dotnet_diagnostic.IDE0032.severity = warning
# IDE0034: Simplify 'default' expression
dotnet_diagnostic.IDE0034.severity = warning
# IDE0035: Remove unreachable code
dotnet_diagnostic.IDE0035.severity = warning
# IDE0036: Order modifiers
dotnet_diagnostic.IDE0036.severity = warning
# IDE0039: Use local function instead of lambda
dotnet_diagnostic.IDE0039.severity = warning
# IDE0040: Add accessibility modifiers
dotnet_diagnostic.IDE0040.severity = warning
# IDE0041: Use 'is null' check
dotnet_diagnostic.IDE0041.severity = warning
# IDE0043: Format string contains invalid placeholder
dotnet_diagnostic.IDE0043.severity = warning
# IDE0044: Make field readonly
dotnet_diagnostic.IDE0044.severity = warning
# IDE0045: Use conditional expression for assignment
dotnet_diagnostic.IDE0045.severity = warning
# IDE0046: Use conditional expression for return
dotnet_diagnostic.IDE0046.severity = warning
# IDE0047: Parentheses preferences
dotnet_diagnostic.IDE0047.severity = warning
# IDE0048: Parentheses preferences
dotnet_diagnostic.IDE0048.severity = warning
# IDE0051: Remove unused private member
dotnet_diagnostic.IDE0051.severity = warning
# IDE0052: Remove unread private member
dotnet_diagnostic.IDE0052.severity = warning
# IDE0054: Use compound assignment
dotnet_diagnostic.IDE0054.severity = warning
# IDE0055: Fix formatting
dotnet_diagnostic.IDE0055.severity = warning
# IDE0056: Use index operator
dotnet_diagnostic.IDE0056.severity = suggestion
# IDE0057: Use range operator
dotnet_diagnostic.IDE0057.severity = suggestion
# IDE0059: Unnecessary assignment to a value
dotnet_diagnostic.IDE0059.severity = warning
# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning
# IDE0062: Make local function static
dotnet_diagnostic.IDE0062.severity = warning
# IDE0063: Use simple 'using' statement
dotnet_diagnostic.IDE0063.severity = warning
# IDE0065: 'using' directive placement
dotnet_diagnostic.IDE0065.severity = warning
# IDE0066: Use switch expression
dotnet_diagnostic.IDE0066.severity = warning
# IDE0071: Simplify interpolation
dotnet_diagnostic.IDE0071.severity = warning
# IDE0074: Use coalesce compound assignment
dotnet_diagnostic.IDE0074.severity = warning
# IDE0078: Use pattern matching
dotnet_diagnostic.IDE0078.severity = warning
# IDE0082: Convert typeof to nameof
dotnet_diagnostic.IDE0082.severity = warning
# IDE0083: Use pattern matching (not operator)
dotnet_diagnostic.IDE0083.severity = warning
# IDE0090: Use 'new(...)'
dotnet_diagnostic.IDE0090.severity = warning
# IDE0100: Remove unnecessary equality operator
dotnet_diagnostic.IDE0100.severity = warning
# IDE0120: Simplify LINQ expression
dotnet_diagnostic.IDE0120.severity = warning
# IDE0150: Prefer 'null' check over type check
dotnet_diagnostic.IDE0150.severity = warning
# IDE0028: Simplify collection initialization
dotnet_diagnostic.IDE0028.severity = warning
# IDE0160: IDE0161: Namespace declaration preferences
dotnet_diagnostic.IDE0161.severity = warning
# IDE0017: Simplify object initialization
dotnet_diagnostic.IDE0017.severity = warning
# IDE0170: Prefer extended property pattern
dotnet_diagnostic.IDE0170.severity = warning
# IDE0220: Add explicit cast
dotnet_diagnostic.IDE0220.severity = warning
# IDE0240: Remove redundant nullable directive
dotnet_diagnostic.IDE0240.severity = warning
# IDE0241: Remove unnecessary nullable directive
dotnet_diagnostic.IDE0241.severity = warning
dotnet_diagnostic.IDE0250.severity = warning
dotnet_diagnostic.IDE0251.severity = warning
# IDE0260: Use pattern matching
dotnet_diagnostic.IDE0260.severity = warning
dotnet_diagnostic.IDE0280.severity = warning
# IDE0270: Use coalesce expression
dotnet_diagnostic.IDE0270.severity = warning
# IDE0300: Simplify collection initialization
dotnet_style_prefer_collection_expression = false
# IDE0290: Use primary constructor
csharp_style_prefer_primary_constructors = false
# IDE1005: Use conditional delegate call
dotnet_diagnostic.IDE1005.severity = warning
# IDE1006: Naming rule violation
dotnet_diagnostic.IDE1006.severity = warning
# IDE2000: Avoid multiple blank lines
dotnet_diagnostic.IDE2000.severity = warning
dotnet_diagnostic.IDE2002.severity = warning
dotnet_diagnostic.IDE2003.severity = warning
dotnet_diagnostic.IDE2004.severity = warning
dotnet_diagnostic.IDE2005.severity = warning
dotnet_diagnostic.IDE2006.severity = warning
# CA1001: Types that own disposable fields should be disposable
dotnet_diagnostic.CA1001.severity = warning

Просмотреть файл

@ -21,15 +21,13 @@ public static class AssertEx
/// <param name="obj">The object.</param>
/// <returns>True if object is of the given type.</returns>
/// <exception cref="AssertFailedException">If object is not of the given type.</exception>
#pragma warning disable IDE0060 // Remove unused parameter
public static bool IsOfType<T>(this Assert assert, object obj)
#pragma warning restore IDE0060 // Remove unused parameter
{
if (obj is T)
{
return true;
}
throw new AssertFailedException(
string.Format(
return obj is T
? true
: throw new AssertFailedException(string.Format(
CultureInfo.InvariantCulture,
"Expected object of type {0} but found object of type {1}",
typeof(T),
@ -41,7 +39,9 @@ public static class AssertEx
/// </summary>
/// <param name="assert">The Assert class.</param>
/// <returns>The class that contains the assert methods for this grouping.</returns>
#pragma warning disable IDE0060 // Remove unused parameter
public static AssertIs Is(this Assert assert)
#pragma warning restore IDE0060 // Remove unused parameter
{
s_assertIs ??= new AssertIs();

Просмотреть файл

@ -23,12 +23,9 @@ public class AssertIs
public bool Divisor(int number, int divisor)
#pragma warning restore CA1822 // Mark members as static
{
if (number % divisor == 0)
{
return true;
}
throw new AssertFailedException(string.Format(CultureInfo.InvariantCulture, "{0} is not a divisor of {1}", divisor, number));
return number % divisor == 0
? true
: throw new AssertFailedException(string.Format(CultureInfo.InvariantCulture, "{0} is not a divisor of {1}", divisor, number));
}
/// <summary>
@ -41,11 +38,8 @@ public class AssertIs
public bool Positive(int number)
#pragma warning restore CA1822 // Mark members as static
{
if (number > 0)
{
return true;
}
throw new AssertFailedException(string.Format(CultureInfo.InvariantCulture, "{0} is not positive", number));
return number > 0
? true
: throw new AssertFailedException(string.Format(CultureInfo.InvariantCulture, "{0} is not positive", number));
}
}

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;

Просмотреть файл

@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using System.Security;
@ -14,8 +10,6 @@ using System.Text;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FrameworkITestDataSource = Microsoft.VisualStudio.TestTools.UnitTesting.ITestDataSource;
@ -278,76 +272,7 @@ internal class AssemblyEnumerator : MarshalByRefObject
var testMethod = test.TestMethod;
var testContext = PlatformServiceProvider.Instance.GetTestContext(testMethod, writer, sourceLevelParameters);
var testMethodInfo = _typeCache.GetTestMethodInfo(testMethod, testContext, MSTestSettings.CurrentSettings.CaptureDebugTraces);
if (testMethodInfo == null)
{
return false;
}
return /* DataSourceAttribute discovery is disabled for now, since we cannot serialize DataRow values.
this.TryProcessDataSource(test, testMethodInfo, testContext, tests) || */
TryProcessTestDataSourceTests(test, testMethodInfo, tests);
}
private static bool TryProcessDataSource(UnitTestElement test, TestMethodInfo testMethodInfo, ITestContext testContext, List<UnitTestElement> tests)
{
var dataSourceAttributes = ReflectHelper.GetAttributes<DataSourceAttribute>(testMethodInfo.MethodInfo, false);
if (dataSourceAttributes == null)
{
return false;
}
if (dataSourceAttributes.Length > 1)
{
var message = string.Format(CultureInfo.CurrentCulture, Resource.CannotEnumerateDataSourceAttribute_MoreThenOneDefined, test.TestMethod.ManagedTypeName, test.TestMethod.ManagedMethodName, dataSourceAttributes.Length);
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo($"DynamicDataEnumerator: {message}");
throw new InvalidOperationException(message);
}
// when dataSourceAttributes.Length == 1
try
{
return TryProcessDataSourceTests(test, testMethodInfo, testContext, tests);
}
catch (Exception ex)
{
var message = string.Format(CultureInfo.CurrentCulture, Resource.CannotEnumerateDataSourceAttribute, test.TestMethod.ManagedTypeName, test.TestMethod.ManagedMethodName, ex);
PlatformServiceProvider.Instance.AdapterTraceLogger.LogInfo($"DynamicDataEnumerator: {message}");
return false;
}
}
private static bool TryProcessDataSourceTests(UnitTestElement test, TestMethodInfo testMethodInfo, ITestContext testContext, List<UnitTestElement> tests)
{
var dataRows = PlatformServiceProvider.Instance.TestDataSource.GetData(testMethodInfo, testContext);
if (dataRows == null || !dataRows.Any())
{
return false;
}
try
{
int rowIndex = 0;
foreach (var dataRow in dataRows)
{
// TODO: Test serialization
rowIndex++;
var displayName = string.Format(CultureInfo.CurrentCulture, Resource.DataDrivenResultDisplayName, test.DisplayName, rowIndex);
var discoveredTest = test.Clone();
discoveredTest.DisplayName = displayName;
discoveredTest.TestMethod.DataType = DynamicDataType.DataSourceAttribute;
discoveredTest.TestMethod.SerializedData = DataSerializationHelper.Serialize(new[] { (object)rowIndex });
tests.Add(discoveredTest);
}
return true;
}
finally
{
testContext.SetDataConnection(null);
testContext.SetDataRow(null);
}
return testMethodInfo != null && TryProcessTestDataSourceTests(test, testMethodInfo, tests);
}
private static bool TryProcessTestDataSourceTests(UnitTestElement test, TestMethodInfo testMethodInfo, List<UnitTestElement> tests)

Просмотреть файл

@ -1,10 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;

Просмотреть файл

@ -1,13 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Reflection;
@ -91,12 +89,7 @@ internal class TypeValidator
// What we do is:
// - report the class as "not valid" test class. This will cause to skip enumerating tests from it.
// - Do not generate warnings/do not create NOT RUNNABLE tests.
if (type.GetTypeInfo().IsAbstract)
{
return false;
}
return true;
return !type.GetTypeInfo().IsAbstract;
}
/// <summary>

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Globalization;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Text.RegularExpressions;
@ -199,12 +197,7 @@ internal static class ExceptionHelper
var stackTrace = TrimStackTrace(stackTraceString);
if (!StringEx.IsNullOrEmpty(stackTrace))
{
return new StackTraceInformation(stackTrace, null, 0, 0);
}
return null;
return !StringEx.IsNullOrEmpty(stackTrace) ? new StackTraceInformation(stackTrace, null, 0, 0) : null;
}
/// <summary>

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
/// <summary>

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using TestPlatformObjectModel = Microsoft.VisualStudio.TestPlatform.ObjectModel;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
@ -92,12 +91,7 @@ public class TestAssemblyInfo
get
{
// If no assembly cleanup, then continue with the next one.
if (AssemblyCleanupMethod == null)
{
return false;
}
return true;
return AssemblyCleanupMethod != null;
}
}
@ -214,17 +208,10 @@ public class TestAssemblyInfo
{
var realException = ex.InnerException ?? ex;
string errorMessage;
// special case AssertFailedException to trim off part of the stack trace
if (realException is AssertFailedException or AssertInconclusiveException)
{
errorMessage = realException.Message;
}
else
{
errorMessage = realException.GetFormattedExceptionMessage();
}
string errorMessage = realException is AssertFailedException or AssertInconclusiveException
? realException.Message
: realException.GetFormattedExceptionMessage();
DebugEx.Assert(AssemblyCleanupMethod.DeclaringType?.Name is not null, "AssemblyCleanupMethod.DeclaringType.Name is null");
return string.Format(
@ -262,17 +249,10 @@ public class TestAssemblyInfo
{
var realException = ex.InnerException ?? ex;
string errorMessage;
// special case AssertFailedException to trim off part of the stack trace
if (realException is AssertFailedException or AssertInconclusiveException)
{
errorMessage = realException.Message;
}
else
{
errorMessage = realException.GetFormattedExceptionMessage();
}
string errorMessage = realException is AssertFailedException or AssertInconclusiveException
? realException.Message
: realException.GetFormattedExceptionMessage();
var exceptionStackTraceInfo = realException.GetStackTraceInformation();
DebugEx.Assert(AssemblyCleanupMethod.DeclaringType?.Name is not null, "AssemblyCleanupMethod.DeclaringType.Name is null");

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Security;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Collections.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,11 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
@ -161,12 +158,7 @@ public class TestClassInfo
}
// Otherwise, if any base cleanups were pushed to the stack we need to run them
if (BaseClassCleanupMethodsStack.Count != 0)
{
return true;
}
return false;
return BaseClassCleanupMethodsStack.Count != 0;
}
}

Просмотреть файл

@ -1,16 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
@ -298,7 +291,7 @@ public class TestExecutionManager
testSets = testsToRun.GroupBy(t => t.GetPropertyValue(TestAdapter.Constants.DoNotParallelizeProperty, false));
var parallelizableTestSet = testSets.FirstOrDefault(g => g.Key == false);
var nonParallelizableTestSet = testSets.FirstOrDefault(g => g.Key == true);
var nonParallelizableTestSet = testSets.FirstOrDefault(g => g.Key);
if (parallelizableTestSet != null)
{

Просмотреть файл

@ -1,14 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
using System.Text;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
@ -115,14 +112,7 @@ public class TestMethodInfo : ITestMethod
watch.Start();
try
{
if (IsTimeoutSet)
{
result = ExecuteInternalWithTimeout(arguments);
}
else
{
result = ExecuteInternal(arguments);
}
result = IsTimeoutSet ? ExecuteInternalWithTimeout(arguments) : ExecuteInternal(arguments);
}
finally
{
@ -216,14 +206,9 @@ public class TestMethodInfo : ITestMethod
{
// If this is the params parameters, set it to an empty
// array of that type as DefaultValue is DBNull
if (hasParamsValue && parameterNotProvidedIndex == parametersInfo.Length - 1)
{
newParameters[parameterNotProvidedIndex] = Activator.CreateInstance(parametersInfo[parameterNotProvidedIndex].ParameterType, 0);
}
else
{
newParameters[parameterNotProvidedIndex] = parametersInfo[parameterNotProvidedIndex].DefaultValue;
}
newParameters[parameterNotProvidedIndex] = hasParamsValue && parameterNotProvidedIndex == parametersInfo.Length - 1
? Activator.CreateInstance(parametersInfo[parameterNotProvidedIndex].ParameterType, 0)
: parametersInfo[parameterNotProvidedIndex].DefaultValue;
}
return newParameters;
@ -286,14 +271,9 @@ public class TestMethodInfo : ITestMethod
if (result.Outcome != UTF.UnitTestOutcome.Passed)
{
if (ex is AssertInconclusiveException || ex.InnerException is AssertInconclusiveException)
{
result.Outcome = UTF.UnitTestOutcome.Inconclusive;
}
else
{
result.Outcome = UTF.UnitTestOutcome.Failed;
}
result.Outcome = ex is AssertInconclusiveException || ex.InnerException is AssertInconclusiveException
? UTF.UnitTestOutcome.Inconclusive
: UTF.UnitTestOutcome.Failed;
}
}
@ -326,12 +306,7 @@ public class TestMethodInfo : ITestMethod
RunTestCleanupMethod(classInstance, result);
}
if (testRunnerException != null)
{
throw testRunnerException;
}
return result;
return testRunnerException != null ? throw testRunnerException : result;
}
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")]

Просмотреть файл

@ -1,11 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
@ -119,6 +116,7 @@ internal class TestMethodRunner
result = [new UnitTestResult()];
}
#pragma warning disable IDE0056 // Use index operator
var newResult = new UnitTestResult(new TestFailedException(UnitTestOutcome.Error, ex.TryGetMessage(), ex.TryGetStackTraceInformation()))
{
StandardOut = result[result.Length - 1].StandardOut,
@ -128,6 +126,7 @@ internal class TestMethodRunner
Duration = result[result.Length - 1].Duration,
};
result[result.Length - 1] = newResult;
#pragma warning restore IDE0056 // Use index operator
}
finally
{

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;

Просмотреть файл

@ -1,11 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security;
@ -676,13 +673,10 @@ internal class TypeCache : MarshalByRefObject
testMethodInfo = methodBase.DeclaringType!.GetRuntimeMethod(methodBase.Name, parameters);
}
if (testMethodInfo is null
|| !testMethodInfo.HasCorrectTestMethodSignature(true, discoverInternals))
{
return null;
}
return testMethodInfo;
return testMethodInfo is null
|| !testMethodInfo.HasCorrectTestMethodSignature(true, discoverInternals)
? null
: testMethodInfo;
}
private static MethodInfo? GetMethodInfoUsingRuntimeMethods(TestMethod testMethod, TestClassInfo testClassInfo, bool discoverInternals)
@ -758,7 +752,7 @@ internal class TypeCache : MarshalByRefObject
var attributes = testMethodInfo.TestMethod.GetCustomAttributes(typeof(TestPropertyAttribute), false);
DebugEx.Assert(attributes != null, "attributes is null");
foreach (TestPropertyAttribute attribute in attributes)
foreach (TestPropertyAttribute attribute in attributes.Cast<TestPropertyAttribute>())
{
if (!ValidateAndAssignTestProperty(testMethodInfo, testContext, attribute.Name, attribute.Value))
{

Просмотреть файл

@ -1,12 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Reflection;
@ -53,12 +52,9 @@ internal static class ExceptionExtensions
/// <returns>StackTraceInformation for the exception.</returns>
internal static StackTraceInformation? TryGetStackTraceInformation(this Exception exception)
{
if (!StringEx.IsNullOrEmpty(exception?.StackTrace))
{
return ExceptionHelper.CreateStackTraceInformation(exception, false, exception.StackTrace);
}
return null;
return !StringEx.IsNullOrEmpty(exception?.StackTrace)
? ExceptionHelper.CreateStackTraceInformation(exception, false, exception.StackTrace)
: null;
}
/// <summary>

Просмотреть файл

@ -1,10 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
@ -153,17 +151,11 @@ internal static class MethodInfoExtensions
throw new TestFailedException(ObjectModel.UnitTestOutcome.Error, Resource.UTA_TestMethodExpectedParameters);
}
Task? task;
if (parameters is not null
Task? task = parameters is not null
&& methodParameters?.Length == 1
&& methodParameters[0].ParameterType == typeof(object[]))
{
task = methodInfo.Invoke(classInstance, new[] { parameters }) as Task;
}
else
{
task = methodInfo.Invoke(classInstance, parameters) as Task;
}
&& methodParameters[0].ParameterType == typeof(object[])
? methodInfo.Invoke(classInstance, new[] { parameters }) as Task
: methodInfo.Invoke(classInstance, parameters) as Task;
// If methodInfo is an Async method, wait for returned task
task?.GetAwaiter().GetResult();

Просмотреть файл

@ -1,10 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.TestPlatform.AdapterUtilities;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,9 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Concurrent;
using System.IO;
using System.Runtime.Serialization.Json;
using System.Text;

Просмотреть файл

@ -1,10 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
internal static class DictionaryHelper

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
internal class EnvironmentWrapper : IEnvironment

Просмотреть файл

@ -1,11 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;
@ -49,11 +44,6 @@ internal static class MSTestDiscovererHelpers
}
// Scenarios that include testsettings or forcing a run via the legacy adapter are currently not supported in MSTestAdapter.
if (MSTestSettings.IsLegacyScenario(messageLogger))
{
return false;
}
return true;
return !MSTestSettings.IsLegacyScenario(messageLogger);
}
}

Просмотреть файл

@ -1,11 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Security;
@ -210,17 +207,9 @@ internal class ReflectHelper : MarshalByRefObject
/// <returns>True if there is a match.</returns>
internal static bool MatchReturnType(MethodInfo method, Type returnType)
{
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
if (returnType == null)
{
throw new ArgumentNullException(nameof(returnType));
}
return method.ReturnType.Equals(returnType);
return method == null
? throw new ArgumentNullException(nameof(method))
: returnType == null ? throw new ArgumentNullException(nameof(returnType)) : method.ReturnType.Equals(returnType);
}
/// <summary>
@ -310,7 +299,7 @@ internal class ReflectHelper : MarshalByRefObject
if (categories != null)
{
foreach (TestCategoryBaseAttribute category in categories)
foreach (TestCategoryBaseAttribute category in categories.Cast<TestCategoryBaseAttribute>())
{
testCategories.AddRange(category.TestCategories);
}
@ -377,12 +366,7 @@ internal class ReflectHelper : MarshalByRefObject
categories = categories.Concat(GetCustomAttributeForAssembly<TestCategoryBaseAttribute>(owningType.GetTypeInfo())).ToArray();
}
if (categories != null)
{
return categories;
}
return Enumerable.Empty<object>();
return categories ?? Enumerable.Empty<object>();
}
/// <summary>
@ -498,17 +482,9 @@ internal class ReflectHelper : MarshalByRefObject
classInfo.ClassCleanupMethod?.GetCustomAttribute<ClassCleanupAttribute>(true)?.CleanupBehavior,
};
if (cleanupBehaviors.Contains(ClassCleanupBehavior.EndOfClass))
{
return ClassCleanupBehavior.EndOfClass;
}
if (cleanupBehaviors.Contains(ClassCleanupBehavior.EndOfAssembly))
{
return ClassCleanupBehavior.EndOfAssembly;
}
return null;
return cleanupBehaviors.Contains(ClassCleanupBehavior.EndOfClass)
? ClassCleanupBehavior.EndOfClass
: cleanupBehaviors.Contains(ClassCleanupBehavior.EndOfAssembly) ? ClassCleanupBehavior.EndOfAssembly : null;
}
/// <summary>

Просмотреть файл

@ -1,10 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml;

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;

Просмотреть файл

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;$(NetCoreAppCurrent);$(NetCoreAppMinimum);$(NetFrameworkMinimum)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>

Просмотреть файл

@ -1,10 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Xml;
using System.Xml.Linq;
@ -206,14 +204,7 @@ public class MSTestSettings
{
var settings = GetSettings(context.RunSettings.SettingsXml, SettingsName);
if (settings != null)
{
CurrentSettings = settings;
}
else
{
CurrentSettings = new MSTestSettings();
}
CurrentSettings = settings ?? new MSTestSettings();
}
SetGlobalSettings(context.RunSettings.SettingsXml, CurrentSettings);
@ -248,26 +239,24 @@ public class MSTestSettings
return null;
}
using (var stringReader = new StringReader(runSettingsXml))
using var stringReader = new StringReader(runSettingsXml);
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
// read to the fist child
XmlReaderUtilities.ReadToRootNode(reader);
reader.ReadToNextElement();
// Read till we reach nodeName element or reach EOF
while (!string.Equals(reader.Name, settingName, StringComparison.OrdinalIgnoreCase)
&& !reader.EOF)
{
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.SkipToNextElement();
}
// read to the fist child
XmlReaderUtilities.ReadToRootNode(reader);
reader.ReadToNextElement();
// Read till we reach nodeName element or reach EOF
while (!string.Equals(reader.Name, settingName, StringComparison.OrdinalIgnoreCase)
&& !reader.EOF)
{
reader.SkipToNextElement();
}
if (!reader.EOF)
{
// read nodeName element.
return ToSettings(reader.ReadSubtree());
}
if (!reader.EOF)
{
// read nodeName element.
return ToSettings(reader.ReadSubtree());
}
return null;
@ -352,19 +341,14 @@ public class MSTestSettings
case "CLASSCLEANUPLIFECYCLE":
{
var value = reader.ReadInnerXml();
if (TryParseEnum(value, out ClassCleanupBehavior lifecycle))
{
settings.ClassCleanupLifecycle = lifecycle;
}
else
{
throw new AdapterSettingsException(
settings.ClassCleanupLifecycle = TryParseEnum(value, out ClassCleanupBehavior lifecycle)
? (ClassCleanupBehavior?)lifecycle
: throw new AdapterSettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidClassCleanupLifecycleValue,
value,
string.Join(", ", Enum.GetNames(typeof(ClassCleanupBehavior)))));
}
break;
}
@ -484,33 +468,20 @@ public class MSTestSettings
case "WORKERS":
{
var value = reader.ReadInnerXml();
if (int.TryParse(value, out int parallelWorkers))
{
if (parallelWorkers == 0)
{
settings.ParallelizationWorkers = Environment.ProcessorCount;
}
else if (parallelWorkers > 0)
{
settings.ParallelizationWorkers = parallelWorkers;
}
else
{
throw new AdapterSettingsException(
settings.ParallelizationWorkers = int.TryParse(value, out int parallelWorkers)
? parallelWorkers == 0
? Environment.ProcessorCount
: parallelWorkers > 0
? parallelWorkers
: throw new AdapterSettingsException(string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidParallelWorkersValue,
value))
: throw new AdapterSettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidParallelWorkersValue,
value));
}
}
else
{
throw new AdapterSettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidParallelWorkersValue,
value));
}
break;
}
@ -518,19 +489,14 @@ public class MSTestSettings
case "SCOPE":
{
var value = reader.ReadInnerXml();
if (TryParseEnum(value, out ExecutionScope scope))
{
settings.ParallelizationScope = scope;
}
else
{
throw new AdapterSettingsException(
settings.ParallelizationScope = TryParseEnum(value, out ExecutionScope scope)
? (ExecutionScope?)scope
: throw new AdapterSettingsException(
string.Format(
CultureInfo.CurrentCulture,
Resource.InvalidParallelScopeValue,
value,
string.Join(", ", Enum.GetNames(typeof(ExecutionScope)))));
}
break;
}

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
internal class AdapterSettingsException : Exception

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
/// <summary>

Просмотреть файл

@ -1,12 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.TestPlatform.AdapterUtilities;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Extensions;
@ -340,18 +336,6 @@ internal class UnitTestElement
private string GetDisplayName()
{
if (StringEx.IsNullOrWhiteSpace(DisplayName))
{
return TestMethod.Name;
// This causes compatibility problems with older runners.
// return StringEx.IsNullOrWhiteSpace(this.TestMethod.ManagedMethodName)
// ? this.TestMethod.Name
// : this.TestMethod.ManagedMethodName;
}
else
{
return DisplayName;
}
return StringEx.IsNullOrWhiteSpace(DisplayName) ? TestMethod.Name : DisplayName;
}
}

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.VisualStudio.TestPlatform;
/// <summary>

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
@ -48,12 +46,7 @@ public class RunConfigurationSettings
var settings = GetSettings(context.RunSettings.SettingsXml, SettingsName);
if (settings != null)
{
return settings;
}
return new RunConfigurationSettings();
return settings ?? new RunConfigurationSettings();
}
/// <summary>
@ -64,26 +57,24 @@ public class RunConfigurationSettings
/// <returns> The settings if found. Null otherwise. </returns>
internal static RunConfigurationSettings? GetSettings(string runsettingsXml, string settingName)
{
using (var stringReader = new StringReader(runsettingsXml))
using var stringReader = new StringReader(runsettingsXml);
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
// read to the fist child
XmlReaderUtilities.ReadToRootNode(reader);
reader.ReadToNextElement();
// Read till we reach nodeName element or reach EOF
while (!string.Equals(reader.Name, settingName, StringComparison.OrdinalIgnoreCase)
&& !reader.EOF)
{
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.SkipToNextElement();
}
// read to the fist child
XmlReaderUtilities.ReadToRootNode(reader);
reader.ReadToNextElement();
// Read till we reach nodeName element or reach EOF
while (!string.Equals(reader.Name, settingName, StringComparison.OrdinalIgnoreCase)
&& !reader.EOF)
{
reader.SkipToNextElement();
}
if (!reader.EOF)
{
// read nodeName element.
return ToSettings(reader.ReadSubtree());
}
if (!reader.EOF)
{
// read nodeName element.
return ToSettings(reader.ReadSubtree());
}
return null;

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,12 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Testing.Platform.Capabilities.TestFramework;
using Microsoft.Testing.Platform.Extensions.VSTestBridge;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Threading.Tasks;
namespace Microsoft.Testing.Platform.Extensions.MSTest;
internal sealed class MSTestExtension : IExtension

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.Testing.Platform.Builder;

Просмотреть файл

@ -10,7 +10,9 @@ namespace Microsoft.Testing.Platform.Extensions.MSTest;
public static class TestingPlatformBuilderHook
{
#pragma warning disable IDE0060 // Remove unused parameter
public static void AddExtensions(ITestApplicationBuilder testApplicationBuilder, string[] arguments)
#pragma warning restore IDE0060 // Remove unused parameter
{
testApplicationBuilder.AddMSTest(() => new[] { Assembly.GetEntryAssembly()! });
}

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging;

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;

Просмотреть файл

@ -2,11 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Security;
@ -558,17 +554,9 @@ public class AssemblyResolver : MarshalByRefObject, IDisposable
/// <returns> The <see cref="bool"/>. </returns>
private bool TryLoadFromCache(string assemblyName, bool isReflectionOnly, out Assembly? assembly)
{
bool isFoundInCache = false;
if (isReflectionOnly)
{
isFoundInCache = _reflectionOnlyResolvedAssemblies.TryGetValue(assemblyName, out assembly);
}
else
{
isFoundInCache = _resolvedAssemblies.TryGetValue(assemblyName, out assembly);
}
bool isFoundInCache = isReflectionOnly
? _reflectionOnlyResolvedAssemblies.TryGetValue(assemblyName, out assembly)
: _resolvedAssemblies.TryGetValue(assemblyName, out assembly);
if (isFoundInCache)
{
SafeLog(

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Просмотреть файл

@ -3,15 +3,11 @@
#if NETFRAMEWORK
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@ -101,14 +97,9 @@ internal sealed class CsvDataConnection : TestDataConnection
// We have to use the name of the folder which contains the CSV file in the connection string
// If target platform is x64, then use CsvConnectionTemplate64 connection string.
if (IntPtr.Size == 8)
{
connection.ConnectionString = string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate64, Path.GetDirectoryName(fullPath));
}
else
{
connection.ConnectionString = string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate, Path.GetDirectoryName(fullPath));
}
connection.ConnectionString = IntPtr.Size == 8
? string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate64, Path.GetDirectoryName(fullPath))
: string.Format(CultureInfo.InvariantCulture, CsvConnectionTemplate, Path.GetDirectoryName(fullPath));
WriteDiagnostics("Connection String: {0}", connection.ConnectionString);
@ -121,16 +112,9 @@ internal sealed class CsvDataConnection : TestDataConnection
command.Connection = connection;
string topClause;
if (maxRows >= 0)
{
topClause = string.Format(CultureInfo.InvariantCulture, " top {0}", maxRows.ToString(NumberFormatInfo.InvariantInfo));
}
else
{
topClause = string.Empty;
}
string topClause = maxRows >= 0
? string.Format(CultureInfo.InvariantCulture, " top {0}", maxRows.ToString(NumberFormatInfo.InvariantInfo))
: string.Empty;
string columnsClause;
if (columns != null)
{

Просмотреть файл

@ -3,9 +3,7 @@
#if NETFRAMEWORK
using System.Collections.Generic;
using System.Data.Odbc;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -47,12 +45,7 @@ internal sealed class OdbcDataConnection : TestDataConnectionSql
public override string? GetDefaultSchema()
{
if (_isMSSql)
{
return GetDefaultSchemaMSSql();
}
return base.GetDefaultSchema();
return _isMSSql ? GetDefaultSchemaMSSql() : base.GetDefaultSchema();
}
protected override SchemaMetaData[] GetSchemaMetaData()

Просмотреть файл

@ -3,7 +3,6 @@
#if NETFRAMEWORK
using System.Collections.Generic;
using System.Data.OleDb;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -47,12 +46,7 @@ internal sealed class OleDataConnection : TestDataConnectionSql
public override string? GetDefaultSchema()
{
if (_isMSSql)
{
return GetDefaultSchemaMSSql();
}
return base.GetDefaultSchema();
return _isMSSql ? GetDefaultSchemaMSSql() : base.GetDefaultSchema();
}
protected override SchemaMetaData[] GetSchemaMetaData()

Просмотреть файл

@ -3,7 +3,6 @@
#if NETFRAMEWORK
using System.Collections.Generic;
using System.Data.SqlClient;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Просмотреть файл

@ -2,14 +2,11 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Security;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -30,7 +27,7 @@ internal abstract class TestDataConnection : IDisposable
// List of places to look for files when substituting |DataDirectory|
private readonly List<string> _dataFolders;
internal protected TestDataConnection(List<string> dataFolders)
protected internal TestDataConnection(List<string> dataFolders)
{
_dataFolders = dataFolders;
}

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Просмотреть файл

@ -2,9 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.Odbc;
@ -12,7 +10,6 @@ using System.Data.OleDb;
using System.Data.SqlClient;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
@ -25,29 +22,26 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Dat
/// </summary>
internal class TestDataConnectionSql : TestDataConnection
{
private readonly DbCommandBuilder _commandBuilder;
private readonly DbConnection _connection;
private readonly DbProviderFactory _factory;
private string? _quoteSuffix;
private string? _quotePrefix;
#region Constructor
internal protected TestDataConnectionSql(string invariantProviderName, string connectionString, List<string> dataFolders)
protected internal TestDataConnectionSql(string invariantProviderName, string connectionString, List<string> dataFolders)
: base(dataFolders)
{
_factory = DbProviderFactories.GetFactory(invariantProviderName);
DebugEx.Assert(_factory != null, "factory should not be null.");
WriteDiagnostics("DbProviderFactory {0}", _factory);
Factory = DbProviderFactories.GetFactory(invariantProviderName);
DebugEx.Assert(Factory != null, "factory should not be null.");
WriteDiagnostics("DbProviderFactory {0}", Factory);
_connection = _factory.CreateConnection();
_connection = Factory.CreateConnection();
DebugEx.Assert(_connection != null, "connection");
WriteDiagnostics("DbConnection {0}", _connection);
_commandBuilder = _factory.CreateCommandBuilder();
DebugEx.Assert(_commandBuilder != null, "builder");
WriteDiagnostics("DbCommandBuilder {0}", _commandBuilder);
CommandBuilder = Factory.CreateCommandBuilder();
DebugEx.Assert(CommandBuilder != null, "builder");
WriteDiagnostics("DbCommandBuilder {0}", CommandBuilder);
if (!StringEx.IsNullOrEmpty(connectionString))
{
@ -66,9 +60,9 @@ internal class TestDataConnectionSql : TestDataConnection
public override DbConnection Connection => _connection;
protected DbCommandBuilder CommandBuilder => _commandBuilder;
protected DbCommandBuilder CommandBuilder { get; }
protected DbProviderFactory Factory => _factory;
protected DbProviderFactory Factory { get; }
#endregion
@ -380,12 +374,7 @@ internal class TestDataConnectionSql : TestDataConnection
private string MaybeQuote(string identifier, bool force)
{
if (force || FindSeparators(identifier, 0) != -1)
{
return QuoteIdentifier(identifier);
}
return identifier;
return force || FindSeparators(identifier, 0) != -1 ? QuoteIdentifier(identifier) : identifier;
}
/// <summary>
@ -567,14 +556,9 @@ internal class TestDataConnectionSql : TestDataConnection
// If schema is defined and is not equal to default, prepend table schema in front of the table.
string? qualifiedTableName = tableName;
if (isDefaultSchema)
{
qualifiedTableName = FormatTableNameForDisplay(null, tableName);
}
else
{
qualifiedTableName = FormatTableNameForDisplay(tableSchema, tableName);
}
qualifiedTableName = isDefaultSchema
? FormatTableNameForDisplay(null, tableName)
: FormatTableNameForDisplay(tableSchema, tableName);
WriteDiagnostics("Adding Table {0}", qualifiedTableName);
tableNames.Add(qualifiedTableName);
@ -875,7 +859,7 @@ internal class TestDataConnectionSql : TestDataConnection
#pragma warning restore SA1202 // Elements must be ordered by access
{
// Ensure that we Dispose of all disposables...
_commandBuilder?.Dispose();
CommandBuilder?.Dispose();
_connection?.Dispose();
GC.SuppressFinalize(this);

Просмотреть файл

@ -2,13 +2,10 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if NETFRAMEWORK
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Security;
using System.Xml;

Просмотреть файл

@ -3,10 +3,7 @@
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;

Просмотреть файл

@ -1,13 +1,11 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
#if !WINDOWS_UWP
using System.Globalization;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#if !WINDOWS_UWP
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
/// <summary>

Просмотреть файл

@ -2,8 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !WINDOWS_UWP
using System;
using System.IO;
using Microsoft.VisualStudio.TestTools.UnitTesting;

Просмотреть файл

@ -1,9 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
#if !WINDOWS_UWP
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
/// <summary>

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
using System.Reflection;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Xml;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Reflection;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
/// <summary>

Просмотреть файл

@ -1,9 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
/// <summary>

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.IO;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
/// <summary>

Просмотреть файл

@ -1,8 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#pragma warning disable CA1716 // Do not use reserved keywords

Просмотреть файл

@ -2,6 +2,7 @@
<PropertyGroup>
<TargetFrameworks>$(UwpMinimum);$(WinUiMinimum);netstandard2.0;$(NetFrameworkMinimum);$(NetCoreAppMinimum);$(NetCoreAppCurrent)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<PropertyGroup>

Просмотреть файл

@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if WINDOWS_UWP
using System.Runtime.InteropServices;
using System.Security;
#if WINDOWS_UWP
namespace System;
/// <summary>

Просмотреть файл

@ -1,10 +1,14 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
#if NETFRAMEWORK || WIN_UI
using System.Runtime.CompilerServices;
#endif
using System.Runtime.InteropServices;
#if WIN_UI
using System.Runtime.Versioning;
#endif
[assembly: ComVisible(false)]

Просмотреть файл

@ -2,7 +2,6 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !WINDOWS_UWP
using System;
using System.Diagnostics.CodeAnalysis;
using System.Security;

Просмотреть файл

@ -1,7 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Reflection;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Просмотреть файл

@ -1,16 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.IO;
using System.Reflection;
#if WIN_UI
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
#if NETFRAMEWORK
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
@ -48,14 +48,7 @@ public class FileOperations : IFileOperations
return Assembly.Load(new AssemblyName(fileNameWithoutExtension));
#elif NETFRAMEWORK
if (isReflectionOnly)
{
return Assembly.ReflectionOnlyLoadFrom(assemblyName);
}
else
{
return Assembly.LoadFrom(assemblyName);
}
return isReflectionOnly ? Assembly.ReflectionOnlyLoadFrom(assemblyName) : Assembly.LoadFrom(assemblyName);
#endif
}
@ -179,12 +172,7 @@ public class FileOperations : IFileOperations
return assemblyFileName;
#elif WIN_UI
var packagePath = AppModel.GetCurrentPackagePath();
if (packagePath == null)
{
return assemblyFileName;
}
return Path.Combine(packagePath, assemblyFileName);
return packagePath == null ? assemblyFileName : Path.Combine(packagePath, assemblyFileName);
#elif NETFRAMEWORK
return (SafeInvoke(() => Path.GetFullPath(assemblyFileName)) as string) ?? assemblyFileName;

Просмотреть файл

@ -2,10 +2,7 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !WINDOWS_UWP
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;

Просмотреть файл

@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Diagnostics.CodeAnalysis;
#if !NETFRAMEWORK
using System.Linq;
#endif
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System.Collections.Generic;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Просмотреть файл

@ -1,14 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections;
using System.Collections.Generic;
#if NETFRAMEWORK
using System.Data;
using System.Data.Common;
#endif
using System.Globalization;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;
@ -40,16 +38,16 @@ public class TestContextImplementation : TestContext, ITestContext
/// </summary>
private readonly ITestMethod _testMethod;
/// <summary>
/// Properties.
/// </summary>
private readonly Dictionary<string, object?> _properties;
/// <summary>
/// Specifies whether the writer is disposed or not.
/// </summary>
private bool _stringWriterDisposed;
/// <summary>
/// Properties.
/// </summary>
private Dictionary<string, object?> _properties;
/// <summary>
/// Unit test outcome.
/// </summary>
@ -111,7 +109,7 @@ public class TestContextImplementation : TestContext, ITestContext
#endif
/// <inheritdoc/>
public override IDictionary Properties => (IDictionary)_properties;
public override IDictionary Properties => _properties;
#if !WINDOWS_UWP && !WIN_UI
/// <inheritdoc/>

Просмотреть файл

@ -1,21 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
#if NETFRAMEWORK
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Data;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ITestDataSource = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ITestDataSource;
using UTF = Microsoft.VisualStudio.TestTools.UnitTesting;
@ -149,15 +145,10 @@ public class TestDataSource : ITestDataSource
return;
}
UTF.DataSourceElement element = TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName];
if (element == null)
{
// TODO: Change exception type to more specific one.
UTF.DataSourceElement element = TestConfiguration.ConfigurationSection.DataSources[dataSourceAttribute.DataSourceSettingName]
#pragma warning disable CA2201 // Do not raise reserved exception types
throw new Exception(string.Format(CultureInfo.CurrentCulture, Resource.UTA_DataSourceConfigurationSectionMissing, dataSourceAttribute.DataSourceSettingName));
?? throw new Exception(string.Format(CultureInfo.CurrentCulture, Resource.UTA_DataSourceConfigurationSectionMissing, dataSourceAttribute.DataSourceSettingName));
#pragma warning restore CA2201 // Do not raise reserved exception types
}
providerNameInvariant = ConfigurationManager.ConnectionStrings[element.ConnectionString].ProviderName;
connectionString = ConfigurationManager.ConnectionStrings[element.ConnectionString].ConnectionString;
tableName = element.DataTableName;

Просмотреть файл

@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
#if !WINDOWS_UWP
@ -17,8 +13,12 @@ using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utiliti
#endif
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
#if NETFRAMEWORK
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
#endif
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Просмотреть файл

@ -1,17 +1,15 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
#if WIN_UI
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
#if NETFRAMEWORK
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
@ -89,12 +87,7 @@ public class TestSource : ITestSource
bool? utfReference = AssemblyHelper.DoesReferencesAssembly(source, assemblyName);
// If no reference to UTF don't run discovery. Take conservative approach. If not able to find proceed with discovery.
if (utfReference.HasValue && utfReference.Value == false)
{
return false;
}
return true;
return !utfReference.HasValue || utfReference.Value;
#else
// .NET CORE:
// There is no way currently in dotnet core to determine referenced assemblies for a source.

Просмотреть файл

@ -1,18 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
#if NETFRAMEWORK
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
#endif
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
#endif
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
#if NETFRAMEWORK
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
#endif
#if !WINDOWS_UWP
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
@ -22,7 +24,9 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
public class TestSourceHost : ITestSourceHost
{
#if !WINDOWS_UWP
#pragma warning disable IDE0052 // Remove unread private members
private readonly string _sourceFileName;
#pragma warning restore IDE0052 // Remove unread private members
private string? _currentDirectory;
#endif
@ -165,12 +169,9 @@ public class TestSourceHost : ITestSourceHost
{
#if NETFRAMEWORK
// Honor DisableAppDomain setting if it is present in runsettings
if (_isAppDomainCreationDisabled)
{
return Activator.CreateInstance(type, args);
}
return AppDomainUtilities.CreateInstance(AppDomain!, type, args);
return _isAppDomainCreationDisabled
? Activator.CreateInstance(type, args)
: AppDomainUtilities.CreateInstance(AppDomain!, type, args);
#else
return Activator.CreateInstance(type, args);
#endif
@ -305,14 +306,9 @@ public class TestSourceHost : ITestSourceHost
// UWP platform service assembly at the test source location and since CLR starts looking for assemblies from the app base location,
// there would be a mismatch of platform service assemblies during discovery.
DebugEx.Assert(_targetFrameworkVersion is not null, "Target framework version is null.");
if (_targetFrameworkVersion.Contains(Constants.DotNetFrameWorkStringPrefix))
{
return Path.GetDirectoryName(_sourceFileName) ?? Path.GetDirectoryName(typeof(TestSourceHost).Assembly.Location);
}
else
{
return Path.GetDirectoryName(typeof(TestSourceHost).Assembly.Location);
}
return _targetFrameworkVersion.Contains(Constants.DotNetFrameWorkStringPrefix)
? Path.GetDirectoryName(_sourceFileName) ?? Path.GetDirectoryName(typeof(TestSourceHost).Assembly.Location)
: Path.GetDirectoryName(typeof(TestSourceHost).Assembly.Location);
}
/// <summary>

Просмотреть файл

@ -1,10 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
@ -44,17 +40,7 @@ public class ThreadOperations : IThreadOperations
executionThread.SetApartmentState(Thread.CurrentThread.GetApartmentState());
executionThread.Start();
if (executionThread.Join(timeout))
{
if (isUserCancelled)
{
return false;
}
return true;
}
return false;
return executionThread.Join(timeout) && !isUserCancelled;
#else
try
{

Просмотреть файл

@ -1,11 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
@ -140,18 +136,9 @@ public class ThreadSafeStringWriter : StringWriter
{
lock (StaticLockObject)
{
if (State.Value == null)
{
return null;
}
else if (!State.Value.TryGetValue(_outputType, out var stringBuilder))
{
return null;
}
else
{
return stringBuilder;
}
return State.Value == null
? null
: !State.Value.TryGetValue(_outputType, out var stringBuilder) ? null : stringBuilder;
}
}

Просмотреть файл

@ -1,8 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
#if !WINDOWS_UWP && !WIN_UI
using System.Diagnostics;
using System.IO;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -1,9 +1,9 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
#if !WINDOWS_UWP && !WIN_UI
using System.Diagnostics;
using System.IO;
#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;

Просмотреть файл

@ -3,11 +3,8 @@
#if NETFRAMEWORK
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;

Просмотреть файл

@ -3,7 +3,6 @@
#if NETFRAMEWORK
using System;
using System.Security.Policy;
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

Просмотреть файл

@ -3,16 +3,15 @@
#if !WINDOWS_UWP
using System;
using System.Collections.Generic;
#if NETFRAMEWORK
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
#endif
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше