diff --git a/src/Adapter/PlatformServices/Constants.cs b/src/Adapter/PlatformServices/Constants.cs
index ed1266dff4..36366f85b3 100644
--- a/src/Adapter/PlatformServices/Constants.cs
+++ b/src/Adapter/PlatformServices/Constants.cs
@@ -19,11 +19,6 @@ internal class Constants
public const string TargetFrameworkName = "TargetFrameworkName";
- ///
- /// Constants for MSTest in Portable Mode
- ///
- public const string PortableVsTestLocation = "PortableVsTestLocation";
-
public const string PublicAssemblies = "PublicAssemblies";
public const string PrivateAssemblies = "PrivateAssemblies";
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs
index 8b693d688c..0b3c0ef5af 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10DeploymentItemTests.cs
@@ -3,108 +3,90 @@
namespace MSTestAdapter.PlatformServices.Tests.Deployment;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
-[TestClass]
-public class DeploymentItemTests
+using TestFramework.ForTestingMSTest;
+
+public class DeploymentItemTests : TestContainer
{
- [TestMethod]
public void EqualsShouldReturnFalseIfOtherItemIsNull()
{
DeploymentItem item = new("e:\\temp\\temp1.dll");
- Assert.IsFalse(item.Equals(null));
+ Verify(!item.Equals(null));
}
- [TestMethod]
public void EqualsShouldReturnFalseIfOtherItemIsNotDeploymentItem()
{
DeploymentItem item = new("e:\\temp\\temp1.dll");
- Assert.IsFalse(item.Equals(new DeploymentItemTests()));
+ Verify(!item.Equals(new DeploymentItemTests()));
}
- [TestMethod]
public void EqualsShouldReturnFalseIfSourcePathIsDifferent()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll");
DeploymentItem item2 = new("e:\\temp\\temp2.dll");
- Assert.IsFalse(item1.Equals(item2));
+ Verify(!item1.Equals(item2));
}
- [TestMethod]
public void EqualsShouldReturnFalseIfRelativeOutputDirectoryIsDifferent()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "foo2");
- Assert.IsFalse(item1.Equals(item2));
+ Verify(!item1.Equals(item2));
}
- [TestMethod]
public void EqualsShouldReturnTrueIfSourcePathDiffersByCase()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll");
DeploymentItem item2 = new("e:\\temp\\Temp1.dll");
- Assert.IsTrue(item1.Equals(item2));
+ Verify(item1.Equals(item2));
}
- [TestMethod]
public void EqualsShouldReturnTrueIfRelativeOutputDirectoryDiffersByCase()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "Foo1");
- Assert.IsTrue(item1.Equals(item2));
+ Verify(item1.Equals(item2));
}
- [TestMethod]
public void EqualsShouldReturnTrueIfSourceAndRelativeOutputDirectoryAreSame()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "foo1");
- Assert.IsTrue(item1.Equals(item2));
+ Verify(item1.Equals(item2));
}
- [TestMethod]
public void GetHashCodeShouldConsiderSourcePathAndRelativeOutputDirectory()
{
var sourcePath = "e:\\temp\\temp1.dll";
var relativeOutputDirectory = "foo1";
DeploymentItem item = new(sourcePath, relativeOutputDirectory);
- Assert.AreEqual(sourcePath.GetHashCode() + relativeOutputDirectory.GetHashCode(), item.GetHashCode());
+ Verify(sourcePath.GetHashCode() + relativeOutputDirectory.GetHashCode() == item.GetHashCode());
}
- [TestMethod]
public void ToStringShouldReturnDeploymentItemIfRelativeOutputDirectoryIsNotSpecified()
{
var sourcePath = "e:\\temp\\temp1.dll";
DeploymentItem item = new(sourcePath);
- Assert.AreEqual(string.Format(Resource.DeploymentItem, sourcePath), item.ToString());
+ Verify(string.Format(Resource.DeploymentItem, sourcePath) == item.ToString());
}
- [TestMethod]
public void ToStringShouldReturnDeploymentItemAndRelativeOutputDirectory()
{
var sourcePath = "e:\\temp\\temp1.dll";
var relativeOutputDirectory = "foo1";
DeploymentItem item = new(sourcePath, relativeOutputDirectory);
- Assert.AreEqual(string.Format(Resource.DeploymentItemWithOutputDirectory, sourcePath, relativeOutputDirectory), item.ToString());
+ Verify(string.Format(Resource.DeploymentItemWithOutputDirectory, sourcePath, relativeOutputDirectory) == item.ToString());
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs
index 835ec035fb..3f2dbc1cc0 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Deployment/ns10TestRunDirectoriesTests.cs
@@ -3,29 +3,20 @@
namespace MSTestAdapter.PlatformServices.Tests.Deployment;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
using System;
using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
-[TestClass]
-public class TestRunDirectoriesTests
+using TestFramework.ForTestingMSTest;
+
+public class TestRunDirectoriesTests : TestContainer
{
private readonly TestRunDirectories _testRunDirectories = new(@"C:\temp");
- [TestMethod]
public void InMachineNameDirectoryShouldReturnMachineSpecificDeploymentDirectory()
{
- Assert.AreEqual(
- Path.Combine(@"C:\temp\In", Environment.MachineName),
- _testRunDirectories.InMachineNameDirectory);
+ Verify(
+ Path.Combine(@"C:\temp\In", Environment.MachineName)
+ == _testRunDirectories.InMachineNameDirectory);
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs
index b747475d17..b27ac8c0b1 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Extensions/ns10ExceptionExtensionsTests.cs
@@ -3,30 +3,20 @@
namespace MSTestAdapter.PlatformServices.Tests.Extensions;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
using System;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Extensions;
-[TestClass]
-public class ExceptionExtensionsTests
+using TestFramework.ForTestingMSTest;
+
+public class ExceptionExtensionsTests : TestContainer
{
- [TestMethod]
public void GetExceptionMessageShouldReturnExceptionMessage()
{
Exception ex = new("something bad happened");
- Assert.AreEqual("something bad happened", ex.GetExceptionMessage());
+ Verify("something bad happened" == ex.GetExceptionMessage());
}
- [TestMethod]
public void GetExceptionMessageShouldReturnInnerExceptionMessageAsWell()
{
Exception ex = new("something bad happened", new Exception("inner exception", new Exception("the real exception")));
@@ -37,6 +27,6 @@ public void GetExceptionMessageShouldReturnInnerExceptionMessageAsWell()
Environment.NewLine,
"the real exception");
- Assert.AreEqual(expectedMessage, ex.GetExceptionMessage());
+ Verify(expectedMessage == ex.GetExceptionMessage());
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs
index 48b8d3cd3e..2c55b70406 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Services/ns10MSTestAdapterSettingsTests.cs
@@ -3,44 +3,34 @@
namespace MSTestAdapter.PlatformServices.UnitTests;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestCleanup = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
+
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
-using TestUtilities;
-[TestClass]
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // File name must match first type name
-public class MSTestAdapterSettingsTests
+public class MSTestAdapterSettingsTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
- [TestCleanup]
- public void Cleanup()
+ protected override void Dispose(bool disposing)
{
- MSTestSettingsProvider.Reset();
+ if (!IsDisposed)
+ {
+ base.Dispose(disposing);
+ MSTestSettingsProvider.Reset();
+ }
}
#region ResolveEnvironmentVariableAndReturnFullPathIfExist tests.
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath()
{
string path = @"C:\unitTesting\..\MsTest\Adapter";
@@ -54,11 +44,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedAbsolutePath()
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true), 0);
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable()
{
string path = @"%temp%\unitTesting\MsTest\Adapter";
@@ -73,11 +62,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWithAnEnvironmentVariable
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true));
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithoutDot()
{
string path = @"MsTest\Adapter";
@@ -91,11 +79,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true));
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWithDot()
{
string path = @".\MsTest\Adapter";
@@ -109,11 +96,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePathWit
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true));
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath()
{
string path = @"\MsTest\Adapter";
@@ -133,11 +119,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedRelativePath()
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true));
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath()
{
string path = @"\\MsTest\Adapter";
@@ -152,11 +137,10 @@ public void ResolveEnvironmentVariableShouldResolvePathWhenPassedNetworkPath()
string result = adapterSettings.ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(0, string.Compare(result, expectedResult, true));
+ Verify(result is not null);
+ Verify(0 == string.Compare(result, expectedResult, true));
}
- [TestMethod]
public void ResolveEnvironmentVariableShouldReturnFalseForInvalidPath()
{
string path = @"Z:\Program Files (x86)\MsTest\Adapter";
@@ -164,14 +148,13 @@ public void ResolveEnvironmentVariableShouldReturnFalseForInvalidPath()
string result = new TestableMSTestAdapterSettings().ResolveEnvironmentVariableAndReturnFullPathIfExist(path, baseDirectory);
- Assert.IsNull(result);
+ Verify(result is null);
}
#endregion
#region GetDirectoryListWithRecursiveProperty tests.
- [TestMethod]
public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly()
{
string baseDirectory = @"C:\unitTesting";
@@ -189,13 +172,13 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly()
};
IList result = adapterSettings.GetDirectoryListWithRecursiveProperty(baseDirectory);
- Assert.IsNotNull(result);
- Assert.AreEqual(2, result.Count);
+ Verify(result is not null);
+ Verify(2 == result.Count);
for (int i = 0; i < 2; i++)
{
- Assert.AreEqual(0, string.Compare(result[i].DirectoryPath, expectedResult[i].DirectoryPath, StringComparison.OrdinalIgnoreCase));
- Assert.AreEqual(result[i].IncludeSubDirectories, expectedResult[i].IncludeSubDirectories);
+ Verify(0 == string.Compare(result[i].DirectoryPath, expectedResult[i].DirectoryPath, StringComparison.OrdinalIgnoreCase));
+ Verify(result[i].IncludeSubDirectories == expectedResult[i].IncludeSubDirectories);
}
}
@@ -203,7 +186,6 @@ public void GetDirectoryListWithRecursivePropertyShouldReadRunSettingCorrectly()
#region ToSettings tests.
- [TestMethod]
public void ToSettingsShouldNotThrowExceptionWhenRunSettingsXmlUnderTagMSTestv2IsWrong()
{
string runSettingxml =
@@ -225,7 +207,6 @@ public void ToSettingsShouldNotThrowExceptionWhenRunSettingsXmlUnderTagMSTestv2I
MSTestAdapterSettings.ToSettings(reader);
}
- [TestMethod]
public void ToSettingsShouldThrowExceptionWhenRunSettingsXmlIsWrong()
{
string runSettingxml =
@@ -243,14 +224,14 @@ public void ToSettingsShouldThrowExceptionWhenRunSettingsXmlIsWrong()
void shouldThrowException() => MSTestAdapterSettings.ToSettings(reader);
- ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(SettingsException));
+ var ex = VerifyThrows(shouldThrowException);
+ Verify(ex is SettingsException);
}
#endregion
#region DeploymentEnabled tests.
- [TestMethod]
public void DeploymentEnabledIsByDefaultTrueWhenNotSpecified()
{
string runSettingxml =
@@ -260,10 +241,9 @@ public void DeploymentEnabledIsByDefaultTrueWhenNotSpecified()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader);
- Assert.IsTrue(adapterSettings.DeploymentEnabled);
+ Verify(adapterSettings.DeploymentEnabled);
}
- [TestMethod]
public void DeploymentEnabledShouldBeConsumedFromRunSettingsWhenSpecified()
{
string runSettingxml =
@@ -274,14 +254,13 @@ public void DeploymentEnabledShouldBeConsumedFromRunSettingsWhenSpecified()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader);
- Assert.IsFalse(adapterSettings.DeploymentEnabled);
+ Verify(!adapterSettings.DeploymentEnabled);
}
#endregion
#region DeployTestSourceDependencies tests
- [TestMethod]
public void DeployTestSourceDependenciesIsEnabledByDefault()
{
string runSettingxml =
@@ -291,10 +270,9 @@ public void DeployTestSourceDependenciesIsEnabledByDefault()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader);
- Assert.IsTrue(adapterSettings.DeployTestSourceDependencies);
+ Verify(adapterSettings.DeployTestSourceDependencies);
}
- [TestMethod]
public void DeployTestSourceDependenciesWhenFalse()
{
string runSettingxml =
@@ -305,10 +283,9 @@ public void DeployTestSourceDependenciesWhenFalse()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader);
- Assert.IsFalse(adapterSettings.DeployTestSourceDependencies);
+ Verify(!adapterSettings.DeployTestSourceDependencies);
}
- [TestMethod]
public void DeployTestSourceDependenciesWhenTrue()
{
string runSettingxml =
@@ -319,7 +296,7 @@ public void DeployTestSourceDependenciesWhenTrue()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
MSTestAdapterSettings adapterSettings = MSTestAdapterSettings.ToSettings(reader);
- Assert.IsTrue(adapterSettings.DeployTestSourceDependencies);
+ Verify(adapterSettings.DeployTestSourceDependencies);
}
#endregion
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs
index f2abe140de..c29e7b4ac4 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10DeploymentUtilityTests.cs
@@ -3,18 +3,6 @@
namespace MSTestAdapter.PlatformServices.Tests.Utilities;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Collections.Generic;
using System.IO;
@@ -23,22 +11,22 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Moq;
-[TestClass]
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // File name must match first type name
-public class DeploymentUtilityTests
+public class DeploymentUtilityTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
private const string TestRunDirectory = "C:\\temp\\testRunDirectory";
private const string RootDeploymentDirectory = "C:\\temp\\testRunDirectory\\Deploy";
- private Mock _mockReflectionUtility;
- private Mock _mockFileUtility;
- private Mock _mockAssemblyUtility;
- private DeploymentUtility _deploymentUtility;
- private Mock _mockRunContext;
+ private readonly Mock _mockReflectionUtility;
+ private readonly Mock _mockFileUtility;
+ private readonly Mock _mockAssemblyUtility;
+ private readonly DeploymentUtility _deploymentUtility;
+ private readonly Mock _mockRunContext;
- [TestInitialize]
- public void TestInit()
+ public DeploymentUtilityTests()
{
_mockReflectionUtility = new Mock();
_mockFileUtility = new Mock();
@@ -54,7 +42,6 @@ public void TestInit()
#region CreateDeploymentDirectories tests
- [TestMethod]
public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunContext()
{
// Setup mocks
@@ -72,7 +59,6 @@ public void CreateDeploymentDirectoriesShouldCreateDeploymentDirectoryFromRunCon
_mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once);
}
- [TestMethod]
public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfTestRunDirectoryIsNull()
{
// Setup mocks
@@ -90,7 +76,6 @@ public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfT
_mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(Path.Combine(Path.Combine(RootDeploymentDirectory, TestRunDirectories.DeploymentInDirectorySuffix), Environment.MachineName)), Times.Once);
}
- [TestMethod]
public void CreateDeploymentDirectoriesShouldCreateDefaultDeploymentDirectoryIfRunContextIsNull()
{
// Setup mocks
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs
index 0f2a9fc796..2a433f665a 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/Utilities/ns10FileUtilityTests.cs
@@ -3,53 +3,40 @@
namespace MSTestAdapter.PlatformServices.Tests.Utilities;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.IO;
using System.Linq;
+
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
+
using Moq;
-[TestClass]
-public class FileUtilityTests
+using TestFramework.ForTestingMSTest;
+
+public class FileUtilityTests : TestContainer
{
- private Mock _fileUtility;
+ private readonly Mock _fileUtility;
- [TestInitialize]
- public void TestInit()
+ public FileUtilityTests()
=> _fileUtility = new Mock
{
CallBase = true
};
- [TestMethod]
public void ReplaceInvalidFileNameCharactersShouldReturnFileNameIfItHasNoInvalidChars()
{
var fileName = "galaxy";
- Assert.AreEqual(fileName, FileUtility.ReplaceInvalidFileNameCharacters(fileName));
+ Verify(fileName == FileUtility.ReplaceInvalidFileNameCharacters(fileName));
}
- [TestMethod]
public void ReplaceInvalidFileNameCharactersShouldReplaceInvalidChars()
{
var fileName = "galaxy<>far:far?away";
- Assert.AreEqual("galaxy__far_far_away", FileUtility.ReplaceInvalidFileNameCharacters(fileName));
+ Verify("galaxy__far_far_away" == FileUtility.ReplaceInvalidFileNameCharacters(fileName));
}
#region AddFilesFromDirectory tests
- [TestMethod]
public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory()
{
var topLevelFiles = new string[] { "tick.txt", "tock.tick.txt" };
@@ -59,37 +46,35 @@ public void AddFilesInADirectoryShouldReturnAllTopLevelFilesInADirectory()
var files = _fileUtility.Object.AddFilesFromDirectory("C:\\randomclock", false);
- CollectionAssert.AreEqual(topLevelFiles, files);
+ Verify(topLevelFiles.SequenceEqual(files));
}
- [TestMethod]
public void AddFilesInADirectoryShouldReturnAllFilesUnderSubFolders()
{
var allFiles = new string[]
- {
- "MainClock\\tickmain.txt", "MainClock\\tock.tick.txt",
- "MainClock\\Folder1\\tick.txt", "MainClock\\Folder1\\tock.tick.txt",
- "MainClock\\Folder2\\newtick.log", "MainClock\\Folder2\\newtock.log",
- "MainClock\\Folder2\\backup\\newtock.tick.txt",
- };
+ {
+ "MainClock\\tickmain.txt", "MainClock\\tock.tick.txt",
+ "MainClock\\Folder1\\tick.txt", "MainClock\\Folder1\\tock.tick.txt",
+ "MainClock\\Folder2\\newtick.log", "MainClock\\Folder2\\newtock.log",
+ "MainClock\\Folder2\\backup\\newtock.tick.txt",
+ };
SetupMockFileAPIs(allFiles);
var files = _fileUtility.Object.AddFilesFromDirectory("MainClock", false);
- CollectionAssert.AreEqual(allFiles, files);
+ Verify(allFiles.SequenceEqual(files));
}
- [TestMethod]
public void AddFilesInADirectoryShouldReturnAllFilesUnderSubFoldersEvenIfAFolderIsEmpty()
{
var allFiles = new string[]
- {
- "MainClock\\tickmain.txt", "MainClock\\tock.tick.txt",
- "MainClock\\Folder1\\tick.txt", "MainClock\\Folder1\\tock.tick.txt",
- "MainClock\\Folder2\\newtick.log", "MainClock\\Folder2\\newtock.log",
- "MainClock\\Folder2\\backup\\",
- };
+ {
+ "MainClock\\tickmain.txt", "MainClock\\tock.tick.txt",
+ "MainClock\\Folder1\\tick.txt", "MainClock\\Folder1\\tock.tick.txt",
+ "MainClock\\Folder2\\newtick.log", "MainClock\\Folder2\\newtock.log",
+ "MainClock\\Folder2\\backup\\",
+ };
SetupMockFileAPIs(allFiles);
@@ -98,20 +83,19 @@ public void AddFilesInADirectoryShouldReturnAllFilesUnderSubFoldersEvenIfAFolder
var expectedFiles = new string[allFiles.Length - 1];
Array.Copy(allFiles, 0, expectedFiles, 0, 6);
- CollectionAssert.AreEqual(expectedFiles, files);
+ Verify(expectedFiles.SequenceEqual(files));
}
- [TestMethod]
public void AddFilesWithIgnoreDirectory()
{
// Setup
var allFiles = new string[]
- {
- "c:\\MainClock\\Results\\tickmain.trx", "c:\\MainClock\\Results\\Run1\\tock.tick.txt",
- "c:\\MainClock\\tickmain.txt", "c:\\MainClock\\tock.tick.txt",
- "c:\\MainClock\\Folder1\\tick.txt", "c:\\MainClock\\Folder1\\tock.tick.txt",
- "c:\\MainClock\\Folder2\\backup\\Data.csv",
- };
+ {
+ "c:\\MainClock\\Results\\tickmain.trx", "c:\\MainClock\\Results\\Run1\\tock.tick.txt",
+ "c:\\MainClock\\tickmain.txt", "c:\\MainClock\\tock.tick.txt",
+ "c:\\MainClock\\Folder1\\tick.txt", "c:\\MainClock\\Folder1\\tock.tick.txt",
+ "c:\\MainClock\\Folder2\\backup\\Data.csv",
+ };
_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns((directory) =>
{
@@ -133,26 +117,25 @@ public void AddFilesWithIgnoreDirectory()
Console.WriteLine($"File to validate {sourceFile}");
if (sourceFile.Contains("Results"))
{
- Assert.IsFalse(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
{
- Assert.IsTrue(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");
}
}
}
- [TestMethod]
public void AddFilesWithNoIgnoreDirectory()
{
// Setup
var allFiles = new string[]
- {
- "c:\\MainClock\\Results\\tickmain.trx", "c:\\MainClock\\Results\\Run1\\tock.tick.txt",
- "c:\\MainClock\\tickmain.txt", "c:\\MainClock\\tock.tick.txt",
- "c:\\MainClock\\Folder1\\tick.txt", "c:\\MainClock\\Folder1\\tock.tick.txt",
- "c:\\MainClock\\Folder2\\backup\\Data.csv",
- };
+ {
+ "c:\\MainClock\\Results\\tickmain.trx", "c:\\MainClock\\Results\\Run1\\tock.tick.txt",
+ "c:\\MainClock\\tickmain.txt", "c:\\MainClock\\tock.tick.txt",
+ "c:\\MainClock\\Folder1\\tick.txt", "c:\\MainClock\\Folder1\\tock.tick.txt",
+ "c:\\MainClock\\Folder2\\backup\\Data.csv",
+ };
_fileUtility.Setup(fu => fu.GetDirectoriesInADirectory(It.IsAny())).Returns((directory) =>
{
@@ -171,7 +154,7 @@ public void AddFilesWithNoIgnoreDirectory()
// Validate
foreach (var sourceFile in allFiles)
{
- Assert.IsTrue(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");
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs
index badc49d8ce..747c3ce855 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10DiaSessionOperationsTests.cs
@@ -3,24 +3,14 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
-[TestClass]
-public class DiaSessionOperationsTests
+using TestFramework.ForTestingMSTest;
+
+#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
+public class DiaSessionOperationsTests : TestContainer
{
private readonly FileOperations _fileOperations;
@@ -29,15 +19,14 @@ public DiaSessionOperationsTests()
_fileOperations = new FileOperations();
}
- [TestMethod]
- public void CreateNavigationSessionShouldReurnNullIfSourceIsNull()
+ public void CreateNavigationSessionShouldReturnNullIfSourceIsNull()
{
try
{
DiaSessionOperations.Initialize(typeof(MockDiaSession).AssemblyQualifiedName, typeof(MockDiaNavigationData).AssemblyQualifiedName);
- Assert.IsNull(_fileOperations.CreateNavigationSession(null));
- Assert.IsTrue(MockDiaSession.IsConstructorInvoked);
+ Verify(_fileOperations.CreateNavigationSession(null) is null);
+ Verify(MockDiaSession.IsConstructorInvoked);
}
finally
{
@@ -45,15 +34,14 @@ public void CreateNavigationSessionShouldReurnNullIfSourceIsNull()
}
}
- [TestMethod]
- public void CreateNavigationSessionShuldReturnNullIfDiaSessionNotFound()
+ public void CreateNavigationSessionShouldReturnNullIfDiaSessionNotFound()
{
try
{
DiaSessionOperations.Initialize(string.Empty, string.Empty);
- Assert.IsNull(_fileOperations.CreateNavigationSession(null));
- Assert.IsFalse(MockDiaSession.IsConstructorInvoked);
+ Verify(_fileOperations.CreateNavigationSession(null) is null);
+ Verify(!MockDiaSession.IsConstructorInvoked);
}
finally
{
@@ -61,7 +49,6 @@ public void CreateNavigationSessionShuldReturnNullIfDiaSessionNotFound()
}
}
- [TestMethod]
public void CreateNavigationSessionShouldReturnDiaSession()
{
try
@@ -72,7 +59,7 @@ public void CreateNavigationSessionShouldReturnDiaSession()
var diaSession = _fileOperations.CreateNavigationSession(typeof(DiaSessionOperationsTests).GetTypeInfo().Assembly.Location);
- Assert.IsTrue(diaSession is MockDiaSession);
+ Verify(diaSession is MockDiaSession);
}
finally
{
@@ -80,7 +67,6 @@ public void CreateNavigationSessionShouldReturnDiaSession()
}
}
- [TestMethod]
public void GetNavigationDataShouldReturnDataFromNavigationSession()
{
try
@@ -99,9 +85,9 @@ public void GetNavigationDataShouldReturnDataFromNavigationSession()
out int minLineNumber,
out string fileName);
- Assert.AreEqual(navigationData.MinLineNumber, minLineNumber);
- Assert.AreEqual(navigationData.FileName, fileName);
- Assert.IsTrue(MockDiaSession.IsGetNavigationDataInvoked);
+ Verify(navigationData.MinLineNumber == minLineNumber);
+ Verify(navigationData.FileName == fileName);
+ Verify(MockDiaSession.IsGetNavigationDataInvoked);
}
finally
{
@@ -109,7 +95,6 @@ public void GetNavigationDataShouldReturnDataFromNavigationSession()
}
}
- [TestMethod]
public void GetNavigationDataShouldNotThrowOnNullNavigationSession()
{
DiaSessionOperations.Initialize(string.Empty, string.Empty);
@@ -121,11 +106,10 @@ public void GetNavigationDataShouldNotThrowOnNullNavigationSession()
out int minLineNumber,
out string fileName);
- Assert.AreEqual(-1, minLineNumber);
- Assert.IsNull(fileName);
+ Verify(-1 == minLineNumber);
+ Verify(fileName is null);
}
- [TestMethod]
public void GetNavigationDataShouldNotThrowOnMissingFileNameField()
{
try
@@ -144,8 +128,8 @@ public void GetNavigationDataShouldNotThrowOnMissingFileNameField()
out int minLineNumber,
out string fileName);
- Assert.AreEqual(86, minLineNumber);
- Assert.IsNull(fileName);
+ Verify(86 == minLineNumber);
+ Verify(fileName is null);
}
finally
{
@@ -153,7 +137,6 @@ public void GetNavigationDataShouldNotThrowOnMissingFileNameField()
}
}
- [TestMethod]
public void GetNavigationDataShouldNotThrowOnMissingLineNumberField()
{
try
@@ -172,8 +155,8 @@ public void GetNavigationDataShouldNotThrowOnMissingLineNumberField()
out int minLineNumber,
out string fileName);
- Assert.AreEqual(-1, minLineNumber);
- Assert.AreEqual(navigationData.FileName, fileName);
+ Verify(-1 == minLineNumber);
+ Verify(navigationData.FileName == fileName);
}
finally
{
@@ -181,7 +164,6 @@ public void GetNavigationDataShouldNotThrowOnMissingLineNumberField()
}
}
- [TestMethod]
public void DisposeNavigationSessionShouldDisposeDiaSession()
{
try
@@ -193,7 +175,7 @@ public void DisposeNavigationSessionShouldDisposeDiaSession()
var diaSession = _fileOperations.CreateNavigationSession(typeof(DiaSessionOperationsTests).GetTypeInfo().Assembly.Location);
_fileOperations.DisposeNavigationSession(diaSession);
- Assert.IsTrue(MockDiaSession.IsDisposeInvoked);
+ Verify(MockDiaSession.IsDisposeInvoked);
}
finally
{
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs
index 679d8a9492..5afba6f1b6 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10FileOperationsTests.cs
@@ -3,35 +3,22 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.IO;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using MSTestAdapter.TestUtilities;
-[TestClass]
-public class FileOperationsTests
+using TestFramework.ForTestingMSTest;
+
+public class FileOperationsTests : TestContainer
{
- private FileOperations _fileOperations;
+ private readonly FileOperations _fileOperations;
- [TestInitialize]
- public void TestInit()
+ public FileOperationsTests()
{
_fileOperations = new FileOperations();
}
- [TestMethod]
public void LoadAssemblyShouldThrowExceptionIfTheFileNameHasInvalidCharacters()
{
var filePath = "temp<>txt";
@@ -44,18 +31,18 @@ public void LoadAssemblyShouldThrowExceptionIfTheFileNameHasInvalidCharacters()
expectedException = typeof(ArgumentException);
#endif
- ActionUtility.ActionShouldThrowExceptionOfType(a, expectedException);
+ var ex = VerifyThrows(a);
+ Verify(ex.GetType() == expectedException);
}
- [TestMethod]
public void LoadAssemblyShouldThrowExceptionIfFileIsNotFound()
{
var filePath = "temptxt";
void a() => _fileOperations.LoadAssembly(filePath, false);
- ActionUtility.ActionShouldThrowExceptionOfType(a, typeof(FileNotFoundException));
+ var ex = VerifyThrows(a);
+ Verify(ex is FileNotFoundException);
}
- [TestMethod]
public void LoadAssemblyShouldLoadAssemblyInCurrentContext()
{
var filePath = typeof(FileOperationsTests).GetTypeInfo().Assembly.Location;
@@ -65,19 +52,17 @@ public void LoadAssemblyShouldLoadAssemblyInCurrentContext()
}
#if !WIN_UI
- [TestMethod]
public void DoesFileExistReturnsTrueForAllFiles()
{
- Assert.IsTrue(_fileOperations.DoesFileExist(null));
- Assert.IsTrue(_fileOperations.DoesFileExist("foobar"));
+ Verify(_fileOperations.DoesFileExist(null));
+ Verify(_fileOperations.DoesFileExist("foobar"));
}
#endif
- [TestMethod]
public void GetFullFilePathShouldReturnAssemblyFileName()
{
- Assert.IsNull(_fileOperations.GetFullFilePath(null));
- Assert.AreEqual("assemblyFileName", _fileOperations.GetFullFilePath("assemblyFileName"));
+ Verify(_fileOperations.GetFullFilePath(null) is null);
+ Verify("assemblyFileName" == _fileOperations.GetFullFilePath("assemblyFileName"));
}
}
#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs
index e96c10d747..12874ce936 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ReflectionOperationsTests.cs
@@ -3,24 +3,15 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-[TestClass]
-public class ReflectionOperationsTests
+using TestFramework.ForTestingMSTest;
+
+public class ReflectionOperationsTests : TestContainer
{
private readonly ReflectionOperations _reflectionOperations;
@@ -29,190 +20,177 @@ public ReflectionOperationsTests()
_reflectionOperations = new ReflectionOperations();
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributes()
{
- var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : base", "DummySingleA : base" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : base", "DummySingleA : base" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummySingleA : derived" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, true);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(3, attribs.Length);
+ Verify(attributes is not null);
+ Verify(3 == attributes.Length);
// Notice that the DummySingleA on the base method does not show up since it can only be defined once.
- var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributes()
{
- var tinfo = typeof(DummyBaseTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyBaseTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(tinfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(typeInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var tinfo = typeof(DummyTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(tinfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(typeInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetTypeInfo();
+ var methodInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, true);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a", "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributes()
{
- var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), false);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : base" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : base" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), false);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummyA : base", };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()
{
- var tinfo = typeof(DummyBaseTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyBaseTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false);
+ var attributes = _reflectionOperations.GetCustomAttributes(typeInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var tinfo = typeof(DummyTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false);
+ var attributes = _reflectionOperations.GetCustomAttributes(typeInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetTypeInfo();
+ var methodInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a", "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
{
var asm = typeof(DummyTestClass).GetTypeInfo().Assembly;
- var attribs = _reflectionOperations.GetCustomAttributes(asm, typeof(DummyAAttribute));
+ var attributes = _reflectionOperations.GetCustomAttributes(asm, typeof(DummyAAttribute));
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a1", "DummyA : a2" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- private string[] GetAttributeValuePairs(object[] attributes)
+ private static string[] GetAttributeValuePairs(object[] attributes)
{
var attribValuePairs = new List();
foreach (var attrib in attributes)
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs
index ac38addcb4..0edd8081b6 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10SettingsProviderTests.cs
@@ -3,30 +3,17 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP1_0
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Moq;
-[TestClass]
-public class SettingsProviderTests
+using TestFramework.ForTestingMSTest;
+
+public class SettingsProviderTests : TestContainer
{
- [TestMethod]
public void GetPropertiesShouldReturnEmptyDictionary()
{
MSTestSettingsProvider settings = new();
- Assert.AreEqual(0, settings.GetProperties(It.IsAny()).Count);
+ Verify(0 == settings.GetProperties(It.IsAny()).Count);
}
}
-
-#pragma warning restore SA1649 // SA1649FileNameMustMatchTypeName
-
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs
index 0269459b48..8127fd72bf 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs
@@ -3,53 +3,38 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-using UnitTestOutcome = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
-#endif
-
using System.Collections.Generic;
-using System.IO;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
using Moq;
+
+using TestFramework.ForTestingMSTest;
+
using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod;
-[TestClass]
-public class TestContextImplementationTests
+public class TestContextImplementationTests : TestContainer
{
- private Mock _testMethod;
+ private readonly Mock _testMethod;
- private IDictionary _properties;
+ private readonly IDictionary _properties;
private TestContextImplementation _testContextImplementation;
- [TestInitialize]
- public void TestInit()
+ public TestContextImplementationTests()
{
_testMethod = new Mock();
_properties = new Dictionary();
}
- [TestMethod]
public void TestContextConstructorShouldInitializeProperties()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Properties);
+ Verify(_testContextImplementation.Properties is not null);
}
- [TestMethod]
public void TestContextConstructorShouldInitializeDefaultProperties()
{
_testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
@@ -57,55 +42,46 @@ public void TestContextConstructorShouldInitializeDefaultProperties()
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Properties);
+ Verify(_testContextImplementation.Properties is not null);
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("FullyQualifiedTestClassName", "A.C.M"));
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("TestName", "M"));
+ Verify(_testContextImplementation.Properties["FullyQualifiedTestClassName"].Equals("A.C.M"));
+ Verify(_testContextImplementation.Properties["TestName"].Equals("M"));
}
- [TestMethod]
public void CurrentTestOutcomeShouldReturnDefaultOutcome()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual(UnitTestOutcome.Failed, _testContextImplementation.CurrentTestOutcome);
+ Verify(UnitTestOutcome.Failed == _testContextImplementation.CurrentTestOutcome);
}
- [TestMethod]
public void CurrentTestOutcomeShouldReturnOutcomeSet()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
_testContextImplementation.SetOutcome(UnitTestOutcome.InProgress);
- Assert.AreEqual(UnitTestOutcome.InProgress, _testContextImplementation.CurrentTestOutcome);
+ Verify(UnitTestOutcome.InProgress == _testContextImplementation.CurrentTestOutcome);
}
- [TestMethod]
public void FullyQualifiedTestClassNameShouldReturnTestMethodsFullClassName()
{
_testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual("A.C.M", _testContextImplementation.FullyQualifiedTestClassName);
+ Verify("A.C.M" == _testContextImplementation.FullyQualifiedTestClassName);
}
- [TestMethod]
public void TestNameShouldReturnTestMethodsName()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual("M", _testContextImplementation.TestName);
+ Verify("M" == _testContextImplementation.TestName);
}
- [TestMethod]
public void PropertiesShouldReturnPropertiesPassedToTestContext()
{
var property1 = new KeyValuePair("IntProperty", 1);
@@ -116,70 +92,61 @@ public void PropertiesShouldReturnPropertiesPassedToTestContext()
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- CollectionAssert.Contains(_testContextImplementation.Properties, property1);
- CollectionAssert.Contains(_testContextImplementation.Properties, property2);
+ Verify(_testContextImplementation.Properties[property1.Key] == property1.Value);
+ Verify(_testContextImplementation.Properties[property2.Key] == property2.Value);
}
- [TestMethod]
public void ContextShouldReturnTestContextObject()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Context);
- Assert.AreEqual("M", _testContextImplementation.Context.TestName);
+ Verify(_testContextImplementation.Context is not null);
+ Verify("M" == _testContextImplementation.Context.TestName);
}
- [TestMethod]
public void TryGetPropertyValueShouldReturnTrueIfPropertyIsPresent()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsTrue(_testContextImplementation.TryGetPropertyValue("TestName", out object propValue));
- Assert.AreEqual("M", propValue);
+ Verify(_testContextImplementation.TryGetPropertyValue("TestName", out object propValue));
+ Verify("M".Equals(propValue));
}
- [TestMethod]
public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsFalse(_testContextImplementation.TryGetPropertyValue("Random", out object propValue));
- Assert.IsNull(propValue);
+ Verify(!_testContextImplementation.TryGetPropertyValue("Random", out object propValue));
+ Verify(propValue is null);
}
- [TestMethod]
public void AddPropertyShouldAddPropertiesToThePropertyBag()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
_testContextImplementation.AddProperty("SomeNewProperty", "SomeValue");
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("SomeNewProperty", "SomeValue"));
+ Verify(_testContextImplementation.Properties["SomeNewProperty"].Equals("SomeValue"));
}
- [TestMethod]
public void WriteShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("{0} Testing write", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("{0} Testing \0 write \0", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -191,25 +158,22 @@ public void WriteShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.Write("{0} Testing write", 1);
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("1 Testing write");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("1 Testing \0 write \0");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteWithMessageShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -221,7 +185,6 @@ public void WriteWithMessageShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.Write("1 Testing write");
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriterForReturnCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -231,7 +194,6 @@ public void WriteWithMessageShouldWriteToStringWriterForReturnCharacters()
Equals(stringWriter.ToString(), "2 Testing write 3 Testing write");
}
- [TestMethod]
public void WriteLineShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -239,10 +201,9 @@ public void WriteLineShouldWriteToStringWriter()
_testContextImplementation.WriteLine("{0} Testing write", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteLineShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -250,10 +211,9 @@ public void WriteLineShouldWriteToStringWriterForNullCharacters()
_testContextImplementation.WriteLine("{0} Testing \0 write \0", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteLineShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -267,7 +227,6 @@ public void WriteLineShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.WriteLine("{0} Testing write", 1);
}
- [TestMethod]
public void WriteLineWithMessageShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -275,10 +234,9 @@ public void WriteLineWithMessageShouldWriteToStringWriter()
_testContextImplementation.WriteLine("1 Testing write");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteLineWithMessageShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -286,10 +244,9 @@ public void WriteLineWithMessageShouldWriteToStringWriterForNullCharacters()
_testContextImplementation.WriteLine("1 Testing \0 write \0");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteLineWithMessageShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -303,7 +260,6 @@ public void WriteLineWithMessageShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.WriteLine("1 Testing write");
}
- [TestMethod]
public void GetDiagnosticMessagesShouldReturnMessagesFromWriteLine()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -311,11 +267,10 @@ public void GetDiagnosticMessagesShouldReturnMessagesFromWriteLine()
_testContextImplementation.WriteLine("1 Testing write");
_testContextImplementation.WriteLine("2 Its a happy day");
- StringAssert.Contains(_testContextImplementation.GetDiagnosticMessages(), "1 Testing write");
- StringAssert.Contains(_testContextImplementation.GetDiagnosticMessages(), "2 Its a happy day");
+ Verify(_testContextImplementation.GetDiagnosticMessages().Contains("1 Testing write"));
+ Verify(_testContextImplementation.GetDiagnosticMessages().Contains("2 Its a happy day"));
}
- [TestMethod]
public void ClearDiagnosticMessagesShouldClearMessagesFromWriteLine()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -326,7 +281,7 @@ public void ClearDiagnosticMessagesShouldClearMessagesFromWriteLine()
_testContextImplementation.ClearDiagnosticMessages();
- Assert.AreEqual(string.Empty, stringWriter.ToString());
+ Verify(string.Empty == stringWriter.ToString());
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs
index 15d3f5431d..c15e72bb71 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceHostTests.cs
@@ -3,39 +3,27 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
-[TestClass]
-public class TestSourceHostTests
+public class TestSourceHostTests : TestContainer
{
- private TestSourceHost _testSourceHost;
+ private readonly TestSourceHost _testSourceHost;
- [TestInitialize]
- public void TestInit()
+ public TestSourceHostTests()
{
_testSourceHost = new TestSourceHost(null, null, null);
}
- [TestMethod]
public void CreateInstanceForTypeCreatesAnInstanceOfAGivenTypeThroughDefaultConstructor()
{
var type = _testSourceHost.CreateInstanceForType(typeof(DummyType), null) as DummyType;
- Assert.IsNotNull(type);
- Assert.IsTrue(type.IsDefaultConstructorCalled);
+ Verify(type is not null);
+ Verify(type.IsDefaultConstructorCalled);
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs
index 6d0b0eb21d..9bcc87cc88 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestSourceTests.cs
@@ -3,58 +3,42 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-[TestClass]
-public class TestSourceTests
+using TestFramework.ForTestingMSTest;
+
+public class TestSourceTests : TestContainer
{
- private TestSource _testSource;
+ private readonly TestSource _testSource;
- [TestInitialize]
- public void TestInit()
+ public TestSourceTests()
{
_testSource = new TestSource();
}
- [TestMethod]
public void ValidSourceExtensionsShouldContainDllExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".dll");
+ Verify(_testSource.ValidSourceExtensions.ToList().Contains(".dll"));
}
- [TestMethod]
public void ValidSourceExtensionsShouldContainExeExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".exe");
+ Verify(_testSource.ValidSourceExtensions.ToList().Contains(".exe"));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfSourceOrAssemblyNameIsNull()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(null, null));
- Assert.IsTrue(_testSource.IsAssemblyReferenced(null, string.Empty));
- Assert.IsTrue(_testSource.IsAssemblyReferenced(new AssemblyName(), null));
+ Verify(_testSource.IsAssemblyReferenced(null, null));
+ Verify(_testSource.IsAssemblyReferenced(null, string.Empty));
+ Verify(_testSource.IsAssemblyReferenced(new AssemblyName(), null));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueForAllSourceOrAssemblyNames()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(new AssemblyName("ReferenceAssembly"), "SourceAssembly"));
+ Verify(_testSource.IsAssemblyReferenced(new AssemblyName("ReferenceAssembly"), "SourceAssembly"));
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs
index 1fbca6ee59..400bb7ecb1 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10ThreadOperationsTests.cs
@@ -3,26 +3,17 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
-[TestClass]
-public class ThreadOperationsTests
+public class ThreadOperationsTests : TestContainer
{
private readonly ThreadOperations _asyncOperations;
@@ -31,7 +22,6 @@ public ThreadOperationsTests()
_asyncOperations = new ThreadOperations();
}
- [TestMethod]
public void ExecuteShouldStartTheActionOnANewThread()
{
int actionThreadID = 0;
@@ -41,20 +31,18 @@ void action()
}
CancellationTokenSource tokenSource = new();
- Assert.IsTrue(_asyncOperations.Execute(action, 1000, tokenSource.Token));
- Assert.AreNotEqual(Environment.CurrentManagedThreadId, actionThreadID);
+ Verify(_asyncOperations.Execute(action, 1000, tokenSource.Token));
+ Verify(Environment.CurrentManagedThreadId != actionThreadID);
}
- [TestMethod]
public void ExecuteShouldReturnFalseIftheActionTimesout()
{
static void action() => Task.Delay(100).Wait();
CancellationTokenSource tokenSource = new();
- Assert.IsFalse(_asyncOperations.Execute(action, 1, tokenSource.Token));
+ Verify(!_asyncOperations.Execute(action, 1, tokenSource.Token));
}
- [TestMethod]
public void ExecuteWithAbortSafetyShouldInvokeTheAction()
{
var isInvoked = false;
@@ -62,6 +50,6 @@ public void ExecuteWithAbortSafetyShouldInvokeTheAction()
_asyncOperations.ExecuteWithAbortSafety(action);
- Assert.IsTrue(isInvoked);
+ Verify(isInvoked);
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs
index 2509a78b70..571a4eee1f 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13MSTestSettingsProviderTests.cs
@@ -3,18 +3,6 @@
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.IO;
using System.Xml;
@@ -22,43 +10,38 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Services;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
-using MSTestAdapter.TestUtilities;
+using TestFramework.ForTestingMSTest;
-[TestClass]
#pragma warning disable SA1649 // File name must match first type name
-public class DesktopSettingsProviderTests
+public class DesktopSettingsProviderTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
- private MSTestSettingsProvider _settingsProvider;
+ private readonly MSTestSettingsProvider _settingsProvider;
- [TestInitialize]
- public void TestInit()
+ public DesktopSettingsProviderTests()
{
_settingsProvider = new MSTestSettingsProvider();
MSTestSettingsProvider.Reset();
}
- [TestMethod]
public void GetPropertiesShouldReturnDeploymentInformation()
{
// this is a base case and we just validating that properties does not remain un-initialized,
// so passing 'null' source will also suffice.
var properties = _settingsProvider.GetProperties(null);
- Assert.IsNotNull(properties);
- Assert.IsTrue(properties.Count > 0);
+ Verify(properties is not null);
+ Verify(properties.Count > 0);
}
- [TestMethod]
public void SettingsShouldReturnDefaultSettingsIfNotInitialized()
{
var settings = MSTestSettingsProvider.Settings;
- Assert.IsNotNull(settings);
- Assert.IsTrue(settings.DeploymentEnabled);
+ Verify(settings is not null);
+ Verify(settings.DeploymentEnabled);
}
- [TestMethod]
public void SettingsShouldReturnInitializedSettings()
{
string runSettingxml =
@@ -69,16 +52,15 @@ public void SettingsShouldReturnInitializedSettings()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
_settingsProvider.Load(reader);
- Assert.IsFalse(MSTestSettingsProvider.Settings.DeploymentEnabled);
+ Verify(!MSTestSettingsProvider.Settings.DeploymentEnabled);
}
- [TestMethod]
public void LoadShouldThrowIfReaderIsNull()
{
- ActionUtility.ActionShouldThrowExceptionOfType(() => _settingsProvider.Load(null), typeof(ArgumentNullException));
+ var exception = VerifyThrows(() => _settingsProvider.Load(null));
+ Verify(exception is ArgumentNullException);
}
- [TestMethod]
public void LoadShouldReadAndFillInSettings()
{
string runSettingxml =
@@ -89,6 +71,6 @@ public void LoadShouldReadAndFillInSettings()
XmlReader reader = XmlReader.Create(stringReader, XmlRunSettingsUtilities.ReaderSettings);
reader.Read();
_settingsProvider.Load(reader);
- Assert.IsFalse(MSTestSettingsProvider.Settings.DeploymentEnabled);
+ Verify(!MSTestSettingsProvider.Settings.DeploymentEnabled);
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs
index 6eff536249..4d377ba20f 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Services/ns13TestDeploymentTests.cs
@@ -3,51 +3,37 @@
namespace MSTestAdapter.PlatformServices.Tests.Services;
-extern alias FrameworkV2Extension;
-
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using Ignore = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Xml;
+
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Utilities;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
using Moq;
+
using MSTestAdapter.PlatformServices.Tests.Utilities;
-using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class TestDeploymentTests
+public class TestDeploymentTests : TestContainer
{
private const string DefaultDeploymentItemPath = @"c:\temp";
private const string DefaultDeploymentItemOutputDirectory = "out";
- private Mock _mockReflectionUtility;
- private Mock _mockFileUtility;
+ private readonly Mock _mockReflectionUtility;
+ private readonly Mock _mockFileUtility;
private IList _warnings;
- [TestInitialize]
- public void TestInit()
+ public TestDeploymentTests()
{
_mockReflectionUtility = new Mock();
_mockFileUtility = new Mock();
@@ -59,16 +45,14 @@ public void TestInit()
#region GetDeploymentItems tests.
- [TestMethod]
public void GetDeploymentItemsReturnsNullWhenNoDeploymentItems()
{
var methodInfo =
typeof(TestDeploymentTests).GetMethod("GetDeploymentItemsReturnsNullWhenNoDeploymentItems");
- Assert.IsNull(new TestDeployment().GetDeploymentItems(methodInfo, typeof(TestDeploymentTests), _warnings));
+ Verify(new TestDeployment().GetDeploymentItems(methodInfo, typeof(TestDeploymentTests), _warnings) is null);
}
- [TestMethod]
public void GetDeploymentItemsReturnsDeploymentItems()
{
// Arrange.
@@ -76,17 +60,17 @@ public void GetDeploymentItemsReturnsDeploymentItems()
// setup mocks
var methodLevelDeploymentItems = new[]
- {
- new KeyValuePair(
- DefaultDeploymentItemPath,
- DefaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ DefaultDeploymentItemPath,
+ DefaultDeploymentItemOutputDirectory)
+ };
var classLevelDeploymentItems = new[]
- {
- new KeyValuePair(
- DefaultDeploymentItemPath + "\\temp2",
- DefaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ DefaultDeploymentItemPath + "\\temp2",
+ DefaultDeploymentItemOutputDirectory)
+ };
var memberInfo =
typeof(TestDeploymentTests).GetMethod(
"GetDeploymentItemsReturnsDeploymentItems");
@@ -98,24 +82,23 @@ public void GetDeploymentItemsReturnsDeploymentItems()
// Assert.
var expectedDeploymentItems = new KeyValuePair[]
- {
- new KeyValuePair(
- DefaultDeploymentItemPath,
- DefaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- DefaultDeploymentItemPath + "\\temp2",
- DefaultDeploymentItemOutputDirectory)
- };
-
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ {
+ new KeyValuePair(
+ DefaultDeploymentItemPath,
+ DefaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ DefaultDeploymentItemPath + "\\temp2",
+ DefaultDeploymentItemOutputDirectory)
+ };
+
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems));
}
#endregion
#region Cleanup tests
- [TestMethod]
- public void CleanupShouldNotDeleteDirectoriesIfRunDirectoiresIsNull()
+ public void CleanupShouldNotDeleteDirectoriesIfRunDirectoriesIsNull()
{
var testDeployment = new TestDeployment(null, null, _mockFileUtility.Object);
@@ -124,7 +107,6 @@ public void CleanupShouldNotDeleteDirectoriesIfRunDirectoiresIsNull()
_mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never);
}
- [TestMethod]
public void CleanupShouldNotDeleteDirectoriesIfRunSettingsSpecifiesSo()
{
string runSettingxml =
@@ -142,14 +124,13 @@ public void CleanupShouldNotDeleteDirectoriesIfRunSettingsSpecifiesSo()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
testDeployment.Cleanup();
_mockFileUtility.Verify(fu => fu.DeleteDirectories(It.IsAny()), Times.Never);
}
- [TestMethod]
public void CleanupShouldDeleteRootDeploymentDirectory()
{
var testCase = GetTestCase(typeof(DeploymentUtilityTests).GetTypeInfo().Assembly.Location);
@@ -160,7 +141,7 @@ public void CleanupShouldDeleteRootDeploymentDirectory()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
// Act.
testDeployment.Cleanup();
@@ -172,13 +153,11 @@ public void CleanupShouldDeleteRootDeploymentDirectory()
#region GetDeploymentDirectory tests
- [TestMethod]
public void GetDeploymentDirectoryShouldReturnNullIfDeploymentDirectoryIsNull()
{
- Assert.IsNull(new TestDeployment().GetDeploymentDirectory());
+ Verify(new TestDeployment().GetDeploymentDirectory() is null);
}
- [TestMethod]
public void GetDeploymentDirectoryShouldReturnDeploymentOutputDirectory()
{
var testCase = GetTestCase(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location);
@@ -189,26 +168,25 @@ public void GetDeploymentDirectoryShouldReturnDeploymentOutputDirectory()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
// Act.
- Assert.AreEqual(testRunDirectories.OutDirectory, testDeployment.GetDeploymentDirectory());
+ Verify(testRunDirectories.OutDirectory == testDeployment.GetDeploymentDirectory());
}
#endregion
#region Deploy tests
- [TestMethod]
public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeploymentItems()
{
var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");
var kvparray = new[]
- {
- new KeyValuePair(
- DefaultDeploymentItemPath,
- DefaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ DefaultDeploymentItemPath,
+ DefaultDeploymentItemOutputDirectory)
+ };
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvparray);
var testDeployment = new TestDeployment(
@@ -224,13 +202,12 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseButHasDeployme
mstestSettingsProvider.Load(reader);
// Deployment should not happen
- Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null));
+ Verify(!testDeployment.Deploy(new List { testCase }, null, null));
// Deployment directories should not be created
- Assert.IsNull(testDeployment.GetDeploymentDirectory());
+ Verify(testDeployment.GetDeploymentDirectory() is null);
}
- [TestMethod]
public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseAndHasNoDeploymentItems()
{
var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");
@@ -248,13 +225,12 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToFalseAndHasNoDeploy
mstestSettingsProvider.Load(reader);
// Deployment should not happen
- Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null));
+ Verify(!testDeployment.Deploy(new List { testCase }, null, null));
// Deployment directories should get created
- Assert.IsNotNull(testDeployment.GetDeploymentDirectory());
+ Verify(testDeployment.GetDeploymentDirectory() is not null);
}
- [TestMethod]
public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploymentItems()
{
var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");
@@ -272,14 +248,13 @@ public void DeployShouldReturnFalseWhenDeploymentEnabledSetToTrueButHasNoDeploym
mstestSettingsProvider.Load(reader);
// Deployment should not happen
- Assert.IsFalse(testDeployment.Deploy(new List { testCase }, null, null));
+ Verify(!testDeployment.Deploy(new List { testCase }, null, null));
// Deployment directories should get created
- Assert.IsNotNull(testDeployment.GetDeploymentDirectory());
+ Verify(testDeployment.GetDeploymentDirectory() is not null);
}
// TODO: This test has to have mocks. It actually deploys stuff and we cannot assume that all the dependencies get copied over to bin\debug.
- [TestMethod]
[Ignore]
public void DeployShouldReturnTrueWhenDeploymentEnabledSetToTrueAndHasDeploymentItems()
{
@@ -304,17 +279,16 @@ public void DeployShouldReturnTrueWhenDeploymentEnabledSetToTrueAndHasDeployment
mstestSettingsProvider.Load(reader);
// Deployment should happen
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, null, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, null, new Mock().Object));
// Deployment directories should get created
- Assert.IsNotNull(testDeployment.GetDeploymentDirectory());
+ Verify(testDeployment.GetDeploymentDirectory() is not null);
}
#endregion
#region GetDeploymentInformation tests
- [TestMethod]
public void GetDeploymentInformationShouldReturnAppBaseDirectoryIfRunDirectoryIsNull()
{
TestDeployment.Reset();
@@ -322,47 +296,46 @@ public void GetDeploymentInformationShouldReturnAppBaseDirectoryIfRunDirectoryIs
var applicationBaseDirectory = Path.GetDirectoryName(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location);
var expectedProperties = new Dictionary
- {
- {
- TestContextPropertyStrings.TestRunDirectory,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings.DeploymentDirectory,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings.ResultsDirectory,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings
- .TestRunResultsDirectory,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings
- .TestResultsDirectory,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings.TestDir,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings.TestDeploymentDir,
- applicationBaseDirectory
- },
- {
- TestContextPropertyStrings.TestLogsDir,
- applicationBaseDirectory
- }
- };
- Assert.IsNotNull(properties);
- CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList());
+ {
+ {
+ TestContextPropertyStrings.TestRunDirectory,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings.DeploymentDirectory,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings.ResultsDirectory,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestRunResultsDirectory,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestResultsDirectory,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDir,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDeploymentDir,
+ applicationBaseDirectory
+ },
+ {
+ TestContextPropertyStrings.TestLogsDir,
+ applicationBaseDirectory
+ }
+ };
+ Verify(properties is not null);
+ Verify(expectedProperties.SequenceEqual(properties));
}
- [TestMethod]
public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNull()
{
// Arrange.
@@ -374,55 +347,54 @@ public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceI
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
// Act.
var properties = TestDeployment.GetDeploymentInformation(null);
// Assert.
var expectedProperties = new Dictionary
- {
- {
- TestContextPropertyStrings.TestRunDirectory,
- testRunDirectories.RootDeploymentDirectory
- },
- {
- TestContextPropertyStrings.DeploymentDirectory,
- testRunDirectories.OutDirectory
- },
- {
- TestContextPropertyStrings.ResultsDirectory,
- testRunDirectories.InDirectory
- },
- {
- TestContextPropertyStrings
- .TestRunResultsDirectory,
- testRunDirectories.InMachineNameDirectory
- },
- {
- TestContextPropertyStrings
- .TestResultsDirectory,
- testRunDirectories.InDirectory
- },
- {
- TestContextPropertyStrings.TestDir,
- testRunDirectories.RootDeploymentDirectory
- },
- {
- TestContextPropertyStrings.TestDeploymentDir,
- testRunDirectories.OutDirectory
- },
- {
- TestContextPropertyStrings.TestLogsDir,
- testRunDirectories.InMachineNameDirectory
- }
- };
-
- Assert.IsNotNull(properties);
- CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList());
+ {
+ {
+ TestContextPropertyStrings.TestRunDirectory,
+ testRunDirectories.RootDeploymentDirectory
+ },
+ {
+ TestContextPropertyStrings.DeploymentDirectory,
+ testRunDirectories.OutDirectory
+ },
+ {
+ TestContextPropertyStrings.ResultsDirectory,
+ testRunDirectories.InDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestRunResultsDirectory,
+ testRunDirectories.InMachineNameDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestResultsDirectory,
+ testRunDirectories.InDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDir,
+ testRunDirectories.RootDeploymentDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDeploymentDir,
+ testRunDirectories.OutDirectory
+ },
+ {
+ TestContextPropertyStrings.TestLogsDir,
+ testRunDirectories.InMachineNameDirectory
+ }
+ };
+
+ Verify(properties is not null);
+ Verify(expectedProperties.SequenceEqual(properties));
}
- [TestMethod]
public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceIsNotNull()
{
// Arrange.
@@ -434,52 +406,52 @@ public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceI
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
// Act.
var properties = TestDeployment.GetDeploymentInformation(typeof(TestDeploymentTests).GetTypeInfo().Assembly.Location);
// Assert.
var expectedProperties = new Dictionary
- {
- {
- TestContextPropertyStrings.TestRunDirectory,
- testRunDirectories.RootDeploymentDirectory
- },
- {
- TestContextPropertyStrings.DeploymentDirectory,
- testRunDirectories.OutDirectory
- },
- {
- TestContextPropertyStrings.ResultsDirectory,
- testRunDirectories.InDirectory
- },
- {
- TestContextPropertyStrings
- .TestRunResultsDirectory,
- testRunDirectories.InMachineNameDirectory
- },
- {
- TestContextPropertyStrings
- .TestResultsDirectory,
- testRunDirectories.InDirectory
- },
- {
- TestContextPropertyStrings.TestDir,
- testRunDirectories.RootDeploymentDirectory
- },
- {
- TestContextPropertyStrings.TestDeploymentDir,
- testRunDirectories.OutDirectory
- },
- {
- TestContextPropertyStrings.TestLogsDir,
- testRunDirectories.InMachineNameDirectory
- }
- };
-
- Assert.IsNotNull(properties);
- CollectionAssert.AreEqual(expectedProperties.ToList(), properties.ToList());
+ {
+ {
+ TestContextPropertyStrings.TestRunDirectory,
+ testRunDirectories.RootDeploymentDirectory
+ },
+ {
+ TestContextPropertyStrings.DeploymentDirectory,
+ testRunDirectories.OutDirectory
+ },
+ {
+ TestContextPropertyStrings.ResultsDirectory,
+ testRunDirectories.InDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestRunResultsDirectory,
+ testRunDirectories.InMachineNameDirectory
+ },
+ {
+ TestContextPropertyStrings
+ .TestResultsDirectory,
+ testRunDirectories.InDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDir,
+ testRunDirectories.RootDeploymentDirectory
+ },
+ {
+ TestContextPropertyStrings.TestDeploymentDir,
+ testRunDirectories.OutDirectory
+ },
+ {
+ TestContextPropertyStrings.TestLogsDir,
+ testRunDirectories.InMachineNameDirectory
+ }
+ };
+
+ Verify(properties is not null);
+ Verify(expectedProperties.SequenceEqual(properties));
}
#endregion
@@ -488,29 +460,29 @@ public void GetDeploymentInformationShouldReturnRunDirectoryInformationIfSourceI
private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems)
{
- var deploymentItemAttributes = new List();
+ var deploymentItemAttributes = new List();
foreach (var deploymentItem in deploymentItems)
{
- deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
+ deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
}
_mockReflectionUtility.Setup(
ru =>
ru.GetCustomAttributes(
memberInfo,
- typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
+ typeof(DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
}
- private TestCase GetTestCase(string source)
+ private static TestCase GetTestCase(string source)
{
var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), source);
var kvpArray = new[]
- {
- new KeyValuePair(
- DefaultDeploymentItemPath,
- DefaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ DefaultDeploymentItemPath,
+ DefaultDeploymentItemOutputDirectory)
+ };
testCase.SetPropertyValue(DeploymentItemUtilityTests.DeploymentItemsProperty, kvpArray);
return testCase;
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs
index 7257e33e40..50ee4bd97d 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13DeploymentItemUtilityTests.cs
@@ -3,23 +3,6 @@
namespace MSTestAdapter.PlatformServices.Tests.Utilities;
-extern alias FrameworkV2Extension;
-
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@@ -28,14 +11,14 @@ namespace MSTestAdapter.PlatformServices.Tests.Utilities;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting;
+using TestFramework.ForTestingMSTest;
-[TestClass]
#pragma warning disable SA1649 // File name must match first type name
-public class DeploymentItemUtilityTests
+public class DeploymentItemUtilityTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
internal static readonly TestProperty DeploymentItemsProperty = TestProperty.Register(
@@ -45,15 +28,14 @@ public class DeploymentItemUtilityTests
TestPropertyAttributes.Hidden,
typeof(TestCase));
- private Mock _mockReflectionUtility;
- private DeploymentItemUtility _deploymentItemUtility;
- private ICollection _warnings;
+ private readonly Mock _mockReflectionUtility;
+ private readonly DeploymentItemUtility _deploymentItemUtility;
+ private readonly ICollection _warnings;
private readonly string _defaultDeploymentItemPath = @"c:\temp";
private readonly string _defaultDeploymentItemOutputDirectory = "out";
- [TestInitialize]
- public void TestInit()
+ public DeploymentItemUtilityTests()
{
_mockReflectionUtility = new Mock();
_deploymentItemUtility = new DeploymentItemUtility(_mockReflectionUtility.Object);
@@ -62,48 +44,45 @@ public void TestInit()
#region GetClassLevelDeploymentItems tests
- [TestMethod]
public void GetClassLevelDeploymentItemsShouldReturnEmptyListWhenNoDeploymentItems()
{
var deploymentItems = _deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), _warnings);
- Assert.IsNotNull(deploymentItems);
- Assert.AreEqual(0, deploymentItems.Count);
+ Verify(deploymentItems is not null);
+ Verify(0 == deploymentItems.Count);
}
- [TestMethod]
public void GetClassLevelDeploymentItemsShouldReturnADeploymentItem()
{
var kvpArray = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), kvpArray);
var deploymentItems = _deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), _warnings);
var expectedDeploymentItems = new DeploymentItem[]
- {
- new DeploymentItem(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ {
+ new DeploymentItem(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems.ToArray()));
}
- [TestMethod]
public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems()
{
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes);
var deploymentItems =
@@ -121,21 +100,20 @@ public void GetClassLevelDeploymentItemsShouldReturnMoreThanOneDeploymentItems()
deploymentItemAttributes[1].Value)
};
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems.ToArray()));
}
- [TestMethod]
public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEntries()
{
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes);
var deploymentItems =
@@ -144,27 +122,26 @@ public void GetClassLevelDeploymentItemsShouldNotReturnDuplicateDeploymentItemEn
_warnings);
var expectedDeploymentItems = new[]
- {
- new DeploymentItem(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new DeploymentItem(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems.ToArray()));
}
- [TestMethod]
public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeploymentItems()
{
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- null,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ null,
+ _defaultDeploymentItemOutputDirectory)
+ };
SetupDeploymentItems(typeof(DeploymentItemUtilityTests).GetTypeInfo(), deploymentItemAttributes);
var deploymentItems = _deploymentItemUtility.GetClassLevelDeploymentItems(typeof(DeploymentItemUtilityTests), _warnings);
@@ -176,36 +153,34 @@ public void GetClassLevelDeploymentItemsShouldReportWarningsForInvalidDeployment
_defaultDeploymentItemOutputDirectory)
};
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
- Assert.AreEqual(1, _warnings.Count);
- StringAssert.Contains(_warnings.ToArray()[0], Resource.DeploymentItemPathCannotBeNullOrEmpty);
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems.ToArray()));
+ Verify(1 == _warnings.Count);
+ Verify(_warnings.ToArray()[0].Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty));
}
#endregion
#region GetDeploymentItems tests
- [TestMethod]
public void GetDeploymentItemsShouldReturnNullOnNoDeploymentItems()
{
- Assert.IsNull(_deploymentItemUtility.GetDeploymentItems(
+ Verify(_deploymentItemUtility.GetDeploymentItems(
typeof(DeploymentItemUtilityTests).GetMethod("GetDeploymentItemsShouldReturnNullOnNoDeploymentItems"),
null,
- _warnings));
+ _warnings) is null);
}
- [TestMethod]
public void GetDeploymentItemsShouldReturnMethodLevelDeploymentItemsOnly()
{
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
var memberInfo =
typeof(DeploymentItemUtilityTests).GetMethod(
"GetDeploymentItemsShouldReturnNullOnNoDeploymentItems");
@@ -217,22 +192,21 @@ public void GetDeploymentItemsShouldReturnMethodLevelDeploymentItemsOnly()
null,
_warnings);
- CollectionAssert.AreEqual(deploymentItemAttributes, deploymentItems.ToArray());
+ Verify(deploymentItemAttributes.SequenceEqual(deploymentItems.ToArray()));
}
- [TestMethod]
public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly()
{
// Arrange.
var classLevelDeploymentItems = new DeploymentItem[]
- {
- new DeploymentItem(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new DeploymentItem(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new DeploymentItem(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new DeploymentItem(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
// Act.
var deploymentItems = _deploymentItemUtility.GetDeploymentItems(
@@ -242,39 +216,38 @@ public void GetDeploymentItemsShouldReturnClassLevelDeploymentItemsOnly()
// Assert.
var expectedDeploymentItems = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems.ToArray()));
}
- [TestMethod]
public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems()
{
// Arrange.
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
var memberInfo =
typeof(DeploymentItemUtilityTests).GetMethod(
"GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems");
SetupDeploymentItems(memberInfo, deploymentItemAttributes);
var classLevelDeploymentItems = new[]
- {
- new DeploymentItem(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new DeploymentItem(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
// Act.
var deploymentItems = _deploymentItemUtility.GetDeploymentItems(
@@ -284,45 +257,44 @@ public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems()
// Assert.
var expectedDeploymentItems = new KeyValuePair[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems));
}
- [TestMethod]
public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWithoutDuplicates()
{
// Arrange.
var deploymentItemAttributes = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory)
+ };
var memberInfo =
typeof(DeploymentItemUtilityTests).GetMethod(
"GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItems");
SetupDeploymentItems(memberInfo, deploymentItemAttributes);
var classLevelDeploymentItems = new DeploymentItem[]
- {
- new DeploymentItem(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new DeploymentItem(
- _defaultDeploymentItemPath + "\\temp1",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new DeploymentItem(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new DeploymentItem(
+ _defaultDeploymentItemPath + "\\temp1",
+ _defaultDeploymentItemOutputDirectory)
+ };
// Act.
var deploymentItems = _deploymentItemUtility.GetDeploymentItems(
@@ -332,53 +304,49 @@ public void GetDeploymentItemsShouldReturnClassAndMethodLevelDeploymentItemsWith
// Assert.
var expectedDeploymentItems = new KeyValuePair[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp2",
- _defaultDeploymentItemOutputDirectory),
- new KeyValuePair(
- _defaultDeploymentItemPath + "\\temp1",
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp2",
+ _defaultDeploymentItemOutputDirectory),
+ new KeyValuePair(
+ _defaultDeploymentItemPath + "\\temp1",
+ _defaultDeploymentItemOutputDirectory)
+ };
- CollectionAssert.AreEqual(expectedDeploymentItems, deploymentItems.ToArray());
+ Verify(expectedDeploymentItems.SequenceEqual(deploymentItems));
}
#endregion
#region IsValidDeploymentItem tests
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsNull()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem(null, _defaultDeploymentItemOutputDirectory, out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem(null, _defaultDeploymentItemOutputDirectory, out var warning));
- StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning);
+ Verify(Resource.DeploymentItemPathCannotBeNullOrEmpty.Contains(warning));
}
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfSourcePathIsEmpty()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem(string.Empty, _defaultDeploymentItemOutputDirectory, out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem(string.Empty, _defaultDeploymentItemOutputDirectory, out var warning));
- StringAssert.Contains(Resource.DeploymentItemPathCannotBeNullOrEmpty, warning);
+ Verify(Resource.DeploymentItemPathCannotBeNullOrEmpty.Contains(warning));
}
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsNull()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, null, out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, null, out var warning));
StringAssert.Contains(Resource.DeploymentItemOutputDirectoryCannotBeNull, warning);
}
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfSourcePathHasInvalidCharacters()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem("C:<>", _defaultDeploymentItemOutputDirectory, out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem("C:<>", _defaultDeploymentItemOutputDirectory, out var warning));
StringAssert.Contains(
string.Format(
@@ -388,10 +356,9 @@ public void IsValidDeploymentItemShouldReportWarningIfSourcePathHasInvalidCharac
warning);
}
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfOutputDirectoryHasInvalidCharacters()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, "<>", out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, "<>", out var warning));
StringAssert.Contains(
string.Format(
@@ -401,10 +368,9 @@ public void IsValidDeploymentItemShouldReportWarningIfOutputDirectoryHasInvalidC
warning);
}
- [TestMethod]
public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryIsRooted()
{
- Assert.IsFalse(DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, "C:\\temp", out var warning));
+ Verify(!DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, "C:\\temp", out var warning));
StringAssert.Contains(
string.Format(
@@ -413,39 +379,36 @@ public void IsValidDeploymentItemShouldReportWarningIfDeploymentOutputDirectoryI
warning);
}
- [TestMethod]
public void IsValidDeploymentItemShouldReturnTrueForAValidDeploymentItem()
{
- Assert.IsTrue(DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, _defaultDeploymentItemOutputDirectory, out var warning));
+ Verify(DeploymentItemUtility.IsValidDeploymentItem(_defaultDeploymentItemPath, _defaultDeploymentItemOutputDirectory, out var warning));
- Assert.IsTrue(string.Empty.Equals(warning));
+ Verify(string.Empty.Equals(warning));
}
#endregion
#region HasDeployItems tests
- [TestMethod]
public void HasDeployItemsShouldReturnFalseForNoDeploymentItems()
{
TestCase testCase = new("A.C.M", new System.Uri("executor://testExecutor"), "A");
testCase.SetPropertyValue(DeploymentItemsProperty, null);
- Assert.IsFalse(DeploymentItemUtility.HasDeploymentItems(testCase));
+ Verify(!DeploymentItemUtility.HasDeploymentItems(testCase));
}
- [TestMethod]
public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent()
{
TestCase testCase = new("A.C.M", new System.Uri("executor://testExecutor"), "A");
var kvpArray = new[]
- {
- new KeyValuePair(
- _defaultDeploymentItemPath,
- _defaultDeploymentItemOutputDirectory)
- };
+ {
+ new KeyValuePair(
+ _defaultDeploymentItemPath,
+ _defaultDeploymentItemOutputDirectory)
+ };
testCase.SetPropertyValue(DeploymentItemsProperty, kvpArray);
- Assert.IsTrue(DeploymentItemUtility.HasDeploymentItems(testCase));
+ Verify(DeploymentItemUtility.HasDeploymentItems(testCase));
}
#endregion
@@ -454,18 +417,18 @@ public void HasDeployItemsShouldReturnTrueWhenDeploymentItemsArePresent()
private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems)
{
- var deploymentItemAttributes = new List();
+ var deploymentItemAttributes = new List();
foreach (var deploymentItem in deploymentItems)
{
- deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
+ deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
}
_mockReflectionUtility.Setup(
ru =>
ru.GetCustomAttributes(
memberInfo,
- typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
+ typeof(DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
}
#endregion
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs
index f0c662548b..de62f8e1a9 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/Utilities/ns13ReflectionUtilityTests.cs
@@ -3,25 +3,17 @@
namespace MSTestAdapter.PlatformServices.Tests.Utilities;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
-[TestClass]
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // File name must match first type name
-public class ReflectionUtilityTests
+public class ReflectionUtilityTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
private readonly ReflectionUtility _reflectionUtility;
@@ -31,173 +23,161 @@ public ReflectionUtilityTests()
_reflectionUtility = new ReflectionUtility();
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributes()
{
- var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, false);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : base", "DummySingleA : base" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : base", "DummySingleA : base" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, false);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummySingleA : derived" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, true);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(3, attribs.Length);
+ Verify(attributes is not null);
+ Verify(3 == attributes.Length);
// Notice that the DummySingleA on the base method does not show up since it can only be defined once.
- var expectedAttribs = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummySingleA : derived", "DummyA : base", };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributes()
{
- var tinfo = typeof(DummyBaseTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyBaseTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(tinfo, false);
+ var attributes = ReflectionUtility.GetCustomAttributes(typeInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var tinfo = typeof(DummyTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(tinfo, false);
+ var attributes = ReflectionUtility.GetCustomAttributes(typeInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetTypeInfo();
+ var methodInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, true);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a", "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributes()
{
- var minfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyBaseTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : base" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : base" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), false);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(DummyTestClass).GetMethod("DummyVTestMethod1");
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : derived", "DummyA : base", };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : derived", "DummyA : base", };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributes()
{
- var tinfo = typeof(DummyBaseTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyBaseTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false);
+ var attributes = ReflectionUtility.GetCustomAttributes(typeInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesIgnoringBaseInheritance()
{
- var tinfo = typeof(DummyTestClass).GetTypeInfo();
+ var typeInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(tinfo, typeof(DummyAAttribute), false);
+ var attributes = ReflectionUtility.GetCustomAttributes(typeInfo, typeof(DummyAAttribute), false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnTypeShouldReturnAllAttributesWithBaseInheritance()
{
- var minfo = typeof(DummyTestClass).GetTypeInfo();
+ var methodInfo = typeof(DummyTestClass).GetTypeInfo();
- var attribs = ReflectionUtility.GetCustomAttributes(minfo, typeof(DummyAAttribute), true);
+ var attributes = ReflectionUtility.GetCustomAttributes(methodInfo, typeof(DummyAAttribute), true);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a", "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a", "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
internal static string[] GetAttributeValuePairs(object[] attributes)
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13ThreadSafeStringWriterTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13ThreadSafeStringWriterTests.cs
index d00c58189f..a7a9eb0642 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13ThreadSafeStringWriterTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13ThreadSafeStringWriterTests.cs
@@ -3,35 +3,21 @@
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests.Execution;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-using UnitTestOutcome = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
-#endif
-
using System;
using System.Diagnostics;
using System.Globalization;
+using System.Linq;
using System.Threading;
using System.Threading.Tasks;
-using FluentAssertions;
+
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-[TestClass]
-public class ThreadSafeStringWriterTests
+using TestFramework.ForTestingMSTest;
+
+public class ThreadSafeStringWriterTests : TestContainer
{
private bool _task2flag;
- [TestMethod]
public void ThreadSafeStringWriterWritesLinesFromDifferentTasksSeparately()
{
// Suppress the flow of parent context here because this test method will run in
@@ -77,18 +63,19 @@ public void ThreadSafeStringWriterWritesLinesFromDifferentTasksSeparately()
// there was no output in the current task, the output should be empty
var content = stringWriter.ToString();
- content.Should().BeNullOrWhiteSpace();
+ Verify(string.IsNullOrWhiteSpace(content));
// task1 and task2 should output into their respective buckets
- task1Output.Should().NotBeNullOrWhiteSpace();
- task2Output.Should().NotBeNullOrWhiteSpace();
+ Verify(!string.IsNullOrWhiteSpace(task1Output));
+ Verify(!string.IsNullOrWhiteSpace(task2Output));
- task1Output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Should().OnlyContain(i => i == "content1").And.HaveCount(8);
- task2Output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries).Should().OnlyContain(i => i == "content2").And.HaveCount(8);
+ var task1Split = task1Output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ Verify(task1Split.SequenceEqual(Enumerable.Repeat("content1", 8)));
+ var task2Split = task2Output.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
+ Verify(task2Split.SequenceEqual(Enumerable.Repeat("content2", 8)));
}
}
- [TestMethod]
public void ThreadSafeStringWriterWritesLinesIntoDifferentWritesSeparately()
{
// Suppress the flow of parent context here becuase this test method will run in
@@ -120,14 +107,14 @@ public void ThreadSafeStringWriterWritesLinesIntoDifferentWritesSeparately()
}).GetAwaiter().GetResult();
// task1 and task2 should output into their respective buckets
- result.Out.Should().NotBeNullOrWhiteSpace();
- result.Debug.Should().NotBeNullOrWhiteSpace();
+ Verify(!string.IsNullOrWhiteSpace(result.Out));
+ Verify(!string.IsNullOrWhiteSpace(result.Debug));
var output = result.Out.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- output.Should().OnlyContain(i => i == "out").And.HaveCount(2);
+ Verify(output.SequenceEqual(new[] { "out", "out" }));
var debug = result.Debug.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
- debug.Should().OnlyContain(i => i == "debug").And.HaveCount(2);
+ Verify(debug.SequenceEqual(new[] { "debug", "debug" }));
}
}
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs
index 9bd9179ecc..77f7f036ba 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerManagerTests.cs
@@ -3,30 +3,19 @@
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using TestUtilities;
+
+using TestFramework.ForTestingMSTest;
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
-[TestClass]
-public class TraceListenerManagerTests
+public class TraceListenerManagerTests : TestContainer
{
#if !WIN_UI
- [TestMethod]
public void AddShouldAddTraceListenerToListOfTraceListeners()
{
var stringWriter = new StringWriter();
@@ -37,11 +26,10 @@ public void AddShouldAddTraceListenerToListOfTraceListeners()
traceListenerManager.Add(traceListener);
var newCount = Trace.Listeners.Count;
- Assert.AreEqual(originalCount + 1, newCount);
- Assert.IsTrue(Trace.Listeners.Contains(traceListener));
+ Verify(originalCount + 1 == newCount);
+ Verify(Trace.Listeners.Contains(traceListener));
}
- [TestMethod]
public void RemoveShouldRemoveTraceListenerFromListOfTraceListeners()
{
var stringWriter = new StringWriter();
@@ -55,12 +43,11 @@ public void RemoveShouldRemoveTraceListenerFromListOfTraceListeners()
traceListenerManager.Remove(traceListener);
var countAfterRemoving = Trace.Listeners.Count;
- Assert.AreEqual(originalCount + 1, countAfterAdding);
- Assert.AreEqual(countAfterAdding - 1, countAfterRemoving);
- Assert.IsFalse(Trace.Listeners.Contains(traceListener));
+ Verify(originalCount + 1 == countAfterAdding);
+ Verify(countAfterAdding - 1 == countAfterRemoving);
+ Verify(!Trace.Listeners.Contains(traceListener));
}
- [TestMethod]
public void DisposeShouldCallDisposeOnCorrespondingTraceListener()
{
var stringWriter = new StringWriter();
@@ -73,7 +60,8 @@ public void DisposeShouldCallDisposeOnCorrespondingTraceListener()
// Trying to write after closing textWriter should throw exception
void shouldThrowException() => writer.WriteLine("Try to write something");
- ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(ObjectDisposedException));
+ var ex = VerifyThrows(shouldThrowException);
+ Verify(ex is ObjectDisposedException);
}
#endif
}
diff --git a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs
index fb6795e747..a0e0c9ae66 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.3/ns13TraceListenerTests.cs
@@ -3,38 +3,26 @@
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#endif
-
using System;
using System.IO;
using System.Text;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using TestUtilities;
+
+using TestFramework.ForTestingMSTest;
#pragma warning disable SA1649 // SA1649FileNameMustMatchTypeName
-[TestClass]
-public class TraceListenerTests
+public class TraceListenerTests : TestContainer
{
#if !WIN_UI
- [TestMethod]
public void GetWriterShouldReturnInitializedWriter()
{
StringWriter writer = new(new StringBuilder("DummyTrace"));
var traceListener = new TraceListenerWrapper(writer);
var returnedWriter = traceListener.GetWriter();
- Assert.AreEqual("DummyTrace", returnedWriter.ToString());
+ Verify("DummyTrace" == returnedWriter.ToString());
}
- [TestMethod]
public void DisposeShouldDisposeCorrespondingTextWriter()
{
StringWriter writer = new(new StringBuilder("DummyTrace"));
@@ -43,7 +31,8 @@ public void DisposeShouldDisposeCorrespondingTextWriter()
// Trying to write after disposing textWriter should throw exception
void shouldThrowException() => writer.WriteLine("Try to write something");
- ActionUtility.ActionShouldThrowExceptionOfType(shouldThrowException, typeof(ObjectDisposedException));
+ var ex = VerifyThrows(shouldThrowException);
+ Verify(ex is ObjectDisposedException);
}
#endif
}
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/AssemblyResolverTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/AssemblyResolverTests.cs
index 5295e60948..b2165788fd 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/AssemblyResolverTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/AssemblyResolverTests.cs
@@ -4,25 +4,18 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
using System;
using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class AssemblyResolverTests
+public class AssemblyResolverTests : TestContainer
{
- [TestMethod]
public void AddSubDirectoriesShouldReturnSubDirectoriesInDfsOrder()
{
// Arrange.
@@ -63,12 +56,11 @@ public void AddSubDirectoriesShouldReturnSubDirectoriesInDfsOrder()
assemblyResolver.AddSubdirectories(path, searchDirectories);
// Assert.
- Assert.AreEqual(4, searchDirectories.Count, "searchDirectories should have only 5 elements");
+ Verify(4 == searchDirectories.Count);
- CollectionAssert.AreEqual(resultDirectories, searchDirectories, StringComparer.OrdinalIgnoreCase);
+ Verify(resultDirectories.SequenceEqual(searchDirectories, StringComparer.OrdinalIgnoreCase));
}
- [TestMethod]
public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis()
{
int count = 0;
@@ -112,37 +104,37 @@ public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis()
{
// First time SearchAssemblyInTheFollowingLocation should get call with one directory which is in
// m_searchDirectories variable
- Assert.AreEqual(1, listPath.Count);
- Assert.AreEqual(0, string.Compare(listPath[0], dummyDirectories[0], true));
+ Verify(1 == listPath.Count);
+ Verify(0 == string.Compare(listPath[0], dummyDirectories[0], true));
count++;
}
else if (count == 1)
{
// Second time SearchAssemblyInTheFollowingLocation should get call with directory C:\unitTesting
// and with all its sub directory, as its isRecursive property is true
- Assert.AreEqual(3, listPath.Count);
- Assert.AreEqual(0, string.Compare(listPath[0], @"C:\unitTesting", true));
- Assert.AreEqual(0, string.Compare(listPath[1], @"C:\unitTesting\a", true));
- Assert.AreEqual(0, string.Compare(listPath[2], @"C:\unitTesting\b", true));
+ Verify(3 == listPath.Count);
+ Verify(0 == string.Compare(listPath[0], @"C:\unitTesting", true));
+ Verify(0 == string.Compare(listPath[1], @"C:\unitTesting\a", true));
+ Verify(0 == string.Compare(listPath[2], @"C:\unitTesting\b", true));
count++;
}
else if (count == 2)
{
// Third time SearchAssemblyInTheFollowingLocation should get call with directory C:\FunctionalTesting
// as its isRecursive property is false
- Assert.AreEqual(1, listPath.Count);
- Assert.AreEqual(0, string.Compare(listPath[0], @"C:\FunctionalTesting", true));
+ Verify(1 == listPath.Count);
+ Verify(0 == string.Compare(listPath[0], @"C:\FunctionalTesting", true));
count++;
}
else if (count == 3)
{
// call will come here when we will call onResolve second time.
- Assert.AreEqual(5, listPath.Count);
- Assert.AreEqual(0, string.Compare(listPath[0], dummyDirectories[0], true));
- Assert.AreEqual(0, string.Compare(listPath[1], @"C:\unitTesting", true));
- Assert.AreEqual(0, string.Compare(listPath[2], @"C:\unitTesting\a", true));
- Assert.AreEqual(0, string.Compare(listPath[3], @"C:\unitTesting\b", true));
- Assert.AreEqual(0, string.Compare(listPath[4], @"C:\FunctionalTesting", true));
+ Verify(5 == listPath.Count);
+ Verify(0 == string.Compare(listPath[0], dummyDirectories[0], true));
+ Verify(0 == string.Compare(listPath[1], @"C:\unitTesting", true));
+ Verify(0 == string.Compare(listPath[2], @"C:\unitTesting\a", true));
+ Verify(0 == string.Compare(listPath[3], @"C:\unitTesting\b", true));
+ Verify(0 == string.Compare(listPath[4], @"C:\FunctionalTesting", true));
count++;
}
@@ -157,7 +149,6 @@ public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis()
assemblyResolver.OnResolve(null, dummyArgs);
}
- [TestMethod]
public void ReflectionOnlyOnResolveShouldNotReturnACachedDefaultLoadedAssembly()
{
var currentAssembly = typeof(AssemblyResolverTests).Assembly;
@@ -185,8 +176,8 @@ public void ReflectionOnlyOnResolveShouldNotReturnACachedDefaultLoadedAssembly()
// Simulate loading the assembly in default context first.
assemblyResolver.OnResolve(null, new ResolveEventArgs(currentAssembly.FullName));
- Assert.IsTrue(isAssemblyLoaded);
- Assert.IsFalse(isAssemblyReflectionOnlyLoaded);
+ Verify(isAssemblyLoaded);
+ Verify(!isAssemblyReflectionOnlyLoaded);
// Reset.
isAssemblyLoaded = false;
@@ -195,8 +186,8 @@ public void ReflectionOnlyOnResolveShouldNotReturnACachedDefaultLoadedAssembly()
assemblyResolver.ReflectionOnlyOnResolve(null, new ResolveEventArgs(currentAssembly.FullName));
// The below assertions ensure that a cached version is not returned out because it actually Reflection only loads the assembly.
- Assert.IsFalse(isAssemblyLoaded);
- Assert.IsTrue(isAssemblyReflectionOnlyLoaded);
+ Verify(!isAssemblyLoaded);
+ Verify(isAssemblyReflectionOnlyLoaded);
}
}
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs
index 7773f8b746..76bb9f4953 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Deployment/AssemblyLoadWorkerTests.cs
@@ -4,11 +4,9 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Deployment;
-extern alias FrameworkV1;
-
using System;
-using System.Collections.Generic;
using System.IO;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
@@ -16,15 +14,10 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Deployment;
using Moq;
-using Assert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1.Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class AssemblyLoadWorkerTests
+public class AssemblyLoadWorkerTests : TestContainer
{
- [TestMethod]
public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkAssembly()
{
// Arrange.
@@ -45,11 +38,10 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkAssembly()
var dependentAssemblies = worker.GetFullPathToDependentAssemblies("C:\\temp\\test3424.dll", out var warnings);
// Assert.
- var utfassembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
- CollectionAssert.Contains(dependentAssemblies, utfassembly);
+ var utfAssembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
+ Verify(dependentAssemblies.Contains(utfAssembly));
}
- [TestMethod]
public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkReferencedInADependency()
{
// Arrange.
@@ -105,11 +97,11 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkReferencedInA
var dependentAssemblies = worker.GetFullPathToDependentAssemblies("C:\\temp\\test3424.dll", out var warnings);
// Assert.
- var utfassembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
- CollectionAssert.Contains(dependentAssemblies, utfassembly);
+ var utfAssembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
+ Verify(dependentAssemblies.Contains(utfAssembly));
}
-#region Testable Implementations
+ #region Testable Implementations
private class TestableAssembly : Assembly
{
@@ -182,6 +174,6 @@ public override Module[] GetModules(bool getResourceModules)
}
}
-#endregion
+ #endregion
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/PlatformServices.Unit.Tests.csproj b/test/UnitTests/PlatformServices.Unit.Tests/PlatformServices.Unit.Tests.csproj
index 940006e64b..03123e8968 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/PlatformServices.Unit.Tests.csproj
+++ b/test/UnitTests/PlatformServices.Unit.Tests/PlatformServices.Unit.Tests.csproj
@@ -24,30 +24,20 @@
$(DefineConstants);WIN_UI
-
-
- $(MSBuildExtensionsPath)\..\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
-
-
-
-
+
-
+
+
-
-
-
-
-
+
-
@@ -58,7 +48,6 @@
-
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopFileOperationsTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopFileOperationsTests.cs
index 5d10c90281..c5edf16642 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopFileOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopFileOperationsTests.cs
@@ -4,8 +4,6 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-extern alias FrameworkV1;
-
using System;
using System.IO;
using System.Reflection;
@@ -13,36 +11,28 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Services;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopFileOperationsTests
+public class DesktopFileOperationsTests : TestContainer
{
- private FileOperations _fileOperations;
+ private readonly FileOperations _fileOperations;
- [TestInitialize]
- public void TestInit()
+ public DesktopFileOperationsTests()
{
_fileOperations = new FileOperations();
}
- [TestMethod]
- public void CreateNavigationSessionShouldReurnNullIfSourceIsNull()
+ public void CreateNavigationSessionShouldReturnNullIfSourceIsNull()
{
- Assert.IsNull(_fileOperations.CreateNavigationSession(null));
+ Verify(_fileOperations.CreateNavigationSession(null) is null);
}
- [TestMethod]
public void CreateNavigationSessionShouldReturnDiaSession()
{
var diaSession = _fileOperations.CreateNavigationSession(Assembly.GetExecutingAssembly().Location);
- Assert.IsTrue(diaSession is DiaSession);
+ Verify(diaSession is DiaSession);
}
- [TestMethod]
public void GetNavigationDataShouldReturnDataFromNavigationSession()
{
var diaSession = _fileOperations.CreateNavigationSession(Assembly.GetExecutingAssembly().Location);
@@ -53,11 +43,10 @@ public void GetNavigationDataShouldReturnDataFromNavigationSession()
out var minLineNumber,
out var fileName);
- Assert.AreNotEqual(-1, minLineNumber);
- Assert.IsNotNull(fileName);
+ Verify(-1 != minLineNumber);
+ Verify(fileName is not null);
}
- [TestMethod]
public void GetNavigationDataShouldNotThrowOnNullNavigationSession()
{
_fileOperations.GetNavigationData(
@@ -67,11 +56,10 @@ public void GetNavigationDataShouldNotThrowOnNullNavigationSession()
out var minLineNumber,
out var fileName);
- Assert.AreEqual(-1, minLineNumber);
- Assert.IsNull(fileName);
+ Verify(-1 == minLineNumber);
+ Verify(fileName is null);
}
- [TestMethod]
public void DisposeNavigationSessionShouldDisposeNavigationSessionInstance()
{
var session = _fileOperations.CreateNavigationSession(Assembly.GetExecutingAssembly().Location);
@@ -90,46 +78,40 @@ public void DisposeNavigationSessionShouldDisposeNavigationSessionInstance()
isExceptionThrown = true;
}
- Assert.IsTrue(isExceptionThrown);
+ Verify(isExceptionThrown);
}
- [TestMethod]
public void DisposeNavigationSessionShouldNotThrowOnNullNavigationSession()
{
// This should not throw.
_fileOperations.DisposeNavigationSession(null);
}
- [TestMethod]
public void DoesFileExistReturnsFalseIfAssemblyNameIsNull()
{
- Assert.IsFalse(_fileOperations.DoesFileExist(null));
+ Verify(!_fileOperations.DoesFileExist(null));
}
- [TestMethod]
public void DoesFileExistReturnsFalseIfFileDoesNotExist()
{
- Assert.IsFalse(_fileOperations.DoesFileExist("C:\\temp1foobar.txt"));
+ Verify(!_fileOperations.DoesFileExist("C:\\temp1foobar.txt"));
}
- [TestMethod]
public void DoesFileExistReturnsTrueIfFileExists()
{
- Assert.IsTrue(_fileOperations.DoesFileExist(Assembly.GetExecutingAssembly().Location));
+ Verify(_fileOperations.DoesFileExist(Assembly.GetExecutingAssembly().Location));
}
- [TestMethod]
public void GetFullFilePathShouldReturnAssemblyFileNameOnException()
{
var filePath = "temp<>txt";
- Assert.AreEqual(filePath, _fileOperations.GetFullFilePath(filePath));
+ Verify(filePath == _fileOperations.GetFullFilePath(filePath));
}
- [TestMethod]
public void GetFullFilePathShouldReturnFullFilePathForAFile()
{
var filePath = "temp1.txt";
- Assert.AreEqual(Path.GetFullPath(filePath), _fileOperations.GetFullFilePath(filePath));
+ Verify(Path.GetFullPath(filePath) == _fileOperations.GetFullFilePath(filePath));
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopReflectionOperationsTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopReflectionOperationsTests.cs
index 05922df40b..0478cc801f 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopReflectionOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopReflectionOperationsTests.cs
@@ -4,22 +4,17 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-extern alias FrameworkV1;
-
using System;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using MSTestAdapter.PlatformServices.UnitTests.Utilities;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopReflectionOperationsTests
+public class DesktopReflectionOperationsTests : TestContainer
{
private readonly ReflectionOperations _reflectionOperations;
@@ -28,46 +23,43 @@ public DesktopReflectionOperationsTests()
_reflectionOperations = new ReflectionOperations();
}
- [TestMethod]
public void GetCustomAttributesShouldReturnAllAttributes()
{
- var minfo = typeof(ReflectionUtilityTests.DummyBaseTestClass).GetMethod("DummyVTestMethod1");
+ var methodInfo = typeof(ReflectionUtilityTests.DummyBaseTestClass).GetMethod("DummyVTestMethod1");
- var attribs = _reflectionOperations.GetCustomAttributes(minfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(methodInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : base", "DummySingleA : base" };
- CollectionAssert.AreEqual(expectedAttribs, ReflectionUtilityTests.GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : base", "DummySingleA : base" };
+ Verify(expectedAttributes.SequenceEqual(ReflectionUtilityTests.GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetCustomAttributesOnTypeShouldReturnAllAttributes()
{
- var tinfo = typeof(ReflectionUtilityTests.DummyBaseTestClass).GetTypeInfo();
+ var typeInfo = typeof(ReflectionUtilityTests.DummyBaseTestClass).GetTypeInfo();
- var attribs = _reflectionOperations.GetCustomAttributes(tinfo, false);
+ var attributes = _reflectionOperations.GetCustomAttributes(typeInfo, false);
- Assert.IsNotNull(attribs);
- Assert.AreEqual(1, attribs.Length);
+ Verify(attributes is not null);
+ Verify(1 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : ba" };
- CollectionAssert.AreEqual(expectedAttribs, ReflectionUtilityTests.GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : ba" };
+ Verify(expectedAttributes.SequenceEqual(ReflectionUtilityTests.GetAttributeValuePairs(attributes)));
}
- [TestMethod]
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
{
var asm = typeof(ReflectionUtilityTests.DummyTestClass).Assembly;
- var attribs = _reflectionOperations.GetCustomAttributes(asm, typeof(ReflectionUtilityTests.DummyAAttribute));
+ var attributes = _reflectionOperations.GetCustomAttributes(asm, typeof(ReflectionUtilityTests.DummyAAttribute));
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" };
- CollectionAssert.AreEqual(expectedAttribs, ReflectionUtilityTests.GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a1", "DummyA : a2" };
+ Verify(expectedAttributes.SequenceEqual(ReflectionUtilityTests.GetAttributeValuePairs(attributes)));
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDataSourceTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDataSourceTests.cs
index b03c552b33..d01993f42f 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDataSourceTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDataSourceTests.cs
@@ -4,52 +4,43 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-extern alias FrameworkV2Extension;
-
using System.Collections.Generic;
using System.Data;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using DesktopTestFrameworkV2 = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestFrameworkV2 = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
+
+using ITestMethod = Microsoft.VisualStudio.TestTools.UnitTesting.ITestMethod;
-[TestClass]
-public class DesktopTestDataSourceTests
+public class DesktopTestDataSourceTests : TestContainer
{
- private Mock _mockTestMethodInfo;
- private Mock _testMethod;
- private IDictionary _properties;
- private Mock _mockTestContext;
+ private readonly Mock _mockTestMethodInfo;
+ private readonly Mock _testMethod;
+ private readonly IDictionary _properties;
+ private readonly Mock _mockTestContext;
- [TestInitialize]
- public void TestInit()
+ public DesktopTestDataSourceTests()
{
_testMethod = new Mock();
_properties = new Dictionary();
- _mockTestMethodInfo = new Mock();
+ _mockTestMethodInfo = new Mock();
_mockTestContext = new Mock();
}
- [TestMethod]
public void GetDataShouldReadDataFromGivenDataSource()
{
var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest");
- TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new(
- "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);
+ DataSourceAttribute dataSourceAttribute = new(
+ "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", DataAccessMethod.Sequential);
- _mockTestMethodInfo.Setup(ds => ds.GetAttributes(false))
- .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });
+ _mockTestMethodInfo.Setup(ds => ds.GetAttributes(false))
+ .Returns(new DataSourceAttribute[] { dataSourceAttribute });
_mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);
TestDataSource testDataSource = new();
@@ -57,19 +48,18 @@ public void GetDataShouldReadDataFromGivenDataSource()
foreach (DataRow dataRow in dataRows)
{
- Assert.AreEqual("v1", dataRow[3]);
+ Verify("v1".Equals(dataRow[3]));
}
}
- [TestMethod]
public void GetDataShouldSetDataConnectionInTestContextObject()
{
var methodInfo = typeof(DummyTestClass).GetMethod("PassingTest");
- TestFrameworkV2.DataSourceAttribute dataSourceAttribute = new(
- "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", TestFrameworkV2.DataAccessMethod.Sequential);
+ DataSourceAttribute dataSourceAttribute = new(
+ "Microsoft.VisualStudio.TestTools.DataSource.XML", "DataTestSourceFile.xml", "settings", DataAccessMethod.Sequential);
- _mockTestMethodInfo.Setup(ds => ds.GetAttributes(false))
- .Returns(new TestFrameworkV2.DataSourceAttribute[] { dataSourceAttribute });
+ _mockTestMethodInfo.Setup(ds => ds.GetAttributes(false))
+ .Returns(new DataSourceAttribute[] { dataSourceAttribute });
_mockTestMethodInfo.Setup(ds => ds.MethodInfo).Returns(methodInfo);
TestDataSource testDataSource = new();
@@ -82,26 +72,26 @@ public void GetDataShouldSetDataConnectionInTestContextObject()
public class DummyTestClass
{
- private DesktopTestFrameworkV2.TestContext _testContextInstance;
+ private TestContext _testContextInstance;
- public DesktopTestFrameworkV2.TestContext TestContext
+ public TestContext TestContext
{
get { return _testContextInstance; }
set { _testContextInstance = value; }
}
- [TestFrameworkV2.TestMethod]
+ [TestMethod]
public void PassingTest()
{
- Assert.AreEqual("v1", _testContextInstance.DataRow["adapter"].ToString());
- Assert.AreEqual("x86", _testContextInstance.DataRow["targetPlatform"].ToString());
+ Verify("v1" == _testContextInstance.DataRow["adapter"].ToString());
+ Verify("x86" == _testContextInstance.DataRow["targetPlatform"].ToString());
TestContext.AddResultFile("C:\\temp.txt");
}
- [TestFrameworkV2.TestMethod]
+ [TestMethod]
public void FailingTest()
{
- Assert.AreEqual("Release", _testContextInstance.DataRow["configuration"].ToString());
+ Verify("Release" == _testContextInstance.DataRow["configuration"].ToString());
}
}
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDeploymentTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDeploymentTests.cs
index 3b870ab54d..72487b8c93 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDeploymentTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestDeploymentTests.cs
@@ -4,10 +4,6 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-extern alias FrameworkV2Extension;
-
using System.Collections.Generic;
using System.IO;
using System.Reflection;
@@ -17,32 +13,25 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Services;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
using Microsoft.VisualStudio.TestPlatform.ObjectModel;
using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter;
+using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using MSTestAdapter.PlatformServices.Tests.Utilities;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using Ignore = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.IgnoreAttribute;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestFrameworkV2Extension = FrameworkV2Extension::Microsoft.VisualStudio.TestTools.UnitTesting;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopTestDeploymentTests
+public class DesktopTestDeploymentTests : TestContainer
{
private const string DefaultDeploymentItemPath = @"c:\temp";
private const string DefaultDeploymentItemOutputDirectory = "out";
- private Mock _mockReflectionUtility;
- private Mock _mockFileUtility;
+ private readonly Mock _mockReflectionUtility;
+ private readonly Mock _mockFileUtility;
private IList _warnings;
- [TestInitialize]
- public void TestInit()
+ public DesktopTestDeploymentTests()
{
_mockReflectionUtility = new Mock();
_mockFileUtility = new Mock();
@@ -52,9 +41,8 @@ public void TestInit()
MSTestSettingsProvider.Reset();
}
-#region Deploy tests
+ #region Deploy tests
- [TestMethod]
public void DeployShouldDeployFilesInASourceAndReturnTrue()
{
var testCase = GetTestCase(Assembly.GetExecutingAssembly().Location);
@@ -65,7 +53,7 @@ public void DeployShouldDeployFilesInASourceAndReturnTrue()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
string warning;
var sourceFile = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
@@ -78,7 +66,6 @@ public void DeployShouldDeployFilesInASourceAndReturnTrue()
Times.Once);
}
- [TestMethod]
public void DeployShouldDeployFilesInMultipleSourcesAndReturnTrue()
{
var testCase1 = GetTestCase(Assembly.GetExecutingAssembly().Location);
@@ -91,7 +78,7 @@ public void DeployShouldDeployFilesInMultipleSourcesAndReturnTrue()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase1, testCase2 }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase1, testCase2 }, mockRunContext.Object, new Mock().Object));
string warning;
var sourceFile1 = Assembly.GetExecutingAssembly().GetName().Name + ".dll";
@@ -111,7 +98,6 @@ public void DeployShouldDeployFilesInMultipleSourcesAndReturnTrue()
Times.Once);
}
- [TestMethod]
public void DeployShouldCreateDeploymentDirectories()
{
var testCase = GetTestCase(typeof(DesktopTestDeploymentTests).GetTypeInfo().Assembly.Location);
@@ -122,30 +108,30 @@ public void DeployShouldCreateDeploymentDirectories()
var mockRunContext = new Mock();
mockRunContext.Setup(rc => rc.TestRunDirectory).Returns(testRunDirectories.RootDeploymentDirectory);
- Assert.IsTrue(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
+ Verify(testDeployment.Deploy(new List { testCase }, mockRunContext.Object, new Mock().Object));
// matched twice because root deployment and out directory are same in net core
_mockFileUtility.Verify(fu => fu.CreateDirectoryIfNotExists(testRunDirectories.RootDeploymentDirectory), Times.Once);
}
-#endregion
+ #endregion
-#region private methods
+ #region private methods
private void SetupDeploymentItems(MemberInfo memberInfo, KeyValuePair[] deploymentItems)
{
- var deploymentItemAttributes = new List();
+ var deploymentItemAttributes = new List();
foreach (var deploymentItem in deploymentItems)
{
- deploymentItemAttributes.Add(new TestFrameworkV2Extension.DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
+ deploymentItemAttributes.Add(new DeploymentItemAttribute(deploymentItem.Key, deploymentItem.Value));
}
_mockReflectionUtility.Setup(
ru =>
ru.GetCustomAttributes(
memberInfo,
- typeof(TestFrameworkV2Extension.DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
+ typeof(DeploymentItemAttribute))).Returns((object[])deploymentItemAttributes.ToArray());
}
private TestCase GetTestCase(string source)
@@ -187,7 +173,7 @@ private TestDeployment CreateAndSetupDeploymentRelatedUtilities(out TestRunDirec
new DeploymentUtility(deploymentItemUtility, mockAssemblyUtility.Object, _mockFileUtility.Object),
_mockFileUtility.Object);
}
-#endregion
+ #endregion
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceHostTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceHostTests.cs
index cbe412d0cd..0a94d543d8 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceHostTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceHostTests.cs
@@ -4,9 +4,6 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
using System;
using System.Collections.Generic;
using System.IO;
@@ -20,14 +17,10 @@ namespace MSTestAdapter.PlatformServices.UnitTests;
using Moq;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopTestSourceHostTests
+public class DesktopTestSourceHostTests : TestContainer
{
- [TestMethod]
public void GetResolutionPathsShouldAddPublicAndPrivateAssemblyPath()
{
// Setup
@@ -40,16 +33,15 @@ public void GetResolutionPathsShouldAddPublicAndPrivateAssemblyPath()
// Assert
if (!string.IsNullOrWhiteSpace(VSInstallationUtilities.PathToPublicAssemblies))
{
- Assert.IsTrue(result.Contains(VSInstallationUtilities.PathToPublicAssemblies));
+ Verify(result.Contains(VSInstallationUtilities.PathToPublicAssemblies));
}
if (!string.IsNullOrWhiteSpace(VSInstallationUtilities.PathToPrivateAssemblies))
{
- Assert.IsTrue(result.Contains(VSInstallationUtilities.PathToPrivateAssemblies));
+ Verify(result.Contains(VSInstallationUtilities.PathToPrivateAssemblies));
}
}
- [TestMethod]
public void GetResolutionPathsShouldNotAddPublicAndPrivateAssemblyPathInPortableMode()
{
// Setup
@@ -60,11 +52,10 @@ public void GetResolutionPathsShouldNotAddPublicAndPrivateAssemblyPathInPortable
List result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: true);
// Assert
- Assert.IsFalse(result.Contains(VSInstallationUtilities.PathToPublicAssemblies));
- Assert.IsFalse(result.Contains(VSInstallationUtilities.PathToPrivateAssemblies));
+ Verify(!result.Contains(VSInstallationUtilities.PathToPublicAssemblies));
+ Verify(!result.Contains(VSInstallationUtilities.PathToPrivateAssemblies));
}
- [TestMethod]
public void GetResolutionPathsShouldAddAdapterFolderPath()
{
// Setup
@@ -74,10 +65,9 @@ public void GetResolutionPathsShouldAddAdapterFolderPath()
List result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: false);
// Assert
- Assert.IsFalse(result.Contains(typeof(TestSourceHost).Assembly.Location));
+ Verify(!result.Contains(typeof(TestSourceHost).Assembly.Location));
}
- [TestMethod]
public void GetResolutionPathsShouldAddTestPlatformFolderPath()
{
// Setup
@@ -87,15 +77,14 @@ public void GetResolutionPathsShouldAddTestPlatformFolderPath()
List result = sut.GetResolutionPaths("DummyAssembly.dll", isPortableMode: false);
// Assert
- Assert.IsFalse(result.Contains(typeof(AssemblyHelper).Assembly.Location));
+ Verify(!result.Contains(typeof(AssemblyHelper).Assembly.Location));
}
- [TestMethod]
public void CreateInstanceForTypeShouldCreateTheTypeInANewAppDomain()
{
// Setup
- DummyClass dummyclass = new();
- int currentAppDomainId = dummyclass.AppDomainId;
+ DummyClass dummyClass = new();
+ int currentAppDomainId = dummyClass.AppDomainId;
TestSourceHost sut = new(Assembly.GetExecutingAssembly().Location, null, null);
sut.SetupHost();
@@ -109,14 +98,13 @@ public void CreateInstanceForTypeShouldCreateTheTypeInANewAppDomain()
}
// Assert
- Assert.AreNotEqual(currentAppDomainId, newAppDomainId);
+ Verify(currentAppDomainId != newAppDomainId);
}
- [TestMethod]
public void SetupHostShouldSetChildDomainsAppBaseToTestSourceLocation()
{
// Arrange
- DummyClass dummyclass = new();
+ DummyClass dummyClass = new();
var location = typeof(TestSourceHost).Assembly.Location;
Mock sourceHost = new(location, null, null) { CallBase = true };
@@ -128,7 +116,7 @@ public void SetupHostShouldSetChildDomainsAppBaseToTestSourceLocation()
var expectedObject = sourceHost.Object.CreateInstanceForType(typeof(DummyClass), null) as DummyClass;
// Assert
- Assert.AreEqual(Path.GetDirectoryName(typeof(DesktopTestSourceHostTests).Assembly.Location), expectedObject.AppDomainAppBase);
+ Verify(Path.GetDirectoryName(typeof(DesktopTestSourceHostTests).Assembly.Location) == expectedObject.AppDomainAppBase);
}
finally
{
@@ -136,15 +124,14 @@ public void SetupHostShouldSetChildDomainsAppBaseToTestSourceLocation()
}
}
- [TestMethod]
public void SetupHostShouldHaveParentDomainsAppBaseSetToTestSourceLocation()
{
// Arrange
- DummyClass dummyclass = new();
+ DummyClass dummyClass = new();
string runSettingxml =
@"
- True
+ False
";
@@ -152,28 +139,27 @@ public void SetupHostShouldHaveParentDomainsAppBaseSetToTestSourceLocation()
var mockRunSettings = new Mock();
mockRunSettings.Setup(rs => rs.SettingsXml).Returns(runSettingxml);
- Mock sourceHost = new(location, mockRunSettings.Object, null) { CallBase = true };
+ TestSourceHost sourceHost = new(location, mockRunSettings.Object, null);
try
{
// Act
- sourceHost.Object.SetupHost();
- var expectedObject = sourceHost.Object.CreateInstanceForType(typeof(DummyClass), null) as DummyClass;
+ sourceHost.SetupHost();
+ var expectedObject = sourceHost.CreateInstanceForType(typeof(DummyClass), null) as DummyClass;
// Assert
- Assert.AreEqual(Path.GetDirectoryName(typeof(DesktopTestSourceHostTests).Assembly.Location), expectedObject.AppDomainAppBase);
+ Verify(Path.GetDirectoryName(typeof(DesktopTestSourceHostTests).Assembly.Location) == expectedObject.AppDomainAppBase);
}
finally
{
- sourceHost.Object.Dispose();
+ sourceHost.Dispose();
}
}
- [TestMethod]
public void SetupHostShouldSetResolutionsPaths()
{
// Arrange
- DummyClass dummyclass = new();
+ DummyClass dummyClass = new();
var location = typeof(TestSourceHost).Assembly.Location;
Mock sourceHost = new(location, null, null) { CallBase = true };
@@ -192,7 +178,6 @@ public void SetupHostShouldSetResolutionsPaths()
}
}
- [TestMethod]
public void DisposeShouldSetTestHostShutdownOnIssueWithAppDomainUnload()
{
// Arrange
@@ -211,11 +196,10 @@ public void DisposeShouldSetTestHostShutdownOnIssueWithAppDomainUnload()
frameworkHandle.VerifySet(fh => fh.EnableShutdownAfterTestRun = true);
}
- [TestMethod]
public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue()
{
// Arrange
- DummyClass dummyclass = new();
+ DummyClass dummyClass = new();
string runSettingxml =
@"
@@ -233,7 +217,7 @@ public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue()
{
// Act
testSourceHost.Object.SetupHost();
- Assert.IsNull(testSourceHost.Object.AppDomain);
+ Verify(testSourceHost.Object.AppDomain is null);
}
finally
{
@@ -241,11 +225,10 @@ public void NoAppDomainShouldGetCreatedWhenDisableAppDomainIsSetToTrue()
}
}
- [TestMethod]
public void AppDomainShouldGetCreatedWhenDisableAppDomainIsSetToFalse()
{
// Arrange
- DummyClass dummyclass = new();
+ DummyClass dummyClass = new();
string runSettingxml =
@"
@@ -263,7 +246,7 @@ public void AppDomainShouldGetCreatedWhenDisableAppDomainIsSetToFalse()
{
// Act
testSourceHost.Object.SetupHost();
- Assert.IsNotNull(testSourceHost.Object.AppDomain);
+ Verify(testSourceHost.Object.AppDomain is not null);
}
finally
{
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceTests.cs
index 84b69cd82c..ddc4dfbcf9 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopTestSourceTests.cs
@@ -4,71 +4,55 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopTestSourceTests
+public class DesktopTestSourceTests : TestContainer
{
private TestSource _testSource;
- [TestInitialize]
- public void TestInit()
+ public DesktopTestSourceTests()
{
_testSource = new TestSource();
}
- [TestMethod]
public void ValidSourceExtensionsShouldContainDllExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".dll");
+ Verify(_testSource.ValidSourceExtensions.Contains(".dll"));
}
- [TestMethod]
public void ValidSourceExtensionsShouldContainExeExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".exe");
+ Verify(_testSource.ValidSourceExtensions.ToList().Contains(".exe"));
}
- [TestMethod]
public void ValidSourceExtensionsShouldContainAppxExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".appx");
+ Verify(_testSource.ValidSourceExtensions.Contains(".appx"));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfAssemblyNameIsNull()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(null, "DummySource"));
+ Verify(_testSource.IsAssemblyReferenced(null, "DummySource"));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfSourceIsNull()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(Assembly.GetExecutingAssembly().GetName(), null));
+ Verify(_testSource.IsAssemblyReferenced(Assembly.GetExecutingAssembly().GetName(), null));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfAnAssemblyIsReferencedInSource()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(typeof(FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).Assembly.GetName(), Assembly.GetExecutingAssembly().Location));
+ Verify(_testSource.IsAssemblyReferenced(typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).Assembly.GetName(), Assembly.GetExecutingAssembly().Location));
}
- [TestMethod]
public void IsAssemblyReferencedShouldReturnFalseIfAnAssemblyIsNotReferencedInSource()
{
- Assert.IsFalse(_testSource.IsAssemblyReferenced(new AssemblyName("foobar"), Assembly.GetExecutingAssembly().Location));
+ Verify(!_testSource.IsAssemblyReferenced(new AssemblyName("foobar"), Assembly.GetExecutingAssembly().Location));
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopThreadOperationsTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopThreadOperationsTests.cs
index c3ab12bb20..a4cb5ec617 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopThreadOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/DesktopThreadOperationsTests.cs
@@ -4,22 +4,15 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-extern alias FrameworkV1;
-
using System;
using System.Reflection;
using System.Threading;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using MSTestAdapter.TestUtilities;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class DesktopThreadOperationsTests
+public class DesktopThreadOperationsTests : TestContainer
{
private readonly ThreadOperations _asyncOperations;
@@ -28,7 +21,6 @@ public DesktopThreadOperationsTests()
_asyncOperations = new ThreadOperations();
}
- [TestMethod]
public void ExecuteShouldRunActionOnANewThread()
{
int actionThreadID = 0;
@@ -38,11 +30,10 @@ void action()
actionThreadID = Environment.CurrentManagedThreadId;
}
- Assert.IsTrue(_asyncOperations.Execute(action, 1000, cancellationTokenSource.Token));
- Assert.AreNotEqual(Environment.CurrentManagedThreadId, actionThreadID);
+ Verify(_asyncOperations.Execute(action, 1000, cancellationTokenSource.Token));
+ Verify(Environment.CurrentManagedThreadId != actionThreadID);
}
- [TestMethod]
public void ExecuteShouldKillTheThreadExecutingAsyncOnTimeout()
{
ManualResetEvent timeoutMutex = new(false);
@@ -71,16 +62,15 @@ void action()
}
}
- Assert.IsFalse(_asyncOperations.Execute(action, 1, cancellationTokenSource.Token));
+ Verify(!_asyncOperations.Execute(action, 1, cancellationTokenSource.Token));
timeoutMutex.Set();
actionCompleted.WaitOne();
- Assert.IsFalse(hasReachedEnd, "Execution Completed successfully");
- Assert.IsTrue(isThreadAbortThrown, "ThreadAbortException not thrown");
+ Verify(!hasReachedEnd, "Execution Completed successfully");
+ Verify(isThreadAbortThrown, "ThreadAbortException not thrown");
}
- [TestMethod]
- public void ExecuteShouldSpwanOfAthreadWithSpecificAttributes()
+ public void ExecuteShouldSpawnThreadWithSpecificAttributes()
{
var name = string.Empty;
var apartmentState = ApartmentState.Unknown;
@@ -93,26 +83,24 @@ void action()
isBackground = Thread.CurrentThread.IsBackground;
}
- Assert.IsTrue(_asyncOperations.Execute(action, 100, cancellationTokenSource.Token));
+ Verify(_asyncOperations.Execute(action, 100, cancellationTokenSource.Token));
- Assert.AreEqual("MSTestAdapter Thread", name);
- Assert.AreEqual(Thread.CurrentThread.GetApartmentState(), apartmentState);
- Assert.IsTrue(isBackground);
+ Verify("MSTestAdapter Thread" == name);
+ Verify(Thread.CurrentThread.GetApartmentState() == apartmentState);
+ Verify(isBackground);
}
- [TestMethod]
public void ExecuteWithAbortSafetyShouldCatchThreadAbortExceptionsAndResetAbort()
{
static void action() => Thread.CurrentThread.Abort();
- var exception = ActionUtility.PerformActionAndReturnException(() => _asyncOperations.ExecuteWithAbortSafety(action));
+ var exception = VerifyThrows(() => _asyncOperations.ExecuteWithAbortSafety(action));
- Assert.IsNotNull(exception);
- Assert.AreEqual(typeof(TargetInvocationException), exception.GetType());
- Assert.AreEqual(typeof(ThreadAbortException), exception.InnerException.GetType());
+ Verify(exception is not null);
+ Verify(typeof(TargetInvocationException) == exception.GetType());
+ Verify(typeof(ThreadAbortException) == exception.InnerException.GetType());
}
- [TestMethod]
public void TokenCancelShouldAbortExecutingAction()
{
// setup
@@ -123,11 +111,10 @@ public void TokenCancelShouldAbortExecutingAction()
var result = _asyncOperations.Execute(() => { Thread.Sleep(10000); }, 100000, cancellationTokenSource.Token);
// validate
- Assert.IsFalse(result, "The execution failed to abort");
+ Verify(!result, "The execution failed to abort");
}
- [TestMethod]
- public void TokenCancelShouldAbortIfAlreadycanceled()
+ public void TokenCancelShouldAbortIfAlreadyCanceled()
{
// setup
var cancellationTokenSource = new CancellationTokenSource();
@@ -137,7 +124,7 @@ public void TokenCancelShouldAbortIfAlreadycanceled()
var result = _asyncOperations.Execute(() => { Thread.Sleep(10000); }, 100000, cancellationTokenSource.Token);
// validate
- Assert.IsFalse(result, "The execution failed to abort");
+ Verify(!result, "The execution failed to abort");
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Services/TestContextImplementationTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Services/TestContextImplementationTests.cs
index 769e29067f..f8104464c0 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Services/TestContextImplementationTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Services/TestContextImplementationTests.cs
@@ -4,61 +4,40 @@
#if !NET48
namespace MSTestAdapter.PlatformServices.UnitTests.Services;
-#if NETCOREAPP
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#else
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using StringAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.StringAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-using UnitTestOutcome = FrameworkV2::Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
-#endif
-
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
-using System.IO;
-using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;
using Moq;
-using MSTestAdapter.TestUtilities;
+using UnitTestOutcome = Microsoft.VisualStudio.TestTools.UnitTesting.UnitTestOutcome;
using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class TestContextImplementationTests
+public class TestContextImplementationTests : TestContainer
{
- private Mock _testMethod;
+ private readonly Mock _testMethod;
- private IDictionary _properties;
+ private readonly IDictionary _properties;
private TestContextImplementation _testContextImplementation;
- [TestInitialize]
- public void TestInit()
+ public TestContextImplementationTests()
{
_testMethod = new Mock();
_properties = new Dictionary();
}
- [TestMethod]
public void TestContextConstructorShouldInitializeProperties()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Properties);
+ Verify(_testContextImplementation.Properties is not null);
}
- [TestMethod]
public void TestContextConstructorShouldInitializeDefaultProperties()
{
_testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
@@ -66,55 +45,46 @@ public void TestContextConstructorShouldInitializeDefaultProperties()
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Properties);
+ Verify(_testContextImplementation.Properties is not null);
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("FullyQualifiedTestClassName", "A.C.M"));
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("TestName", "M"));
+ Verify(_testContextImplementation.Properties["FullyQualifiedTestClassName"].Equals("A.C.M"));
+ Verify(_testContextImplementation.Properties["TestName"].Equals("M"));
}
- [TestMethod]
public void CurrentTestOutcomeShouldReturnDefaultOutcome()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual(UnitTestOutcome.Failed, _testContextImplementation.CurrentTestOutcome);
+ Verify(UnitTestOutcome.Failed == _testContextImplementation.CurrentTestOutcome);
}
- [TestMethod]
public void CurrentTestOutcomeShouldReturnOutcomeSet()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
_testContextImplementation.SetOutcome(UnitTestOutcome.InProgress);
- Assert.AreEqual(UnitTestOutcome.InProgress, _testContextImplementation.CurrentTestOutcome);
+ Verify(UnitTestOutcome.InProgress == _testContextImplementation.CurrentTestOutcome);
}
- [TestMethod]
public void FullyQualifiedTestClassNameShouldReturnTestMethodsFullClassName()
{
_testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual("A.C.M", _testContextImplementation.FullyQualifiedTestClassName);
+ Verify("A.C.M" == _testContextImplementation.FullyQualifiedTestClassName);
}
- [TestMethod]
public void TestNameShouldReturnTestMethodsName()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.AreEqual("M", _testContextImplementation.TestName);
+ Verify("M" == _testContextImplementation.TestName);
}
- [TestMethod]
public void PropertiesShouldReturnPropertiesPassedToTestContext()
{
var property1 = new KeyValuePair("IntProperty", 1);
@@ -125,78 +95,70 @@ public void PropertiesShouldReturnPropertiesPassedToTestContext()
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- CollectionAssert.Contains(_testContextImplementation.Properties, property1);
- CollectionAssert.Contains(_testContextImplementation.Properties, property2);
+ Verify(_testContextImplementation.Properties[property1.Key] == property1.Value);
+ Verify(_testContextImplementation.Properties[property2.Key] == property2.Value);
}
- [TestMethod]
public void ContextShouldReturnTestContextObject()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsNotNull(_testContextImplementation.Context);
- Assert.AreEqual("M", _testContextImplementation.Context.TestName);
+ Verify(_testContextImplementation.Context is not null);
+ Verify("M" == _testContextImplementation.Context.TestName);
}
- [TestMethod]
public void TryGetPropertyValueShouldReturnTrueIfPropertyIsPresent()
{
_testMethod.Setup(tm => tm.Name).Returns("M");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsTrue(_testContextImplementation.TryGetPropertyValue("TestName", out var propValue));
- Assert.AreEqual("M", propValue);
+ Verify(_testContextImplementation.TryGetPropertyValue("TestName", out var propValue));
+ Verify("M".Equals(propValue));
}
- [TestMethod]
public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- Assert.IsFalse(_testContextImplementation.TryGetPropertyValue("Random", out var propValue));
- Assert.IsNull(propValue);
+ Verify(!_testContextImplementation.TryGetPropertyValue("Random", out var propValue));
+ Verify(propValue is null);
}
- [TestMethod]
public void AddPropertyShouldAddPropertiesToThePropertyBag()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
- _testContextImplementation.AddProperty("SomeNewProperty", "SomeValue");
+ var property = new KeyValuePair("SomeNewProperty", "SomeValue");
+ _testContextImplementation.AddProperty(property.Key, property.Value);
- CollectionAssert.Contains(
- _testContextImplementation.Properties,
- new KeyValuePair("SomeNewProperty", "SomeValue"));
+ Verify(_testContextImplementation.Properties[property.Key].Equals(property.Value));
}
#if !WIN_UI
- [TestMethod]
public void AddResultFileShouldThrowIfFileNameIsNull()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
var exception =
- ActionUtility.PerformActionAndReturnException(() => _testContextImplementation.AddResultFile(null));
+ VerifyThrows(() => _testContextImplementation.AddResultFile(null));
- Assert.AreEqual(typeof(ArgumentException), exception.GetType());
- StringAssert.Contains(exception.Message, Resource.Common_CannotBeNullOrEmpty);
+ Verify(typeof(ArgumentException) == exception.GetType());
+ Verify(exception.Message.Contains(Resource.Common_CannotBeNullOrEmpty));
}
- [TestMethod]
public void AddResultFileShouldThrowIfFileNameIsEmpty()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
var exception =
- ActionUtility.PerformActionAndReturnException(() => _testContextImplementation.AddResultFile(string.Empty));
+ VerifyThrows(() => _testContextImplementation.AddResultFile(string.Empty));
- Assert.AreEqual(typeof(ArgumentException), exception.GetType());
- StringAssert.Contains(exception.Message, Resource.Common_CannotBeNullOrEmpty);
+ Verify(typeof(ArgumentException) == exception.GetType());
+ Verify(exception.Message.Contains(Resource.Common_CannotBeNullOrEmpty));
}
- [TestMethod]
public void AddResultFileShouldAddFileToResultsFiles()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -205,10 +167,9 @@ public void AddResultFileShouldAddFileToResultsFiles()
var resultsFiles = _testContextImplementation.GetResultFiles();
- CollectionAssert.Contains(resultsFiles.ToList(), "C:\\temp.txt");
+ Verify(resultsFiles.Contains("C:\\temp.txt"));
}
- [TestMethod]
public void AddResultFileShouldAddMultipleFilesToResultsFiles()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -218,30 +179,27 @@ public void AddResultFileShouldAddMultipleFilesToResultsFiles()
var resultsFiles = _testContextImplementation.GetResultFiles();
- CollectionAssert.Contains(resultsFiles.ToList(), "C:\\files\\file1.txt");
- CollectionAssert.Contains(resultsFiles.ToList(), "C:\\files\\files2.html");
+ Verify(resultsFiles.Contains("C:\\files\\file1.txt"));
+ Verify(resultsFiles.Contains("C:\\files\\files2.html"));
}
#endif
- [TestMethod]
public void WriteShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("{0} Testing write", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("{0} Testing \0 write \0", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -253,25 +211,22 @@ public void WriteShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.Write("{0} Testing write", 1);
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("1 Testing write");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
_testContextImplementation = new TestContextImplementation(_testMethod.Object, stringWriter, _properties);
_testContextImplementation.Write("1 Testing \0 write \0");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteWithMessageShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -283,7 +238,6 @@ public void WriteWithMessageShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.Write("1 Testing write");
}
- [TestMethod]
public void WriteWithMessageShouldWriteToStringWriterForReturnCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -293,7 +247,6 @@ public void WriteWithMessageShouldWriteToStringWriterForReturnCharacters()
Equals(stringWriter.ToString(), "2 Testing write 3 Testing write");
}
- [TestMethod]
public void WriteLineShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -301,10 +254,9 @@ public void WriteLineShouldWriteToStringWriter()
_testContextImplementation.WriteLine("{0} Testing write", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteLineShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -312,10 +264,9 @@ public void WriteLineShouldWriteToStringWriterForNullCharacters()
_testContextImplementation.WriteLine("{0} Testing \0 write \0", 1);
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteLineShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -329,7 +280,6 @@ public void WriteLineShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.WriteLine("{0} Testing write", 1);
}
- [TestMethod]
public void WriteLineWithMessageShouldWriteToStringWriter()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -337,10 +287,9 @@ public void WriteLineWithMessageShouldWriteToStringWriter()
_testContextImplementation.WriteLine("1 Testing write");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing write");
+ Verify(stringWriter.ToString().Contains("1 Testing write"));
}
- [TestMethod]
public void WriteLineWithMessageShouldWriteToStringWriterForNullCharacters()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -348,10 +297,9 @@ public void WriteLineWithMessageShouldWriteToStringWriterForNullCharacters()
_testContextImplementation.WriteLine("1 Testing \0 write \0");
- StringAssert.Contains(stringWriter.ToString(), "1 Testing \\0 write \\0");
+ Verify(stringWriter.ToString().Contains("1 Testing \\0 write \\0"));
}
- [TestMethod]
public void WriteLineWithMessageShouldNotThrowIfStringWriterIsDisposed()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -365,7 +313,6 @@ public void WriteLineWithMessageShouldNotThrowIfStringWriterIsDisposed()
_testContextImplementation.WriteLine("1 Testing write");
}
- [TestMethod]
public void GetDiagnosticMessagesShouldReturnMessagesFromWriteLine()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -373,11 +320,10 @@ public void GetDiagnosticMessagesShouldReturnMessagesFromWriteLine()
_testContextImplementation.WriteLine("1 Testing write");
_testContextImplementation.WriteLine("2 Its a happy day");
- StringAssert.Contains(_testContextImplementation.GetDiagnosticMessages(), "1 Testing write");
- StringAssert.Contains(_testContextImplementation.GetDiagnosticMessages(), "2 Its a happy day");
+ Verify(_testContextImplementation.GetDiagnosticMessages().Contains("1 Testing write"));
+ Verify(_testContextImplementation.GetDiagnosticMessages().Contains("2 Its a happy day"));
}
- [TestMethod]
public void ClearDiagnosticMessagesShouldClearMessagesFromWriteLine()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -388,11 +334,10 @@ public void ClearDiagnosticMessagesShouldClearMessagesFromWriteLine()
_testContextImplementation.ClearDiagnosticMessages();
- Assert.AreEqual(string.Empty, stringWriter.ToString());
+ Verify(string.Empty == stringWriter.ToString());
}
#if NETFRAMEWORK
- [TestMethod]
public void SetDataRowShouldSetDataRowObjectForCurrentRun()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -408,11 +353,10 @@ public void SetDataRowShouldSetDataRowObjectForCurrentRun()
_testContextImplementation.SetDataRow(dataTable.Select()[0]);
- Assert.AreEqual(2, _testContextImplementation.DataRow.ItemArray[0]);
- Assert.AreEqual("Hello", _testContextImplementation.DataRow.ItemArray[1]);
+ Verify(2.Equals(_testContextImplementation.DataRow.ItemArray[0]));
+ Verify("Hello".Equals(_testContextImplementation.DataRow.ItemArray[1]));
}
- [TestMethod]
public void SetDataConnectionShouldSetDbConnectionForFetchingData()
{
var stringWriter = new ThreadSafeStringWriter(null, "test");
@@ -424,23 +368,22 @@ public void SetDataConnectionShouldSetDbConnectionForFetchingData()
_testContextImplementation.SetDataConnection(connection);
- Assert.AreEqual("Dsn=Excel Files;dbq=.\\data.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5", _testContextImplementation.DataConnection.ConnectionString);
+ Verify("Dsn=Excel Files;dbq=.\\data.xls;defaultdir=.; driverid=790;maxbuffersize=2048;pagetimeout=5"
+ == _testContextImplementation.DataConnection.ConnectionString);
}
#endif
#if NETCOREAPP
- [TestMethod]
public void GetResultFilesShouldReturnNullIfNoAddedResultFiles()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
var resultFiles = _testContextImplementation.GetResultFiles();
- Assert.IsNull(resultFiles, "No added result files");
+ Verify(resultFiles is null);
}
#if WIN_UI
- [TestMethod]
public void GetResultFilesShouldAlwaysReturnNull()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -450,10 +393,9 @@ public void GetResultFilesShouldAlwaysReturnNull()
var resultFiles = _testContextImplementation.GetResultFiles();
- Assert.IsNull(resultFiles, "No added result files");
+ Verify(resultFiles is null);
}
#else
- [TestMethod]
public void GetResultFilesShouldReturnListOfAddedResultFiles()
{
_testContextImplementation = new TestContextImplementation(_testMethod.Object, new ThreadSafeStringWriter(null, "test"), _properties);
@@ -463,9 +405,9 @@ public void GetResultFilesShouldReturnListOfAddedResultFiles()
var resultFiles = _testContextImplementation.GetResultFiles();
- Assert.IsTrue(resultFiles.Count > 0, "GetResultFiles returned added elements");
- CollectionAssert.Contains(resultFiles.ToList(), "C:\\files\\myfile.txt");
- CollectionAssert.Contains(resultFiles.ToList(), "C:\\files\\myfile2.txt");
+ Verify(resultFiles.Count > 0, "GetResultFiles returned added elements");
+ Verify(resultFiles.Contains("C:\\files\\myfile.txt"));
+ Verify(resultFiles.Contains("C:\\files\\myfile2.txt"));
}
#endif
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/AppDomainUtilitiesTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/AppDomainUtilitiesTests.cs
index c30fdce0d5..22dac7fc11 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/AppDomainUtilitiesTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/AppDomainUtilitiesTests.cs
@@ -4,39 +4,32 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Utilities;
-extern alias FrameworkV1;
-
using System;
using System.Xml;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestCleanup = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestCleanupAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class AppDomainUtilitiesTests
+public class AppDomainUtilitiesTests : TestContainer
{
- private TestableXmlUtilities _testableXmlUtilities;
+ private readonly TestableXmlUtilities _testableXmlUtilities;
- [TestInitialize]
- public void TestInit()
+ public AppDomainUtilitiesTests()
{
_testableXmlUtilities = new TestableXmlUtilities();
AppDomainUtilities.XmlUtilities = _testableXmlUtilities;
}
- [TestCleanup]
- public void TestCleanup()
+ protected override void Dispose(bool disposing)
{
- AppDomainUtilities.XmlUtilities = null;
+ if (!IsDisposed)
+ {
+ base.Dispose(disposing);
+ AppDomainUtilities.XmlUtilities = null;
+ }
}
- [TestMethod]
public void SetConfigurationFileShouldSetOMRedirectionIfConfigFileIsPresent()
{
AppDomainSetup setup = new();
@@ -50,7 +43,7 @@ public void SetConfigurationFileShouldSetOMRedirectionIfConfigFileIsPresent()
AppDomainUtilities.SetConfigurationFile(setup, configFile);
// Assert Config file being set.
- Assert.AreEqual(configFile, setup.ConfigurationFile);
+ Verify(configFile == setup.ConfigurationFile);
// Assert Config Bytes.
var expectedRedir = "";
@@ -58,10 +51,9 @@ public void SetConfigurationFileShouldSetOMRedirectionIfConfigFileIsPresent()
var observedConfigBytes = setup.GetConfigurationBytes();
var observedXml = System.Text.Encoding.UTF8.GetString(observedConfigBytes);
- Assert.IsTrue(observedXml.Replace("\r\n", string.Empty).Replace(" ", string.Empty).Contains(expectedRedir.Replace(" ", string.Empty)), "Config must have OM redirection");
+ Verify(observedXml.Replace("\r\n", string.Empty).Replace(" ", string.Empty).Contains(expectedRedir.Replace(" ", string.Empty)), "Config must have OM redirection");
}
- [TestMethod]
public void SetConfigurationFileShouldSetToCurrentDomainsConfigFileIfSourceDoesNotHaveAConfig()
{
AppDomainSetup setup = new();
@@ -69,31 +61,29 @@ public void SetConfigurationFileShouldSetToCurrentDomainsConfigFileIfSourceDoesN
AppDomainUtilities.SetConfigurationFile(setup, null);
// Assert Config file being set.
- Assert.AreEqual(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, setup.ConfigurationFile);
+ Verify(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile == setup.ConfigurationFile);
- Assert.IsNull(setup.GetConfigurationBytes());
+ Verify(setup.GetConfigurationBytes() is null);
}
- [TestMethod]
public void GetTargetFrameworkVersionFromVersionStringShouldReturnDefaultVersionIfversionIsPortable()
{
var expected = new Version();
var version = AppDomainUtilities.GetTargetFrameworkVersionFromVersionString(".NETPortable,Version=v4.5,Profile=Profile259");
- Assert.AreEqual(expected.Major, version.Major);
- Assert.AreEqual(expected.Minor, version.Minor);
+ Verify(expected.Major == version.Major);
+ Verify(expected.Minor == version.Minor);
}
- [TestMethod]
public void GetTargetFrameworkVersionFromVersionStringShouldReturnCurrectVersion()
{
var expected = new Version("4.5");
var version = AppDomainUtilities.GetTargetFrameworkVersionFromVersionString(".NETFramework,Version=v4.5");
- Assert.AreEqual(expected.Major, version.Major);
- Assert.AreEqual(expected.Minor, version.Minor);
+ Verify(expected.Major == version.Major);
+ Verify(expected.Minor == version.Minor);
}
#region Testable Implementations
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DeploymentUtilityTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DeploymentUtilityTests.cs
index 5c48890bf6..15a5d48e29 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DeploymentUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DeploymentUtilityTests.cs
@@ -4,18 +4,6 @@
#if !NET48
namespace MSTestAdapter.PlatformServices.UnitTests.Utilities;
-#if NETFRAMEWORK
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
-#else
-using Microsoft.VisualStudio.TestTools.UnitTesting;
-#endif
-
using System;
using System.Collections.Generic;
using System.IO;
@@ -32,9 +20,10 @@ namespace MSTestAdapter.PlatformServices.UnitTests.Utilities;
using MSTestAdapter.PlatformServices.Tests.Utilities;
-[TestClass]
+using TestFramework.ForTestingMSTest;
+
#pragma warning disable SA1649 // File name must match first type name
-public class DeploymentUtilityTests
+public class DeploymentUtilityTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
private const string TestRunDirectory = "C:\\temp\\testRunDirectory";
@@ -42,17 +31,16 @@ public class DeploymentUtilityTests
private const string DefaultDeploymentItemPath = @"c:\temp";
private const string DefaultDeploymentItemOutputDirectory = "out";
- private Mock _mockReflectionUtility;
- private Mock _mockFileUtility;
- private Mock _mockAssemblyUtility;
- private Mock _mockRunContext;
- private Mock _mocktestExecutionRecorder;
+ private readonly Mock _mockReflectionUtility;
+ private readonly Mock _mockFileUtility;
+ private readonly Mock _mockAssemblyUtility;
+ private readonly Mock _mockRunContext;
+ private readonly Mock _mocktestExecutionRecorder;
- private DeploymentUtility _deploymentUtility;
+ private readonly DeploymentUtility _deploymentUtility;
private IList _warnings;
- [TestInitialize]
- public void TestInit()
+ public DeploymentUtilityTests()
{
_mockReflectionUtility = new Mock();
_mockFileUtility = new Mock();
@@ -70,7 +58,6 @@ public void TestInit()
#region Deploy tests
- [TestMethod]
public void DeployShouldReturnFalseWhenNoDeploymentItemsOnTestCase()
{
var testCase = new TestCase("A.C.M", new System.Uri("executor://testExecutor"), "A");
@@ -88,8 +75,8 @@ public void DeployShouldReturnFalseWhenNoDeploymentItemsOnTestCase()
.Returns(new List { });
#endif
- Assert.IsFalse(
- _deploymentUtility.Deploy(
+ Verify(
+ !_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
_mockRunContext.Object,
@@ -98,7 +85,6 @@ public void DeployShouldReturnFalseWhenNoDeploymentItemsOnTestCase()
}
#if NETFRAMEWORK
- [TestMethod]
public void DeployShouldDeploySourceAndItsConfigFile()
{
var testCase = GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out var testRunDirectories);
@@ -114,7 +100,7 @@ public void DeployShouldDeploySourceAndItsConfigFile()
.Returns(new List { });
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -142,7 +128,6 @@ public void DeployShouldDeploySourceAndItsConfigFile()
Times.Once);
}
- [TestMethod]
public void DeployShouldDeployDependentFiles()
{
var dependencyFile = "C:\\temp\\dependency.dll";
@@ -160,7 +145,7 @@ public void DeployShouldDeployDependentFiles()
.Returns(new List { });
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -180,7 +165,6 @@ public void DeployShouldDeployDependentFiles()
Times.Once);
}
- [TestMethod]
public void DeployShouldDeploySatelliteAssemblies()
{
var testCase = GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out var testRunDirectories);
@@ -198,7 +182,7 @@ public void DeployShouldDeploySatelliteAssemblies()
.Returns(new List { satelliteFullPath });
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -219,7 +203,6 @@ public void DeployShouldDeploySatelliteAssemblies()
}
#endif
- [TestMethod]
public void DeployShouldNotDeployIfOutputDirectoryIsInvalid()
{
var assemblyFullPath = Assembly.GetExecutingAssembly().Location;
@@ -241,7 +224,7 @@ public void DeployShouldNotDeployIfOutputDirectoryIsInvalid()
#endif
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -272,7 +255,6 @@ public void DeployShouldNotDeployIfOutputDirectoryIsInvalid()
Times.Once);
}
- [TestMethod]
public void DeployShouldDeployContentsOfADirectoryIfSpecified()
{
var assemblyFullPath = Assembly.GetExecutingAssembly().Location;
@@ -298,7 +280,7 @@ public void DeployShouldDeployContentsOfADirectoryIfSpecified()
fu => fu.AddFilesFromDirectory(DefaultDeploymentItemPath, It.IsAny>(), It.IsAny())).Returns(directoryContentFiles);
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -319,7 +301,6 @@ public void DeployShouldDeployContentsOfADirectoryIfSpecified()
}
#if NETFRAMEWORK
- [TestMethod]
public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory()
{
var testCase = GetTestCaseAndTestRunDirectories(DefaultDeploymentItemPath, DefaultDeploymentItemOutputDirectory, out var testRunDirectories);
@@ -343,7 +324,7 @@ public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory()
});
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
@@ -370,7 +351,6 @@ public void DeployShouldDeployPdbWithSourceIfPdbFileIsPresentInSourceDirectory()
Times.Once);
}
- [TestMethod]
public void DeployShouldNotDeployPdbFileOfAssemblyIfPdbFileIsNotPresentInAssemblyDirectory()
{
var dependencyFile = "C:\\temp\\dependency.dll";
@@ -399,7 +379,7 @@ public void DeployShouldNotDeployPdbFileOfAssemblyIfPdbFileIsNotPresentInAssembl
});
// Act.
- Assert.IsTrue(
+ Verify(
_deploymentUtility.Deploy(
new List { testCase },
testCase.Source,
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs
index 8e3d02ffac..6a52895c40 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/DesktopReflectionUtilityTests.cs
@@ -4,22 +4,17 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Utilities;
-extern alias FrameworkV1;
-
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
#pragma warning disable SA1649 // File name must match first type name
-public class ReflectionUtilityTests
+public class ReflectionUtilityTests : TestContainer
#pragma warning restore SA1649 // File name must match first type name
{
private readonly ReflectionUtility _reflectionUtility;
@@ -29,18 +24,17 @@ public ReflectionUtilityTests()
_reflectionUtility = new ReflectionUtility();
}
- [TestMethod]
public void GetSpecificCustomAttributesOnAssemblyShouldReturnAllAttributes()
{
var asm = typeof(DummyTestClass).GetTypeInfo().Assembly;
- var attribs = ReflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute));
+ var attributes = ReflectionUtility.GetCustomAttributes(asm, typeof(DummyAAttribute));
- Assert.IsNotNull(attribs);
- Assert.AreEqual(2, attribs.Length);
+ Verify(attributes is not null);
+ Verify(2 == attributes.Length);
- var expectedAttribs = new string[] { "DummyA : a1", "DummyA : a2" };
- CollectionAssert.AreEqual(expectedAttribs, GetAttributeValuePairs(attribs));
+ var expectedAttributes = new string[] { "DummyA : a1", "DummyA : a2" };
+ Verify(expectedAttributes.SequenceEqual(GetAttributeValuePairs(attributes)));
}
internal static string[] GetAttributeValuePairs(object[] attributes)
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/VSInstallationUtilitiesTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/VSInstallationUtilitiesTests.cs
index 08d6e4c384..a653d6ef38 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/VSInstallationUtilitiesTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/VSInstallationUtilitiesTests.cs
@@ -4,43 +4,20 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests;
-extern alias FrameworkV1;
-extern alias FrameworkV2;
-
-using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
-using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;
-using Assert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.Assert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using TestFramework.ForTestingMSTest;
-[TestClass]
-public class VSInstallationUtilitiesTests
+public class VSInstallationUtilitiesTests : TestContainer
{
- [TestMethod]
- public void CheckPortableModeRunningTest()
- {
- string path = Environment.GetEnvironmentVariable(Constants.PortableVsTestLocation);
- if (string.IsNullOrEmpty(path))
- {
- Assert.Inconclusive("This test required Portable vstest to be installed");
- }
- else
- {
- Assert.IsTrue(VSInstallationUtilities.IsProcessRunningInPortableMode(path));
- }
- }
-
- [TestMethod]
public void CheckResolutionPathsDoNotContainPrivateAssembliesPathTest()
{
TestSourceHost isolatedHost = new(null, null, null);
List paths = isolatedHost.GetResolutionPaths(Assembly.GetExecutingAssembly().FullName, true);
- Assert.IsFalse(paths.Contains(Constants.PublicAssemblies) || paths.Contains(Constants.PrivateAssemblies));
+ Verify(!paths.Contains(Constants.PublicAssemblies) || paths.Contains(Constants.PrivateAssemblies));
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/XmlUtilitiesTests.cs b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/XmlUtilitiesTests.cs
index 466870b6fa..a3595cfd04 100644
--- a/test/UnitTests/PlatformServices.Unit.Tests/Utilities/XmlUtilitiesTests.cs
+++ b/test/UnitTests/PlatformServices.Unit.Tests/Utilities/XmlUtilitiesTests.cs
@@ -4,31 +4,24 @@
#if NET462
namespace MSTestAdapter.PlatformServices.UnitTests.Utilities;
-extern alias FrameworkV1;
-
using System.IO;
+using System.Linq;
using System.Reflection;
using System.Xml;
-using static AppDomainUtilitiesTests;
+using TestFramework.ForTestingMSTest;
-using CollectionAssert = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.CollectionAssert;
-using TestClass = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute;
-using TestInitialize = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestInitializeAttribute;
-using TestMethod = FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute;
+using static AppDomainUtilitiesTests;
-[TestClass]
-public class XmlUtilitiesTests
+public class XmlUtilitiesTests : TestContainer
{
- private TestableXmlUtilities _testableXmlUtilities;
+ private readonly TestableXmlUtilities _testableXmlUtilities;
- [TestInitialize]
- public void TestInit()
+ public XmlUtilitiesTests()
{
_testableXmlUtilities = new TestableXmlUtilities();
}
- [TestMethod]
public void AddAssemblyRedirectionShouldAddRedirectionToAnEmptyXml()
{
_testableXmlUtilities.ConfigXml = @"";
@@ -53,10 +46,9 @@ public void AddAssemblyRedirectionShouldAddRedirectionToAnEmptyXml()
expectedConfigBytes = ms.ToArray();
}
- CollectionAssert.AreEqual(expectedConfigBytes, configBytes);
+ Verify(expectedConfigBytes.SequenceEqual(configBytes));
}
- [TestMethod]
public void AddAssemblyRedirectionShouldAddRedirectionToAnEmptyConfig()
{
_testableXmlUtilities.ConfigXml = @"
@@ -83,10 +75,9 @@ public void AddAssemblyRedirectionShouldAddRedirectionToAnEmptyConfig()
expectedConfigBytes = ms.ToArray();
}
- CollectionAssert.AreEqual(expectedConfigBytes, configBytes);
+ Verify(expectedConfigBytes.SequenceEqual(configBytes));
}
- [TestMethod]
public void AddAssemblyRedirectionShouldAddRedirectionToAConfigWithARuntimeSectionOnly()
{
_testableXmlUtilities.ConfigXml = @"
@@ -115,10 +106,9 @@ public void AddAssemblyRedirectionShouldAddRedirectionToAConfigWithARuntimeSecti
expectedConfigBytes = ms.ToArray();
}
- CollectionAssert.AreEqual(expectedConfigBytes, configBytes);
+ Verify(expectedConfigBytes.SequenceEqual(configBytes));
}
- [TestMethod]
public void AddAssemblyRedirectionShouldAddRedirectionToAConfigWithRedirections()
{
_testableXmlUtilities.ConfigXml = "";
@@ -143,7 +133,7 @@ public void AddAssemblyRedirectionShouldAddRedirectionToAConfigWithRedirections(
expectedConfigBytes = ms.ToArray();
}
- CollectionAssert.AreEqual(expectedConfigBytes, configBytes);
+ Verify(expectedConfigBytes.SequenceEqual(configBytes));
}
}
#endif
diff --git a/test/UnitTests/PlatformServices.Universal.Unit.Tests/PlatformServices.Universal.Unit.Tests.csproj b/test/UnitTests/PlatformServices.Universal.Unit.Tests/PlatformServices.Universal.Unit.Tests.csproj
index e875438d85..f8a934c30a 100644
--- a/test/UnitTests/PlatformServices.Universal.Unit.Tests/PlatformServices.Universal.Unit.Tests.csproj
+++ b/test/UnitTests/PlatformServices.Universal.Unit.Tests/PlatformServices.Universal.Unit.Tests.csproj
@@ -9,43 +9,22 @@
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.UWP.UnitTests
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.UWP.UnitTests
1685
- TRACE
- prompt
- 4
- true
full
- false
- $(DefineConstants);DEBUG;CODE_ANALYSIS
pdbonly
- true
-
-
- $(ArtifactsBinDir)PlatformServices\$(UwpMinimum)\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll
-
-
- $(ArtifactsBinDir)Extension\$(UwpMinimum)\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll
-
-
- $(MSBuildExtensionsPath)\..\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll
-
-
-
-
-
+
-
-
+
diff --git a/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalFileOperationsTests.cs b/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalFileOperationsTests.cs
index a0d2cf689d..19f2641c3f 100644
--- a/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalFileOperationsTests.cs
+++ b/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalFileOperationsTests.cs
@@ -3,27 +3,23 @@
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.UWP.UnitTests;
-extern alias FrameworkV1;
-
using System;
using System.IO;
using System.Reflection;
-using FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting;
-using global::MSTestAdapter.TestUtilities;
+
+using TestFramework.ForTestingMSTest;
///
/// The universal file operations tests.
///
-[TestClass]
-public class UniversalFileOperationsTests
+public class UniversalFileOperationsTests : TestContainer
{
- private FileOperations _fileOperations;
+ private readonly FileOperations _fileOperations;
///
/// The test initialization.
///
- [TestInitialize]
- public void TestInit()
+ public UniversalFileOperationsTests()
{
_fileOperations = new FileOperations();
}
@@ -31,29 +27,28 @@ public void TestInit()
///
/// The load assembly should throw exception if the file name has invalid characters.
///
- [TestMethod]
public void LoadAssemblyShouldThrowExceptionIfTheFileNameHasInvalidCharacters()
{
var filePath = "temp<>txt";
void a() => _fileOperations.LoadAssembly(filePath, false);
- ActionUtility.ActionShouldThrowExceptionOfType(a, typeof(ArgumentException));
+ var ex = VerifyThrows(a);
+ Verify(ex is ArgumentException);
}
///
/// The load assembly should throw exception if file is not found.
///
- [TestMethod]
public void LoadAssemblyShouldThrowExceptionIfFileIsNotFound()
{
var filePath = "temptxt";
void a() => _fileOperations.LoadAssembly(filePath, false);
- ActionUtility.ActionShouldThrowExceptionOfType(a, typeof(FileNotFoundException));
+ var ex = VerifyThrows(a);
+ Verify(ex is FileNotFoundException);
}
///
/// The load assembly should load assembly in current context.
///
- [TestMethod]
public void LoadAssemblyShouldLoadAssemblyInCurrentContext()
{
var filePath = Assembly.GetExecutingAssembly().Location;
@@ -65,11 +60,10 @@ public void LoadAssemblyShouldLoadAssemblyInCurrentContext()
///
/// The does file exist returns false if file name has invalid characters.
///
- [TestMethod]
public void DoesFileExistReturnsFalseIfFileNameHasInvalidCharacters()
{
var filePath = "temp<>txt";
- Assert.IsFalse(_fileOperations.DoesFileExist(filePath));
+ Verify(!_fileOperations.DoesFileExist(filePath));
}
/// This Test is not yet validated. Will validate with new adapter.
@@ -81,7 +75,8 @@ public void DoesFileExistReturnsFalseIfFileIsNotFound()
{
var filePath = "C:\\footemp.txt";
void a() => _fileOperations.DoesFileExist(filePath);
- ActionUtility.ActionShouldThrowExceptionOfType(a, typeof(FileNotFoundException));
+ var ex = VerifyThrows(a);
+ Verify(ex is FileNotFoundException);
}
/// This Test is not yet validated. Will validate with new adapter.
@@ -92,26 +87,24 @@ public void DoesFileExistReturnsFalseIfFileIsNotFound()
public void DoesFileExistReturnsTrueWhenFileExists()
{
var filePath = Assembly.GetExecutingAssembly().Location;
- Assert.IsTrue(_fileOperations.DoesFileExist(filePath));
+ Verify(_fileOperations.DoesFileExist(filePath));
}
///
/// The create navigation session should return null for all sources.
///
- [TestMethod]
- [Ignore] // TODO: Re-enable this tests when we have merged projects
- public void CreateNavigationSessionShouldReturnNullForAllSources()
+ // TODO: Re-enable this tests when we have merged projects (make public to re-include)
+ private void CreateNavigationSessionShouldReturnNullForAllSources()
{
- Assert.IsNull(_fileOperations.CreateNavigationSession(null));
- Assert.IsNull(_fileOperations.CreateNavigationSession("foobar"));
+ Verify(_fileOperations.CreateNavigationSession(null) is null);
+ Verify(_fileOperations.CreateNavigationSession("foobar") is null);
}
- [TestMethod]
public void GetNavigationDataShouldReturnNullFileName()
{
_fileOperations.GetNavigationData(null, null, null, out var minLineNumber, out var fileName);
- Assert.IsNull(fileName);
- Assert.AreEqual(-1, minLineNumber);
+ Verify(fileName is null);
+ Verify(-1 == minLineNumber);
}
// Enable these tests when we take dependency on TpV2 object model
@@ -168,10 +161,9 @@ public void DisposeNavigationSessionShouldNotThrowOnNullNavigationSession()
///
/// The get full file path should return assembly file name.
///
- [TestMethod]
public void GetFullFilePathShouldReturnAssemblyFileName()
{
- Assert.IsNull(_fileOperations.GetFullFilePath(null));
- Assert.AreEqual("assemblyFileName", _fileOperations.GetFullFilePath("assemblyFileName"));
+ Verify(_fileOperations.GetFullFilePath(null) is null);
+ Verify("assemblyFileName" == _fileOperations.GetFullFilePath("assemblyFileName"));
}
}
diff --git a/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalTestSourceTests.cs b/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalTestSourceTests.cs
index b552f8e4f7..3f06efcedf 100644
--- a/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalTestSourceTests.cs
+++ b/test/UnitTests/PlatformServices.Universal.Unit.Tests/Services/UniversalTestSourceTests.cs
@@ -3,25 +3,24 @@
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.UWP.UnitTests;
-extern alias FrameworkV1;
-
using System.Linq;
using System.Reflection;
-using FrameworkV1::Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using Microsoft.VisualStudio.TestTools.UnitTesting;
+
+using TestFramework.ForTestingMSTest;
///
/// The universal test source validator tests.
///
-[TestClass]
-public class UniversalTestSourceTests
+public class UniversalTestSourceTests : TestContainer
{
- private TestSource _testSource;
+ private readonly TestSource _testSource;
///
/// The test initialization.
///
- [TestInitialize]
- public void TestInit()
+ public UniversalTestSourceTests()
{
_testSource = new TestSource();
}
@@ -29,63 +28,56 @@ public void TestInit()
///
/// The valid source extensions should contain .dll as extension.
///
- [TestMethod]
public void ValidSourceExtensionsShouldContainDllExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".dll");
+ Verify(_testSource.ValidSourceExtensions.Contains(".dll"));
}
///
/// The valid source extensions should contain .exe as extension.
///
- [TestMethod]
public void ValidSourceExtensionsShouldContainExeExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".exe");
+ Verify(_testSource.ValidSourceExtensions.Contains(".exe"));
}
///
/// The valid source extensions should contain .appx as extension.
///
- [TestMethod]
public void ValidSourceExtensionsShouldContainAppxExtensions()
{
- CollectionAssert.Contains(_testSource.ValidSourceExtensions.ToList(), ".appx");
+ Verify(_testSource.ValidSourceExtensions.Contains(".appx"));
}
///
/// The is assembly referenced should return true if assembly name is null.
///
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfAssemblyNameIsNull()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(null, "DummySource"));
+ Verify(_testSource.IsAssemblyReferenced(null, "DummySource"));
}
///
/// The is assembly referenced should return true if source is null.
///
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfSourceIsNull()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(Assembly.GetExecutingAssembly().GetName(), null));
+ Verify(_testSource.IsAssemblyReferenced(Assembly.GetExecutingAssembly().GetName(), null));
}
///
/// The is assembly referenced should return true if an assembly is referenced in source.
///
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueIfAnAssemblyIsReferencedInSource()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(typeof(TestMethodAttribute).Assembly.GetName(), Assembly.GetExecutingAssembly().Location));
+ Verify(_testSource.IsAssemblyReferenced(typeof(TestMethodAttribute).Assembly.GetName(), Assembly.GetExecutingAssembly().Location));
}
///
/// The is assembly referenced should return false if an assembly is not referenced in source.
///
- [TestMethod]
public void IsAssemblyReferencedShouldReturnTrueForAllSourceOrAssemblyNames()
{
- Assert.IsTrue(_testSource.IsAssemblyReferenced(new AssemblyName("ReferenceAssembly"), "SourceAssembly"));
+ Verify(_testSource.IsAssemblyReferenced(new AssemblyName("ReferenceAssembly"), "SourceAssembly"));
}
}