Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert PlatformServices tests to use new test framework #1249

Merged
merged 1 commit into from
Sep 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions src/Adapter/PlatformServices/Constants.cs
Original file line number Diff line number Diff line change
@@ -19,11 +19,6 @@ internal class Constants

public const string TargetFrameworkName = "TargetFrameworkName";

/// <summary>
/// Constants for MSTest in Portable Mode
/// </summary>
public const string PortableVsTestLocation = "PortableVsTestLocation";

public const string PublicAssemblies = "PublicAssemblies";

public const string PrivateAssemblies = "PrivateAssemblies";
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Loading