Skip to content

Commit

Permalink
Fix more
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Jan 14, 2025
1 parent 0959ede commit 275f176
Showing 1 changed file with 28 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,31 +80,31 @@ public void ConstructorShouldPopulateSettings()

#region RunSingleTest tests

public void RunSingleTestShouldThrowIfTestMethodIsNull() =>
VerifyThrows<ArgumentNullException>(() => _unitTestRunner.RunSingleTest(null, null, null));
public async Task RunSingleTestShouldThrowIfTestMethodIsNull() =>
await VerifyThrowsAsync<ArgumentNullException>(async () => await _unitTestRunner.RunSingleTestAsync(null, null, null));

public void RunSingleTestShouldThrowIfTestRunParametersIsNull()
public async Task RunSingleTestShouldThrowIfTestRunParametersIsNull()
{
var testMethod = new TestMethod("M", "C", "A", isAsync: false);
VerifyThrows<ArgumentNullException>(() => _unitTestRunner.RunSingleTest(testMethod, null, null));
await VerifyThrowsAsync<ArgumentNullException>(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<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.NotFound);
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");
Expand All @@ -113,7 +113,7 @@ public void RunSingleTestShouldReturnTestResultIndicatingNotRunnableTestIfTestMe
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.Returns(Assembly.GetExecutingAssembly());

UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null);
UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null);

string expectedMessage = string.Format(
CultureInfo.InvariantCulture,
Expand All @@ -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");
Expand All @@ -136,15 +136,15 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
Verify(results[0].ErrorMessage == "IgnoreTestClassMessage");
}

public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassButHasNoMessage()
public async Task ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestClassButHasNoMessage()
{
Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClass);
MethodInfo methodInfo = type.GetMethod("TestMethod");
Expand All @@ -153,15 +153,15 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
Verify(results[0].ErrorMessage == string.Empty);
}

public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodAndHasMessage()
public async Task ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodAndHasMessage()
{
Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreTestWithMessage);
MethodInfo methodInfo = type.GetMethod("TestMethod");
Expand All @@ -170,15 +170,15 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
Verify(results[0].ErrorMessage == "IgnoreTestMessage");
}

public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodButHasNoMessage()
public async Task ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsPresentOnTestMethodButHasNoMessage()
{
Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreTest);
MethodInfo methodInfo = type.GetMethod("TestMethod");
Expand All @@ -187,15 +187,15 @@ public void ExecuteShouldSkipTestAndSkipFillingIgnoreMessageIfIgnoreAttributeIsP
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
Verify(results[0].ErrorMessage == string.Empty);
}

public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethod()
public async Task ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethod()
{
Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClassAndIgnoreTestWithMessage);
MethodInfo methodInfo = type.GetMethod("TestMethod");
Expand All @@ -204,15 +204,15 @@ public void ExecuteShouldSkipTestAndFillInClassIgnoreMessageIfIgnoreAttributeIsP
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
Verify(results[0].ErrorMessage == "IgnoreTestClassMessage");
}

public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethodButClassHasNoMessage()
public async Task ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIsPresentOnBothClassAndMethodButClassHasNoMessage()
{
Type type = typeof(TypeCacheTests.DummyTestClassWithIgnoreClassWithNoMessageAndIgnoreTestWithMessage);
MethodInfo methodInfo = type.GetMethod("TestMethod");
Expand All @@ -221,23 +221,23 @@ public void ExecuteShouldSkipTestAndFillInMethodIgnoreMessageIfIgnoreAttributeIs
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Ignored);
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);

_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.Returns(Assembly.GetExecutingAssembly());

UnitTestResult[] results = _unitTestRunner.RunSingleTest(testMethod, _testRunParameters, null);
UnitTestResult[] results = await _unitTestRunner.RunSingleTestAsync(testMethod, _testRunParameters, null);

string expectedMessage = string.Format(
CultureInfo.InvariantCulture,
Expand All @@ -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");
Expand All @@ -260,15 +260,15 @@ public void RunSingleTestShouldReturnTestResultsForAPassingTestMethod()
_testablePlatformServiceProvider.MockFileOperations.Setup(fo => fo.LoadAssembly("A", It.IsAny<bool>()))
.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);
Verify(results[0].Outcome == UnitTestOutcome.Passed);
Verify(results[0].ErrorMessage is null);
}

public void RunSingleTestShouldSetTestsAsInProgressInTestContext()
public async Task RunSingleTestShouldSetTestsAsInProgressInTestContext()
{
Type type = typeof(DummyTestClass);
MethodInfo methodInfo = type.GetMethod("TestMethodToTestInProgress");
Expand All @@ -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<ReflectHelper>();
_unitTestRunner = new UnitTestRunner(new MSTestSettings(), Array.Empty<UnitTestElement>(), null, mockReflectHelper.Object);
Expand All @@ -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);
}
Expand Down

0 comments on commit 275f176

Please sign in to comment.