Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -20,7 +20,7 @@ public virtual void CreateDirectoryIfNotExists(string directory)
{
DebugEx.Assert(!StringEx.IsNullOrEmpty(directory), "directory");

if (!Directory.Exists(directory))
if (!DoesDirectoryExist(directory))
{
Directory.CreateDirectory(directory); // Creates subdir chain if necessary.
}
Expand Down Expand Up @@ -59,7 +59,7 @@ public virtual string GetNextIterationDirectoryName(string parentDirectoryName,
: string.Format(CultureInfo.InvariantCulture, "{0}[{1}]", originalDirectoryName, iteration.ToString(CultureInfo.InvariantCulture));
string tryMePath = Path.Combine(parentDirectoryName, tryMe);

if (!File.Exists(tryMePath) && !Directory.Exists(tryMePath))
if (!DoesFileExist(tryMePath) && !DoesDirectoryExist(tryMePath))
{
return tryMePath;
}
Expand Down Expand Up @@ -92,7 +92,7 @@ public virtual string CopyFileOverwrite(string source, string destination, out s
try
{
string? destinationDirectory = Path.GetDirectoryName(destination);
if (!StringEx.IsNullOrEmpty(destinationDirectory) && File.Exists(source) && !Directory.Exists(destinationDirectory))
if (!StringEx.IsNullOrEmpty(destinationDirectory) && DoesFileExist(source) && !DoesDirectoryExist(destinationDirectory))
{
Directory.CreateDirectory(destinationDirectory);
}
Expand Down Expand Up @@ -253,7 +253,7 @@ public virtual void DeleteDirectories(string filePath)
/// <param name="path">path to symbols file.</param>
/// <returns>Pdb file name or null if non-existent.</returns>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "Requirement is to handle all kinds of user exceptions and message appropriately.")]
private static string? GetSymbolsFileName(string? path)
private string? GetSymbolsFileName(string? path)
{
if (StringEx.IsNullOrEmpty(path) || path.IndexOfAny(Path.GetInvalidPathChars()) != -1)
{
Expand All @@ -266,7 +266,7 @@ public virtual void DeleteDirectories(string filePath)
}

string pdbFile = Path.ChangeExtension(path, ".pdb");
if (File.Exists(pdbFile))
if (DoesFileExist(pdbFile))
{
if (EqtTrace.IsInfoEnabled)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,16 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailur
Verify(
exception.Message
== "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure. Aborting test execution.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(AssertFailedException));
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(AssertFailedException));
}
}

public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive()
Expand All @@ -164,11 +169,16 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveO
Verify(
exception.Message
== "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive. Aborting test execution.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(AssertInconclusiveException));
}
}

public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions()
Expand All @@ -182,12 +192,17 @@ public void RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExce
Verify(
exception.Message
== "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.ArgumentException: Some actualErrorMessage message. Aborting test execution.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.<>c.<RunAssemblyInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
}
}

public void RunAssemblyInitializeShouldThrowTheInnerMostExceptionWhenThereAreMultipleNestedTypeInitializationExceptions()
Expand All @@ -205,11 +220,16 @@ public void RunAssemblyInitializeShouldThrowTheInnerMostExceptionWhenThereAreMul
Verify(
exception.Message
== "Assembly Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests+DummyTestClass.AssemblyInitializeMethod threw exception. System.InvalidOperationException: I fail.. Aborting test execution.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestAssemblyInfoTests.FailingStaticHelper..cctor()", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(InvalidOperationException));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(InvalidOperationException));
}
}

public void RunAssemblyInitializeShouldThrowForAlreadyExecutedTestAssemblyInitWithException()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +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 AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
Expand Down Expand Up @@ -338,12 +340,17 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMeth
Verify(
exception.Message
== "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.InitBaseClassMethod threw exception. System.ArgumentException: Some exception message.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMethodWithNonAssertExceptions>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnBaseInitializeMethodWithNonAssertExceptions>", StringComparison.Ordinal));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(ArgumentException));
Verify(exception.InnerException.InnerException!.GetType() == typeof(InvalidOperationException));
}
}

public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure()
Expand All @@ -358,11 +365,16 @@ public void RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure()
Verify(
exception.Message
== "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException: Assert.Fail failed. Test failure.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(AssertFailedException));
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionOnAssertionFailure>", StringComparison.Ordinal));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(AssertFailedException));
}
}

public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive()
Expand All @@ -377,11 +389,16 @@ public void RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAs
Verify(
exception.Message
== "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. Microsoft.VisualStudio.TestTools.UnitTesting.AssertInconclusiveException: Assert.Inconclusive failed. Test Inconclusive.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(AssertInconclusiveException));
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithInconclusiveOnAssertInconclusive>", StringComparison.Ordinal));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(AssertInconclusiveException));
}
}

public void RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions()
Expand All @@ -396,10 +413,11 @@ public void RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExcepti
Verify(
exception.Message
== "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. System.ArgumentException: Argument exception.");
#if DEBUG
Verify(exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
#endif
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.<>c.<RunClassInitializeShouldThrowTestFailedExceptionWithNonAssertExceptions>", StringComparison.Ordinal));
}
}

public void RunClassInitializeShouldThrowForAlreadyExecutedTestClassInitWithException()
Expand Down Expand Up @@ -438,12 +456,16 @@ public void RunClassInitializeShouldThrowTheInnerMostExceptionWhenThereAreMultip
Verify(
exception.Message
== "Class Initialization method Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests+DummyTestClass.ClassInitializeMethod threw exception. System.InvalidOperationException: I fail..");
#if DEBUG
Verify(
exception.StackTraceInformation!.ErrorStackTrace.StartsWith(
if (exception.StackTraceInformation is { } stackTraceInfo)
{
Verify(stackTraceInfo.ErrorStackTrace.StartsWith(
" at Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution.TestClassInfoTests.FailingStaticHelper..cctor()", StringComparison.Ordinal));
#endif
Verify(exception.InnerException!.GetType() == typeof(InvalidOperationException));
}

if (exception.InnerException?.GetType() is { } innerType)
{
Verify(innerType == typeof(InvalidOperationException));
}
}

private TestResult GetResultOrRunClassInitialize()
Expand Down Expand Up @@ -500,12 +522,9 @@ public void RunClassCleanupShouldReturnAssertFailureExceptionDetails()
Verify(classCleanupException is not null);
Verify(classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal));
Verify(classCleanupException.Message.Contains("Error Message: Assert.Fail failed. Test Failure."));
#if DEBUG
Verify(
classCleanupException.Message.Contains(
$"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertFailureExceptionDetails)}>"),
$"Value: {classCleanupException.Message}");
#endif
classCleanupException.Message.Should().Contain(
$"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertFailureExceptionDetails)}>",
$"Value: {classCleanupException.Message}");
}

public void RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails()
Expand All @@ -522,11 +541,9 @@ public void RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails()
Verify(classCleanupException is not null);
Verify(classCleanupException.Message.StartsWith("Class Cleanup method DummyTestClass.ClassCleanupMethod failed.", StringComparison.Ordinal));
Verify(classCleanupException.Message.Contains("Error Message: Assert.Inconclusive failed. Test Inconclusive."));
#if DEBUG
Verify(
classCleanupException.Message.Contains($"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails)}>"),
classCleanupException.Message.Should().Contain(
$"{typeof(TestClassInfoTests).FullName}.<>c.<{nameof(this.RunClassCleanupShouldReturnAssertInconclusiveExceptionDetails)}>",
$"Value: {classCleanupException.Message}");
#endif
}

public void RunClassCleanupShouldReturnExceptionDetailsOfNonAssertExceptions()
Expand Down
Loading
Loading