Skip to content

Commit

Permalink
remove some redundant lambda parens (#3842)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp authored Sep 15, 2024
1 parent 4978595 commit ee86bd8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ internal void SendTestCases(string source, IEnumerable<UnitTestElement> testElem
bool hasFixtureTraits = testCase.Traits.Any(t => t.Name == Constants.FixturesTestTrait);

// Filter tests based on test case filters
if (filterExpression != null && !filterExpression.MatchTestCase(testCase, (p) => _testMethodFilter.PropertyValueProvider(testCase, p)))
if (filterExpression != null && !filterExpression.MatchTestCase(testCase, p => _testMethodFilter.PropertyValueProvider(testCase, p)))
{
// If test is a fixture test, add it to the list of fixture tests.
if (hasFixtureTraits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ protected IEnumerable<string> Deploy(IList<DeploymentItem> deploymentItems, stri
{
return FileUtility.AddFilesFromDirectory(
directory!,
(deployDirectory) => string.Equals(deployDirectory, resultsDirectory, StringComparison.OrdinalIgnoreCase), false);
deployDirectory => string.Equals(deployDirectory, resultsDirectory, StringComparison.OrdinalIgnoreCase), false);
}

if (IsDeploymentItemSourceAFile(deploymentItem.SourcePath, testSource, out string fileName))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static bool IsCIEnvironment()

foreach (string[] variables in AllNotNullVariables)
{
if (variables.All((variable) => !RoslynString.IsNullOrEmpty(Environment.GetEnvironmentVariable(variable))))
if (variables.All(variable => !RoslynString.IsNullOrEmpty(Environment.GetEnvironmentVariable(variable))))
{
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public static void AddTrxReportProvider(this ITestApplicationBuilder builder)
TrxCompareToolCommandLine createTrxCompareToolCommandLine = toolTrxCompareFactory.CreateTrxCompareToolCommandLine();
builder.CommandLine.AddProvider(() => createTrxCompareToolCommandLine);

testApplicationBuilder.Tools.AddTool((serviceProvider) => toolTrxCompareFactory.CreateTrxCompareTool(
testApplicationBuilder.Tools.AddTool(serviceProvider => toolTrxCompareFactory.CreateTrxCompareTool(
serviceProvider.GetCommandLineOptions(),
serviceProvider.GetOutputDevice(),
serviceProvider.GetRequiredService<ITask>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath()

var adapterSettings = new TestableMSTestAdapterSettings
{
DoesDirectoryExistSetter = (str) => true,
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand All @@ -52,8 +52,8 @@ public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable

var adapterSettings = new TestableMSTestAdapterSettings
{
ExpandEnvironmentVariablesSetter = (str) => str.Replace("%temp%", "C:\\foo"),
DoesDirectoryExistSetter = (str) => true,
ExpandEnvironmentVariablesSetter = str => str.Replace("%temp%", "C:\\foo"),
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand All @@ -70,7 +70,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit

var adapterSettings = new TestableMSTestAdapterSettings
{
DoesDirectoryExistSetter = (str) => true,
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand All @@ -87,7 +87,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit

var adapterSettings = new TestableMSTestAdapterSettings
{
DoesDirectoryExistSetter = (str) => true,
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand All @@ -110,7 +110,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath()

var adapterSettings = new TestableMSTestAdapterSettings
{
DoesDirectoryExistSetter = (str) => true,
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand All @@ -128,7 +128,7 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath()

var adapterSettings = new TestableMSTestAdapterSettings
{
DoesDirectoryExistSetter = (str) => true,
DoesDirectoryExistSetter = _ => true,
};

string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
Expand Down Expand Up @@ -163,8 +163,8 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly()

var adapterSettings = new TestableMSTestAdapterSettings(expectedResult)
{
ExpandEnvironmentVariablesSetter = (str) => str.Replace("%temp%", "C:\\foo"),
DoesDirectoryExistSetter = (str) => true,
ExpandEnvironmentVariablesSetter = str => str.Replace("%temp%", "C:\\foo"),
DoesDirectoryExistSetter = _ => true,
};

IList<RecursiveDirectoryPath> result = adapterSettings.GetDirectoryListWithRecursiveProperty(baseDirectory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,28 +102,28 @@ public void AddFilesWithIgnoreDirectory()
"c:\\MainClock\\Folder2\\backup\\Data.csv"
];

_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny<string>())).Returns<string>((directory) =>
_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny<string>())).Returns<string>(directory =>
{
IEnumerable<string> directories = allFiles.Where(file => IsFileUnderDirectory(directory, file)).Select((file) => Path.GetDirectoryName(file)).Distinct();
IEnumerable<string> directories = allFiles.Where(file => IsFileUnderDirectory(directory, file)).Select(file => Path.GetDirectoryName(file)).Distinct();
return directories.ToArray();
});

_fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny<string>())).Returns<string>((directory) => allFiles.Where((file) => Path.GetDirectoryName(file).Equals(directory, StringComparison.OrdinalIgnoreCase)).Distinct().ToArray());
_fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny<string>())).Returns<string>(directory => allFiles.Where(file => Path.GetDirectoryName(file).Equals(directory, StringComparison.OrdinalIgnoreCase)).Distinct().ToArray());

// Act
List<string> files = _fileUtility.Object.AddFilesFromDirectory("C:\\MainClock", (directory) => directory.Contains("Results"), false);
List<string> files = _fileUtility.Object.AddFilesFromDirectory("C:\\MainClock", directory => directory.Contains("Results"), false);

// Validate
foreach (string sourceFile in allFiles)
{
Console.WriteLine($"File to validate {sourceFile}");
if (sourceFile.Contains("Results"))
{
Verify(!files.Any((file) => file.Contains("Results")), $"{sourceFile} returned in the list from AddFilesFromDirectory");
Verify(!files.Any(file => file.Contains("Results")), $"{sourceFile} returned in the list from AddFilesFromDirectory");
}
else
{
Verify(files.Any((file) => file.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)), $"{sourceFile} not returned in the list from AddFilesFromDirectory");
Verify(files.Any(file => file.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)), $"{sourceFile} not returned in the list from AddFilesFromDirectory");
}
}
}
Expand All @@ -142,21 +142,21 @@ public void AddFilesWithNoIgnoreDirectory()
"c:\\MainClock\\Folder2\\backup\\Data.csv"
];

_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny<string>())).Returns<string>((directory) =>
_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny<string>())).Returns<string>(directory =>
{
IEnumerable<string> directories = allFiles.Where(file => IsFileUnderDirectory(directory, file)).Select((file) => Path.GetDirectoryName(file)).Distinct();
IEnumerable<string> directories = allFiles.Where(file => IsFileUnderDirectory(directory, file)).Select(file => Path.GetDirectoryName(file)).Distinct();
return directories.ToArray();
});

_fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny<string>())).Returns<string>((directory) => allFiles.Where((file) => Path.GetDirectoryName(file).Equals(directory, StringComparison.OrdinalIgnoreCase)).Distinct().ToArray());
_fileUtility.Setup(fu => fu.GetFilesInADirectory(It.IsAny<string>())).Returns<string>(directory => allFiles.Where(file => Path.GetDirectoryName(file).Equals(directory, StringComparison.OrdinalIgnoreCase)).Distinct().ToArray());

// Act
List<string> files = _fileUtility.Object.AddFilesFromDirectory("C:\\MainClock", false);

// Validate
foreach (string sourceFile in allFiles)
{
Verify(files.Any((file) => file.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)), $"{sourceFile} not returned in the list from AddFilesFromDirectory");
Verify(files.Any(file => file.Equals(sourceFile, StringComparison.OrdinalIgnoreCase)), $"{sourceFile} not returned in the list from AddFilesFromDirectory");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void SendTestCasesShouldSendTestCasesWithNavigationDataForAsyncMethods()
/// </summary>
public void SendTestCasesShouldSendFilteredTestCasesIfValidFilterExpression()
{
TestableDiscoveryContextWithGetTestCaseFilter discoveryContext = new(() => new TestableTestCaseFilterExpression((p) => p.DisplayName == "M1"));
TestableDiscoveryContextWithGetTestCaseFilter discoveryContext = new(() => new TestableTestCaseFilterExpression(p => p.DisplayName == "M1"));

var test1 = new UnitTestElement(new TestMethod("M1", "C", "A", false));
var test2 = new UnitTestElement(new TestMethod("M2", "C", "A", false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void TestAssemblyHasExecutableCleanupMethodShouldReturnTrueIfAssemblyClea
public void RunAssemblyInitializeShouldNotInvokeIfAssemblyInitializeIsNull()
{
int assemblyInitCallCount = 0;
DummyTestClass.AssemblyInitializeMethodBody = (tc) => assemblyInitCallCount++;
DummyTestClass.AssemblyInitializeMethodBody = _ => assemblyInitCallCount++;

_testAssemblyInfo.AssemblyInitializeMethod = null;

Expand All @@ -91,7 +91,7 @@ public void RunAssemblyInitializeShouldNotInvokeIfAssemblyInitializeIsNull()

public void RunAssemblyInitializeShouldThrowIfTestContextIsNull()
{
DummyTestClass.AssemblyInitializeMethodBody = (tc) => { };
DummyTestClass.AssemblyInitializeMethodBody = _ => { };

_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");

Expand All @@ -104,7 +104,7 @@ public void RunAssemblyInitializeShouldThrowIfTestContextIsNull()
public void RunAssemblyInitializeShouldNotExecuteAssemblyInitializeIfItHasAlreadyExecuted()
{
int assemblyInitCallCount = 0;
DummyTestClass.AssemblyInitializeMethodBody = (tc) => assemblyInitCallCount++;
DummyTestClass.AssemblyInitializeMethodBody = _ => assemblyInitCallCount++;

_testAssemblyInfo.IsAssemblyInitializeExecuted = true;
_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");
Expand All @@ -117,7 +117,7 @@ public void RunAssemblyInitializeShouldNotExecuteAssemblyInitializeIfItHasAlread
public void RunAssemblyInitializeShouldExecuteAssemblyInitialize()
{
int assemblyInitCallCount = 0;
DummyTestClass.AssemblyInitializeMethodBody = (tc) => assemblyInitCallCount++;
DummyTestClass.AssemblyInitializeMethodBody = _ => assemblyInitCallCount++;
_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");

_testAssemblyInfo.RunAssemblyInitialize(_testContext);
Expand All @@ -127,7 +127,7 @@ public void RunAssemblyInitializeShouldExecuteAssemblyInitialize()

public void RunAssemblyInitializeShouldSetAssemblyInitializeExecutedFlag()
{
DummyTestClass.AssemblyInitializeMethodBody = (tc) => { };
DummyTestClass.AssemblyInitializeMethodBody = _ => { };

_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");

Expand All @@ -138,7 +138,7 @@ public void RunAssemblyInitializeShouldSetAssemblyInitializeExecutedFlag()

public void RunAssemblyInitializeShouldSetAssemblyInitializationExceptionOnException()
{
DummyTestClass.AssemblyInitializeMethodBody = (tc) => UTF.Assert.Inconclusive("Test Inconclusive");
DummyTestClass.AssemblyInitializeMethodBody = _ => UTF.Assert.Inconclusive("Test Inconclusive");
_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");

Exception exception = VerifyThrows(() => _testAssemblyInfo.RunAssemblyInitialize(_testContext));
Expand Down Expand Up @@ -225,7 +225,7 @@ public void RunAssemblyInitializeShouldThrowTheInnerMostExceptionWhenThereAreMul

public void RunAssemblyInitializeShouldThrowForAlreadyExecutedTestAssemblyInitWithException()
{
DummyTestClass.AssemblyInitializeMethodBody = (tc) => { };
DummyTestClass.AssemblyInitializeMethodBody = _ => { };
_testAssemblyInfo.IsAssemblyInitializeExecuted = true;
_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");
_testAssemblyInfo.AssemblyInitializationException = new TestFailedException(UnitTestOutcome.Failed, "Cached Test failure");
Expand All @@ -239,7 +239,7 @@ public void RunAssemblyInitializeShouldThrowForAlreadyExecutedTestAssemblyInitWi

public void RunAssemblyInitializeShouldPassOnTheTestContextToAssemblyInitMethod()
{
DummyTestClass.AssemblyInitializeMethodBody = (tc) => Verify(tc == _testContext);
DummyTestClass.AssemblyInitializeMethodBody = tc => Verify(tc == _testContext);
_testAssemblyInfo.AssemblyInitializeMethod = typeof(DummyTestClass).GetMethod("AssemblyInitializeMethod");

_testAssemblyInfo.RunAssemblyInitialize(_testContext);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class TestExecutionManagerTests : TestContainer
public TestExecutionManagerTests()
{
_runContext = new TestableRunContextTestExecutionTests(() => new TestableTestCaseFilterExpression((p) => true));
_runContext = new TestableRunContextTestExecutionTests(() => new TestableTestCaseFilterExpression(_ => true));
_frameworkHandle = new TestableFrameworkHandle();
_cancellationToken = new TestRunCancellationToken();
_mockMessageLogger = new Mock<IMessageLogger>();
Expand Down Expand Up @@ -110,7 +110,7 @@ public void RunTestsForTestWithFilterShouldSendResultsForFilteredTests()
TestCase failingTestCase = GetTestCase(typeof(DummyTestClass), "FailingTest");
TestCase[] tests = [testCase, failingTestCase];

_runContext = new TestableRunContextTestExecutionTests(() => new TestableTestCaseFilterExpression((p) => p.DisplayName == "PassingTest"));
_runContext = new TestableRunContextTestExecutionTests(() => new TestableTestCaseFilterExpression(p => p.DisplayName == "PassingTest"));

_testExecutionManager.RunTests(tests, _runContext, _frameworkHandle, _cancellationToken);

Expand Down

0 comments on commit ee86bd8

Please sign in to comment.