Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;

using TestFramework.ForTestingMSTest;
Expand Down Expand Up @@ -50,9 +52,9 @@ public void AddSubDirectoriesShouldReturnSubDirectoriesInDfsOrder()
assemblyResolver.AddSubdirectories(path, searchDirectories);

// Assert.
Verify(searchDirectories.Count == 4);
searchDirectories.Count.Should().Be(4);

Verify(resultDirectories.SequenceEqual(searchDirectories, StringComparer.OrdinalIgnoreCase));
resultDirectories.SequenceEqual(searchDirectories, StringComparer.OrdinalIgnoreCase).Should().BeTrue();
}

public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis()
Expand Down Expand Up @@ -98,37 +100,37 @@ public void OnResolveShouldAddSearchDirectoryListOnANeedToBasis()
{
// First time SearchAssemblyInTheFollowingLocation should get call with one directory which is in
// m_searchDirectories variable
Verify(listPath.Count == 1);
Verify(string.Equals(listPath[0], dummyDirectories[0], StringComparison.OrdinalIgnoreCase));
listPath.Count.Should().Be(1);
string.Equals(listPath[0], dummyDirectories[0], StringComparison.OrdinalIgnoreCase).Should().BeTrue();
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
Verify(listPath.Count == 3);
Verify(string.Equals(listPath[0], @"C:\unitTesting", StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[1], @"C:\unitTesting\a", StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[2], @"C:\unitTesting\b", StringComparison.OrdinalIgnoreCase));
listPath.Count.Should().Be(3);
string.Equals(listPath[0], @"C:\unitTesting", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[1], @"C:\unitTesting\a", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[2], @"C:\unitTesting\b", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
count++;
}
else if (count == 2)
{
// Third time SearchAssemblyInTheFollowingLocation should get call with directory C:\FunctionalTesting
// as its isRecursive property is false
Verify(listPath.Count == 1);
Verify(string.Equals(listPath[0], @"C:\FunctionalTesting", StringComparison.OrdinalIgnoreCase));
listPath.Count.Should().Be(1);
string.Equals(listPath[0], @"C:\FunctionalTesting", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
count++;
}
else if (count == 3)
{
// call will come here when we will call onResolve second time.
Verify(listPath.Count == 5);
Verify(string.Equals(listPath[0], dummyDirectories[0], StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[1], @"C:\unitTesting", StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[2], @"C:\unitTesting\a", StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[3], @"C:\unitTesting\b", StringComparison.OrdinalIgnoreCase));
Verify(string.Equals(listPath[4], @"C:\FunctionalTesting", StringComparison.OrdinalIgnoreCase));
listPath.Count.Should().Be(5);
string.Equals(listPath[0], dummyDirectories[0], StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[1], @"C:\unitTesting", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[2], @"C:\unitTesting\a", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[3], @"C:\unitTesting\b", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
string.Equals(listPath[4], @"C:\FunctionalTesting", StringComparison.OrdinalIgnoreCase).Should().BeTrue();
count++;
}

Expand Down Expand Up @@ -170,8 +172,8 @@ public void ReflectionOnlyOnResolveShouldNotReturnACachedDefaultLoadedAssembly()
// Simulate loading the assembly in default context first.
assemblyResolver.OnResolve(null, new ResolveEventArgs(currentAssembly.FullName));

Verify(isAssemblyLoaded);
Verify(!isAssemblyReflectionOnlyLoaded);
isAssemblyLoaded.Should().BeTrue();
isAssemblyReflectionOnlyLoaded.Should().BeFalse();

// Reset.
isAssemblyLoaded = false;
Expand All @@ -180,8 +182,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.
Verify(!isAssemblyLoaded);
Verify(isAssemblyReflectionOnlyLoaded);
isAssemblyLoaded.Should().BeFalse();
isAssemblyReflectionOnlyLoaded.Should().BeTrue();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if NETFRAMEWORK
using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Utilities;

Expand Down Expand Up @@ -34,7 +36,7 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkAssembly()

// Assert.
string utfAssembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
Verify(dependentAssemblies.Contains(utfAssembly));
dependentAssemblies.Should().Contain(utfAssembly);
}

public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkReferencedInADependency()
Expand Down Expand Up @@ -93,7 +95,7 @@ public void GetFullPathToDependentAssembliesShouldReturnV1FrameworkReferencedInA

// Assert.
string utfAssembly = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll");
Verify(dependentAssemblies.Contains(utfAssembly));
dependentAssemblies.Should().Contain(utfAssembly);
}

#region Testable Implementations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Resources;

Expand All @@ -14,54 +16,54 @@ public void EqualsShouldReturnFalseIfOtherItemIsNull()
{
DeploymentItem item = new("e:\\temp\\temp1.dll");

Verify(!item.Equals(null));
item.Equals(null).Should().BeFalse();
}

public void EqualsShouldReturnFalseIfOtherItemIsNotDeploymentItem()
{
DeploymentItem item = new("e:\\temp\\temp1.dll");

Verify(!item.Equals(new DeploymentItemTests()));
item.Equals(new DeploymentItemTests()).Should().BeFalse();
}

public void EqualsShouldReturnFalseIfSourcePathIsDifferent()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll");
DeploymentItem item2 = new("e:\\temp\\temp2.dll");

Verify(!item1.Equals(item2));
item1.Equals(item2).Should().BeFalse();
}

public void EqualsShouldReturnFalseIfRelativeOutputDirectoryIsDifferent()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "foo2");

Verify(!item1.Equals(item2));
item1.Equals(item2).Should().BeFalse();
}

public void EqualsShouldReturnTrueIfSourcePathDiffersByCase()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll");
DeploymentItem item2 = new("e:\\temp\\Temp1.dll");

Verify(item1.Equals(item2));
item1.Equals(item2).Should().BeTrue();
}

public void EqualsShouldReturnTrueIfRelativeOutputDirectoryDiffersByCase()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "Foo1");

Verify(item1.Equals(item2));
item1.Equals(item2).Should().BeTrue();
}

public void EqualsShouldReturnTrueIfSourceAndRelativeOutputDirectoryAreSame()
{
DeploymentItem item1 = new("e:\\temp\\temp1.dll", "foo1");
DeploymentItem item2 = new("e:\\temp\\temp1.dll", "foo1");

Verify(item1.Equals(item2));
item1.Equals(item2).Should().BeTrue();
}

public void GetHashCodeShouldConsiderSourcePathAndRelativeOutputDirectory()
Expand All @@ -70,15 +72,15 @@ public void GetHashCodeShouldConsiderSourcePathAndRelativeOutputDirectory()
string relativeOutputDirectory = "foo1";
DeploymentItem item = new(sourcePath, relativeOutputDirectory);

Verify(sourcePath.GetHashCode() + relativeOutputDirectory.GetHashCode() == item.GetHashCode());
item.GetHashCode().Should().Be(sourcePath.GetHashCode() + relativeOutputDirectory.GetHashCode());
}

public void ToStringShouldReturnDeploymentItemIfRelativeOutputDirectoryIsNotSpecified()
{
string sourcePath = "e:\\temp\\temp1.dll";
DeploymentItem item = new(sourcePath);

Verify(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentItem, sourcePath) == item.ToString());
item.ToString().Should().Be(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentItem, sourcePath));
}

public void ToStringShouldReturnDeploymentItemAndRelativeOutputDirectory()
Expand All @@ -87,6 +89,6 @@ public void ToStringShouldReturnDeploymentItemAndRelativeOutputDirectory()
string relativeOutputDirectory = "foo1";
DeploymentItem item = new(sourcePath, relativeOutputDirectory);

Verify(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentItemWithOutputDirectory, sourcePath, relativeOutputDirectory) == item.ToString());
item.ToString().Should().Be(string.Format(CultureInfo.InvariantCulture, Resource.DeploymentItemWithOutputDirectory, sourcePath, relativeOutputDirectory));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Deployment;

using TestFramework.ForTestingMSTest;
Expand All @@ -11,9 +13,12 @@ public class TestRunDirectoriesTests : TestContainer
{
private readonly TestRunDirectories _testRunDirectories = new(@"C:\temp");

public void InDirectoryShouldReturnCorrectDirectory() => Verify(_testRunDirectories.InDirectory == @"C:\temp\In");
public void InDirectoryShouldReturnCorrectDirectory()
=> _testRunDirectories.InDirectory.Should().Be(@"C:\temp\In");

public void OutDirectoryShouldReturnCorrectDirectory() => Verify(_testRunDirectories.OutDirectory == @"C:\temp\Out");
public void OutDirectoryShouldReturnCorrectDirectory()
=> _testRunDirectories.OutDirectory.Should().Be(@"C:\temp\Out");

public void InMachineNameDirectoryShouldReturnMachineSpecificDeploymentDirectory() => Verify(Path.Combine(@"C:\temp\In", Environment.MachineName) == _testRunDirectories.InMachineNameDirectory);
public void InMachineNameDirectoryShouldReturnMachineSpecificDeploymentDirectory()
=> _testRunDirectories.InMachineNameDirectory.Should().Be(Path.Combine(@"C:\temp\In", Environment.MachineName));
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

using System.Collections.ObjectModel;

using AwesomeAssertions;

using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Discovery;
using Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Helpers;
Expand Down Expand Up @@ -68,8 +70,8 @@ public void ConstructorShouldPopulateSettings()
// Constructor has the side effect of populating the passed settings to MSTestSettings.CurrentSettings
_ = new AssemblyEnumerator(adapterSettings);

Verify(MSTestSettings.CurrentSettings.ForcedLegacyMode);
Verify(MSTestSettings.CurrentSettings.TestSettingsFile == "DummyPath\\TestSettings1.testsettings");
MSTestSettings.CurrentSettings.ForcedLegacyMode.Should().BeTrue();
MSTestSettings.CurrentSettings.TestSettingsFile.Should().Be("DummyPath\\TestSettings1.testsettings");
}

#endregion
Expand All @@ -83,7 +85,7 @@ public void GetTypesShouldReturnEmptyArrayWhenNoDeclaredTypes()
// Setup mocks
mockAssembly.Setup(a => a.GetTypes()).Returns([]);

Verify(AssemblyEnumerator.GetTypes(mockAssembly.Object).Length == 0);
AssemblyEnumerator.GetTypes(mockAssembly.Object).Length.Should().Be(0);
}

public void GetTypesShouldReturnSetOfDefinedTypes()
Expand All @@ -96,7 +98,7 @@ public void GetTypesShouldReturnSetOfDefinedTypes()
mockAssembly.Setup(a => a.GetTypes()).Returns(expectedTypes);

Type[] types = AssemblyEnumerator.GetTypes(mockAssembly.Object);
Verify(expectedTypes.SequenceEqual(types));
expectedTypes.SequenceEqual(types).Should().BeTrue();
}

#endregion
Expand All @@ -114,7 +116,7 @@ public void EnumerateAssemblyShouldReturnEmptyListWhenNoDeclaredTypes()

AssemblyEnumerationResult result = _assemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);
Verify(result.TestElements.Count == 0);
result.TestElements.Count.Should().Be(0);
}

public void EnumerateAssemblyShouldReturnEmptyListWhenNoTestElementsInAType()
Expand All @@ -134,7 +136,7 @@ public void EnumerateAssemblyShouldReturnEmptyListWhenNoTestElementsInAType()

AssemblyEnumerationResult result = _assemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);
Verify(result.TestElements.Count == 0);
result.TestElements.Count.Should().Be(0);
}

public void EnumerateAssemblyShouldReturnTestElementsForAType()
Expand All @@ -156,7 +158,7 @@ public void EnumerateAssemblyShouldReturnTestElementsForAType()
AssemblyEnumerationResult result = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);

Verify(new Collection<UnitTestElement> { unitTestElement }.SequenceEqual(result.TestElements));
new Collection<UnitTestElement> { unitTestElement }.SequenceEqual(result.TestElements).Should().BeTrue();
}

public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForAType()
Expand All @@ -179,7 +181,7 @@ public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForAType()
AssemblyEnumerationResult result = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);

Verify(expectedTestElements.SequenceEqual(result.TestElements));
expectedTestElements.SequenceEqual(result.TestElements).Should().BeTrue();
}

public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForMoreThanOneType()
Expand All @@ -204,7 +206,7 @@ public void EnumerateAssemblyShouldReturnMoreThanOneTestElementForMoreThanOneTyp

expectedTestElements.Add(unitTestElement);
expectedTestElements.Add(unitTestElement);
Verify(expectedTestElements.SequenceEqual(result.TestElements));
expectedTestElements.SequenceEqual(result.TestElements).Should().BeTrue();
}

public void EnumerateAssemblyShouldNotLogWarningsIfNonePresent()
Expand All @@ -224,7 +226,7 @@ public void EnumerateAssemblyShouldNotLogWarningsIfNonePresent()

AssemblyEnumerationResult result = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);
Verify(result.Warnings.Count == 0);
result.Warnings.Count.Should().Be(0);
}

public void EnumerateAssemblyShouldLogWarningsIfPresent()
Expand All @@ -248,7 +250,7 @@ public void EnumerateAssemblyShouldLogWarningsIfPresent()

AssemblyEnumerationResult result = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly");

Verify(warningsFromTypeEnumerator.SequenceEqual(result.Warnings));
warningsFromTypeEnumerator.SequenceEqual(result.Warnings).Should().BeTrue();
}

public void EnumerateAssemblyShouldHandleExceptionsWhileEnumeratingAType()
Expand All @@ -269,13 +271,13 @@ public void EnumerateAssemblyShouldHandleExceptionsWhileEnumeratingAType()
AssemblyEnumerationResult result = testableAssemblyEnumerator.EnumerateAssembly("DummyAssembly");
_warnings.AddRange(result.Warnings);

Verify(result.Warnings.Contains(
result.Warnings.Contains(
string.Format(
CultureInfo.CurrentCulture,
Resource.CouldNotInspectTypeDuringDiscovery,
typeof(InternalTestClass),
"DummyAssembly",
exception.Message)));
exception.Message)).Should().BeTrue();
}

private static Mock<TestableAssembly> CreateMockTestableAssembly()
Expand Down
Loading
Loading