Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d5577c0
CA1507 Use nameof in place of string literal.
Mar 3, 2020
f0529e4
IDE0016 Null check can be simplified.
Mar 3, 2020
4dc50eb
IDE0017 Object initialization can be simplified.
Mar 3, 2020
9557e50
IDE0028 Collection initialization can be simplified.
Mar 3, 2020
4b0c942
IDE0029 Null check can be simplified.
Mar 3, 2020
862549c
IDE0034 'default' expression can be simplified.
Mar 3, 2020
ef0abcc
S1066 Merge this if statement with the enclosing one.
Mar 3, 2020
939edb0
S1125 Remove the unnecessary Boolean literal(s).
Mar 3, 2020
3814461
CA1825 Avoid unnecessary zero-length array allocations. Use Array.Em…
Mar 4, 2020
c8a2e94
IDE0054 Use compound assignment.
Mar 4, 2020
f456f61
IDE0059 Unnecessary assignment of a value
Mar 5, 2020
e2e2c67
S2971 Drop 'Where' and move the condition into the 'Count'.
Mar 12, 2020
d2b409d
S2971 Drop 'Where' and move the condition into the 'FirstOrDefault'.
Mar 12, 2020
e744c84
S2971 Use 'Count' property here instead.
Mar 12, 2020
bcb80c2
Revert "S2971 Drop 'Where' and move the condition into the 'Count'."
Mar 12, 2020
4cc118b
S3415 Make sure these 2 arguments are in the correct order: expected …
Mar 12, 2020
cab75c5
S2971 Drop 'Where' and move the condition into the 'Count'.
Mar 12, 2020
4a45d1a
S1128 Remove this unnecessary 'using'.
Mar 12, 2020
30957fc
S1939 'int' should not be explicitly used as the underlying type.
Mar 12, 2020
0068609
S1155 Use '.Any()' to test whether this 'IEnumerable<string>' is empt…
Mar 12, 2020
a3cd16b
Fix Using thats only used for not for NETSTANDARD1_5
Mar 12, 2020
442afc1
CA1813 Avoid unsealed attributes.
Mar 12, 2020
bcec9b5
Revert "IDE0034 'default' expression can be simplified."
Mar 12, 2020
26ab882
fix GetResultFiles()
Mar 13, 2020
fc10751
Merge branch 'master' into fix-messages
HeroMaxPower Mar 24, 2020
7f9b684
merge
Apr 1, 2021
2c4b261
merged
Apr 1, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal void SendTestCases(string source, IEnumerable<UnitTestElement> testElem
var testCase = testElement.ToTestCase();

// Filter tests based on test case filters
if (filterExpression != null && filterExpression.MatchTestCase(testCase, (p) => this.TestMethodFilter.PropertyValueProvider(testCase, p)) == false)
if (filterExpression != null && !filterExpression.MatchTestCase(testCase, (p) => this.TestMethodFilter.PropertyValueProvider(testCase, p)))
{
continue;
}
Expand Down
8 changes: 5 additions & 3 deletions src/Adapter/MSTest.CoreAdapter/Execution/StackTraceHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ private static List<string> TypeToBeExcluded
{
if (typesToBeExcluded == null)
{
typesToBeExcluded = new List<string>();
typesToBeExcluded.Add(typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert).Namespace);
typesToBeExcluded.Add(typeof(MSTestExecutor).Namespace);
typesToBeExcluded = new List<string>
{
typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert).Namespace,
typeof(MSTestExecutor).Namespace
};
}

return typesToBeExcluded;
Expand Down
7 changes: 3 additions & 4 deletions src/Adapter/MSTest.CoreAdapter/Execution/TestAssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,9 @@ public void RunAssemblyInitialize(TestContext testContext)

var realException = this.AssemblyInitializationException.InnerException
?? this.AssemblyInitializationException;

var outcome = UnitTestOutcome.Failed;
string errorMessage = null;
StackTraceInformation stackTraceInfo = null;
UnitTestOutcome outcome;
string errorMessage;
StackTraceInformation stackTraceInfo;
if (!realException.TryGetUnitTestAssertException(out outcome, out errorMessage, out stackTraceInfo))
{
var exception = realException.GetType().ToString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ internal void SendTestResults(TestCase test, UnitTestResult[] unitTestResults, D

private static bool MatchTestFilter(ITestCaseFilterExpression filterExpression, TestCase test, TestMethodFilter testMethodFilter)
{
if (filterExpression != null && filterExpression.MatchTestCase(test, p => testMethodFilter.PropertyValueProvider(test, p)) == false)
if (filterExpression != null && !filterExpression.MatchTestCase(test, p => testMethodFilter.PropertyValueProvider(test, p)))
{
// Skip test if not fitting filter criteria.
return false;
Expand Down Expand Up @@ -289,8 +289,8 @@ private void ExecuteTestsInSource(IEnumerable<TestCase> tests, IRunContext runCo
// Parallel and not parallel sets.
testsets = testsToRun.GroupBy(t => t.GetPropertyValue<bool>(TestAdapter.Constants.DoNotParallelizeProperty, false));

var parallelizableTestSet = testsets.FirstOrDefault(g => g.Key == false);
var nonparallelizableTestSet = testsets.FirstOrDefault(g => g.Key == true);
var parallelizableTestSet = testsets.FirstOrDefault(g => !g.Key);
var nonparallelizableTestSet = testsets.FirstOrDefault(g => g.Key);

if (parallelizableTestSet != null)
{
Expand Down
20 changes: 10 additions & 10 deletions src/Adapter/MSTest.CoreAdapter/Execution/TestMethodInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,10 +453,9 @@ private Exception HandleMethodException(Exception ex, string className, string m

// Get the real exception thrown by the test method
Exception realException = this.GetRealException(ex);
string exceptionMessage = null;
StackTraceInformation exceptionStackTraceInfo = null;
var outcome = TestTools.UnitTesting.UnitTestOutcome.Failed;

string exceptionMessage;
StackTraceInformation exceptionStackTraceInfo;
UTF.UnitTestOutcome outcome;
if (realException.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out exceptionStackTraceInfo))
{
return new TestFailedException(outcome.ToUnitTestOutcome(), exceptionMessage, exceptionStackTraceInfo, realException);
Expand Down Expand Up @@ -531,7 +530,10 @@ private void RunTestCleanupMethod(object classInstance, TestResult result)
}
catch (Exception ex)
{
var cleanupOutcome = UTF.UnitTestOutcome.Failed;
StackTraceInformation realExceptionStackTraceInfo;
UTF.UnitTestOutcome cleanupOutcome;
string exceptionMessage;

var cleanupError = new StringBuilder();
var cleanupStackTrace = new StringBuilder();
StackTraceInformation cleanupStackTraceInfo = null;
Expand All @@ -546,8 +548,6 @@ private void RunTestCleanupMethod(object classInstance, TestResult result)
}

Exception realException = ex.GetInnerExceptionOrDefault();
string exceptionMessage = null;
StackTraceInformation realExceptionStackTraceInfo = null;

// special case UnitTestAssertException to trim off part of the stack trace
if (!realException.TryGetUnitTestAssertException(out cleanupOutcome, out exceptionMessage, out realExceptionStackTraceInfo))
Expand Down Expand Up @@ -632,9 +632,9 @@ private bool RunTestInitializeMethod(object classInstance, TestResult result)
catch (Exception ex)
{
var innerException = ex.GetInnerExceptionOrDefault();
string exceptionMessage = null;
StackTraceInformation exceptionStackTraceInfo = null;
var outcome = TestTools.UnitTesting.UnitTestOutcome.Failed;
string exceptionMessage;
StackTraceInformation exceptionStackTraceInfo;
UTF.UnitTestOutcome outcome;

if (innerException.TryGetUnitTestAssertException(out outcome, out exceptionMessage, out exceptionStackTraceInfo))
{
Expand Down
24 changes: 15 additions & 9 deletions src/Adapter/MSTest.CoreAdapter/Execution/TestMethodRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -244,9 +244,11 @@ internal UnitTestResult[] RunTestMethod()
if (dataRows == null)
{
watch.Stop();
var inconclusiveResult = new UTF.TestResult();
inconclusiveResult.Outcome = UTF.UnitTestOutcome.Inconclusive;
inconclusiveResult.Duration = watch.Elapsed;
var inconclusiveResult = new UTF.TestResult
{
Outcome = UTF.UnitTestOutcome.Inconclusive,
Duration = watch.Elapsed
};
results.Add(inconclusiveResult);
}
else
Expand Down Expand Up @@ -296,10 +298,12 @@ internal UnitTestResult[] RunTestMethod()
catch (Exception ex)
{
watch.Stop();
var failedResult = new UTF.TestResult();
failedResult.Outcome = UTF.UnitTestOutcome.Error;
failedResult.TestFailureException = ex;
failedResult.Duration = watch.Elapsed;
var failedResult = new UTF.TestResult
{
Outcome = UTF.UnitTestOutcome.Error,
TestFailureException = ex,
Duration = watch.Elapsed
};
results.Add(failedResult);
}
}
Expand Down Expand Up @@ -421,8 +425,10 @@ private UTF.UnitTestOutcome GetAggregateOutcome(List<UTF.TestResult> results)
}

// UpdatedResults contain parent result at first position and remaining results has parent info updated.
var updatedResults = new List<UTF.TestResult>();
updatedResults.Add(parentResult);
var updatedResults = new List<UTF.TestResult>
{
parentResult
};

foreach (var result in results)
{
Expand Down
8 changes: 4 additions & 4 deletions src/Adapter/MSTest.CoreAdapter/Execution/TypeCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ public TestMethodInfo GetTestMethodInfo(TestMethod testMethod, ITestContext test
{
if (testMethod == null)
{
throw new ArgumentNullException("testMethod");
throw new ArgumentNullException(nameof(testMethod));
}

if (testContext == null)
{
throw new ArgumentNullException("testContext");
throw new ArgumentNullException(nameof(testContext));
}

// Get the classInfo (This may throw as GetType calls assembly.GetType(..,true);)
Expand Down Expand Up @@ -682,9 +682,9 @@ private MethodInfo GetMethodInfoUsingRuntimeMethods(TestMethod testMethod, TestC
{
// Only find methods that match the given declaring name.
testMethodInfo =
methodsInClass.Where(method => method.Name.Equals(testMethod.Name)
methodsInClass.FirstOrDefault(method => method.Name.Equals(testMethod.Name)
&& method.DeclaringType.FullName.Equals(testMethod.DeclaringClassFullName)
&& method.HasCorrectTestMethodSignature(true)).FirstOrDefault();
&& method.HasCorrectTestMethodSignature(true));
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/MSTest.CoreAdapter/Execution/UnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal UnitTestResult[] RunSingleTest(TestMethod testMethod, IDictionary<strin
{
if (testMethod == null)
{
throw new ArgumentNullException("testMethod");
throw new ArgumentNullException(nameof(testMethod));
}

try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static UnitTestResult[] ToUnitTestResults(this UTF.TestResult[] testResul

for (int i = 0; i < testResults.Length; ++i)
{
UnitTestResult unitTestResult = null;
UnitTestResult unitTestResult;
UnitTestOutcome outcome = testResults[i].Outcome.ToUnitTestOutcome();

if (testResults[i].TestFailureException != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static class UnitTestOutcomeExtensions
/// <returns>The adapter's UnitTestOutcome object.</returns>
public static UnitTestOutcome ToUnitTestOutcome(this UTF.UnitTestOutcome frameworkTestOutcome)
{
UnitTestOutcome outcome = UnitTestOutcome.Passed;
UnitTestOutcome outcome;

switch (frameworkTestOutcome)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ internal static XmlReaderSettings ReaderSettings
{
get
{
var settings = new XmlReaderSettings();
settings.IgnoreComments = true;
settings.IgnoreWhitespace = true;
var settings = new XmlReaderSettings
{
IgnoreComments = true,
IgnoreWhitespace = true
};
return settings;
}
}
Expand Down
8 changes: 5 additions & 3 deletions src/Adapter/MSTest.CoreAdapter/ObjectModel/UnitTestElement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public UnitTestElement(TestMethod testMethod)
{
if (testMethod == null)
{
throw new ArgumentNullException("testMethod");
throw new ArgumentNullException(nameof(testMethod));
}

Debug.Assert(testMethod.FullClassName != null, "Full className cannot be empty");
Expand Down Expand Up @@ -115,8 +115,10 @@ internal TestCase ToTestCase()
// : string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this.TestMethod.FullClassName, this.TestMethod.Name);
var fullName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", this.TestMethod.FullClassName, this.TestMethod.Name);

TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName);
testCase.DisplayName = this.GetDisplayName();
TestCase testCase = new TestCase(fullName, TestAdapter.Constants.ExecutorUri, this.TestMethod.AssemblyName)
{
DisplayName = string.IsNullOrEmpty(this.DisplayName) ? this.TestMethod.Name : this.DisplayName
};

if (this.TestMethod.HasManagedMethodAndTypeProperties)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel
/// <summary>
/// Outcome of a test
/// </summary>
public enum UnitTestOutcome : int
public enum UnitTestOutcome
{
/// <summary>
/// There was a system error while we were trying to execute a test.
Expand Down
9 changes: 2 additions & 7 deletions src/Adapter/MSTest.CoreAdapter/TestMethodFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,9 @@ internal object PropertyValueProvider(TestCase currentTest, string propertyName)
if (currentTest != null && propertyName != null)
{
TestProperty testProperty;
if (this.supportedProperties.TryGetValue(propertyName, out testProperty))
if (this.supportedProperties.TryGetValue(propertyName, out testProperty) && currentTest.Properties.Contains(testProperty))
{
// Test case might not have defined this property. In that case GetPropertyValue()
// would return default value. For filtering, if property is not defined return null.
if (currentTest.Properties.Contains(testProperty))
{
return currentTest.GetPropertyValue(testProperty);
}
return currentTest.GetPropertyValue(testProperty);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Adapter/PlatformServices.Desktop/AssemblyResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public AssemblyResolver(IList<string> directories)
{
if (directories == null || directories.Count == 0)
{
throw new ArgumentNullException("directories");
throw new ArgumentNullException(nameof(directories));
}

this.searchDirectories = new List<string>(directories);
Expand Down
12 changes: 8 additions & 4 deletions src/Adapter/PlatformServices.Desktop/Data/CsvDataConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ private string TableName

public override List<string> GetDataTablesAndViews()
{
List<string> tableNames = new List<string>(1);
tableNames.Add(this.TableName);
List<string> tableNames = new List<string>(1)
{
this.TableName
};
return tableNames;
}

Expand Down Expand Up @@ -155,8 +157,10 @@ public DataTable ReadTable(string tableName, IEnumerable columns, int maxRows)

dataAdapter.SelectCommand = command;

DataTable table = new DataTable();
table.Locale = CultureInfo.InvariantCulture;
DataTable table = new DataTable
{
Locale = CultureInfo.InvariantCulture
};
dataAdapter.Fill(table);
return table;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public OdbcDataConnection(string invariantProviderName, string connectionString,
// Need open connection to get Connection.Driver.
Debug.Assert(this.IsOpen(), "The connection must be open!");

this.isMSSql = this.Connection != null ? IsMSSql(this.Connection.Driver) : false;
this.isMSSql = this.Connection != null && IsMSSql(this.Connection.Driver);
}

public new OdbcCommandBuilder CommandBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public OleDataConnection(string invariantProviderName, string connectionString,
Debug.Assert(this.IsOpen(), "The connection must be open!");

// Fill m_isMSSql.
this.isMSSql = this.Connection != null ? IsMSSql(this.Connection.Provider) : false;
this.isMSSql = this.Connection != null && IsMSSql(this.Connection.Provider);
}

public new OleDbCommandBuilder CommandBuilder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,9 @@ public virtual void Dispose()

internal static bool PathNeedsFixup(string path)
{
if (!string.IsNullOrEmpty(path))
if (!string.IsNullOrEmpty(path) && path.StartsWith(ConnectionDirectoryKey, StringComparison.Ordinal))
{
if (path.StartsWith(ConnectionDirectoryKey, StringComparison.Ordinal))
{
return true;
}
return true;
}

return false;
Expand Down
Loading