From 275f17687785b8e5358dd9ce2cf01be6e9b35a46 Mon Sep 17 00:00:00 2001 From: Youssef1313 Date: Tue, 14 Jan 2025 04:38:05 +0100 Subject: [PATCH] Fix more --- .../Execution/UnitTestRunnerTests.cs | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/test/UnitTests/MSTestAdapter.UnitTests/Execution/UnitTestRunnerTests.cs b/test/UnitTests/MSTestAdapter.UnitTests/Execution/UnitTestRunnerTests.cs index 52524eabf9..d9941fcd5a 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/Execution/UnitTestRunnerTests.cs +++ b/test/UnitTests/MSTestAdapter.UnitTests/Execution/UnitTestRunnerTests.cs @@ -80,23 +80,23 @@ public void ConstructorShouldPopulateSettings() #region RunSingleTest tests - public void RunSingleTestShouldThrowIfTestMethodIsNull() => - VerifyThrows(() => _unitTestRunner.RunSingleTest(null, null, null)); + public async Task RunSingleTestShouldThrowIfTestMethodIsNull() => + await VerifyThrowsAsync(async () => await _unitTestRunner.RunSingleTestAsync(null, null, null)); - public void RunSingleTestShouldThrowIfTestRunParametersIsNull() + public async Task RunSingleTestShouldThrowIfTestRunParametersIsNull() { var testMethod = new TestMethod("M", "C", "A", isAsync: false); - VerifyThrows(() => _unitTestRunner.RunSingleTest(testMethod, null, null)); + await VerifyThrowsAsync(async () => await _unitTestRunner.RunSingleTestAsync(testMethod, null, null)); } - public void RunSingleTestShouldReturnTestResultIndicateATestNotFoundIfTestMethodCannotBeFound() + public async Task RunSingleTestShouldReturnTestResultIndicateATestNotFoundIfTestMethodCannotBeFound() { var testMethod = new TestMethod("M", "C", "A", isAsync: false); _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -104,7 +104,7 @@ public void RunSingleTestShouldReturnTestResultIndicateATestNotFoundIfTestMethod Verify(results[0].ErrorMessage == "Test method M was not found."); } - public void RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMethodCannotBeRun() + public async Task RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMethodCannotBeRun() { Type type = typeof(TypeCacheTests.DummyTestClassWithTestMethods); MethodInfo methodInfo = type.GetMethod("TestMethodWithNullCustomPropertyName"); @@ -113,7 +113,7 @@ public void RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMe _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); string expectedMessage = string.Format( CultureInfo.InvariantCulture, @@ -127,7 +127,7 @@ public void RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMe Verify(expectedMessage == results[0].ErrorMessage); } - public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassAndHasMessage() + public async Task ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassAndHasMessage() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClassWithMessage); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -136,7 +136,7 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -144,7 +144,7 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP Verify(results[0].ErrorMessage == "IgnoreTestClassMessage"); } - public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassButHasNoMessage() + public async Task ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassButHasNoMessage() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClass); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -153,7 +153,7 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -161,7 +161,7 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP Verify(results[0].ErrorMessage == string.Empty); } - public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodAndHasMessage() + public async Task ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodAndHasMessage() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreTestWithMessage); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -170,7 +170,7 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -178,7 +178,7 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs Verify(results[0].ErrorMessage == "IgnoreTestMessage"); } - public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodButHasNoMessage() + public async Task ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodButHasNoMessage() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreTest); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -187,7 +187,7 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -195,7 +195,7 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP Verify(results[0].ErrorMessage == string.Empty); } - public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethod() + public async Task ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethod() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClassAndIgnoreTestWithMessage); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -204,7 +204,7 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -212,7 +212,7 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP Verify(results[0].ErrorMessage == "IgnoreTestClassMessage"); } - public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethodButClassHasNoMessage() + public async Task ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethodButClassHasNoMessage() { Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClassWithNoMessageAndIgnoreTestWithMessage); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -221,7 +221,7 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -229,7 +229,7 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs Verify(results[0].ErrorMessage == "IgnoreTestMessage"); } - public void RunSingleTestShouldReturnTestResultIndicatingFailureIfThereIsAnyTypeInspectionExceptionWhenInspectingTestMethod() + public async Task RunSingleTestShouldReturnTestResultIndicatingFailureIfThereIsAnyTypeInspectionExceptionWhenInspectingTestMethod() { Type type = typeof(TypeCacheTests.DummyTestClassWithTestMethods); var testMethod = new TestMethod("ImaginaryTestMethod", type.FullName, "A", isAsync: false); @@ -237,7 +237,7 @@ public void RunSingleTestShouldReturnTestResultIndicatingFailureIfThereIsAnyType _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); string expectedMessage = string.Format( CultureInfo.InvariantCulture, @@ -251,7 +251,7 @@ public void RunSingleTestShouldReturnTestResultIndicatingFailureIfThereIsAnyType Verify(expectedMessage == results[0].ErrorMessage); } - public void RunSingleTestShouldReturnTestResultsForAPassingTestMethod() + public async Task RunSingleTestShouldReturnTestResultsForAPassingTestMethod() { Type type = typeof(TypeCacheTests.DummyTestClassWithTestMethods); MethodInfo methodInfo = type.GetMethod("TestMethod"); @@ -260,7 +260,7 @@ public void RunSingleTestShouldReturnTestResultsForAPassingTestMethod() _testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny())) .Returns(Assembly.GetExecutingAssembly()); - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); @@ -268,7 +268,7 @@ public void RunSingleTestShouldReturnTestResultsForAPassingTestMethod() Verify(results[0].ErrorMessage is null); } - public void RunSingleTestShouldSetTestsAsInProgressInTestContext() + public async Task RunSingleTestShouldSetTestsAsInProgressInTestContext() { Type type = typeof(DummyTestClass); MethodInfo methodInfo = type.GetMethod("TestMethodToTestInProgress"); @@ -278,14 +278,14 @@ public void RunSingleTestShouldSetTestsAsInProgressInTestContext() .Returns(Assembly.GetExecutingAssembly()); // Asserting in the test method execution flow itself. - UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(results is not null); Verify(results.Length == 1); Verify(results[0].Outcome == UnitTestOutcome.Passed); } - public void RunSingleTestShouldCallAssemblyInitializeAndClassInitializeMethodsInOrder() + public async Task RunSingleTestShouldCallAssemblyInitializeAndClassInitializeMethodsInOrder() { var mockReflectHelper = new Mock(); _unitTestRunner = new UnitTestRunner(new MSTestSettings(), Array.Empty(), null, mockReflectHelper.Object); @@ -304,7 +304,7 @@ public void RunSingleTestShouldCallAssemblyInitializeAndClassInitializeMethodsIn DummyTestClassWithInitializeMethods.AssemblyInitializeMethodBody = () => validator <<= 2; DummyTestClassWithInitializeMethods.ClassInitializeMethodBody = () => validator >>= 2; - _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null); + await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null); Verify(validator == 1); }