Skip to content
Merged
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 @@ -270,7 +270,7 @@ internal static void FixUpTestCase(this TestCase testCase)
{
// Because this project is the actually registered test adapter, we need to replace test framework executor
// URI by ours.
if (!testCase.Properties.Any(x => x.Id == OriginalExecutorUriProperty.Id))
if (!testCase.GetProperties().Any(static property => property.Key.Id == OriginalExecutorUriProperty.Id))
Comment thread
Evangelink marked this conversation as resolved.
Resolved
{
testCase.SetPropertyValue(OriginalExecutorUriProperty, testCase.ExecutorUri);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ namespace Microsoft.Testing.Extensions.VSTestBridge.UnitTests.ObjectModel;
public sealed class ObjectModelConvertersTests
{
private static readonly IClientInfo ClientInfo = new ClientInfoService(WellKnownClients.VisualStudio, "1.0.0", new ClientCapabilitiesService(IsStateful: false));
private static readonly TestProperty OriginalExecutorUriProperty = TestProperty.Register(
VSTestTestNodeProperties.OriginalExecutorUriPropertyName,
VSTestTestNodeProperties.OriginalExecutorUriPropertyName,
typeof(Uri),
typeof(TestCase));

[TestMethod]
[DataRow(true)]
Expand Down Expand Up @@ -291,6 +296,58 @@ public void ToTestNode_WhenTestResultHasMultipleStandardErrorMessages_TestNodePr
Assert.AreEqual($"message1{Environment.NewLine}message2", standardErrorProperties[0].StandardError);
}

[TestMethod]
public void FixUpTestCase_WhenOriginalExecutorUriPropertyExists_DoesNotOverwriteIt()
{
var originalExecutorUri = new Uri("executor://original");
var testCase = new TestCase("SomeFqn", new("executor://current"), "source.cs");
testCase.SetPropertyValue(OriginalExecutorUriProperty, originalExecutorUri);

testCase.FixUpTestCase();

Assert.AreEqual(originalExecutorUri, testCase.GetPropertyValue(OriginalExecutorUriProperty));
}

[TestMethod]
public void FixUpTestCase_WhenOriginalExecutorUriPropertyIsMissing_CapturesItExactlyOnce()
{
var originalExecutorUri = new Uri("executor://original");
var testCase = new TestCase("SomeFqn", originalExecutorUri, "source.cs");

testCase.FixUpTestCase();
testCase.FixUpTestCase();

KeyValuePair<TestProperty, object?>[] originalExecutorUriProperties =
[.. testCase.GetProperties().Where(static property => property.Key.Id == VSTestTestNodeProperties.OriginalExecutorUriPropertyName)];
Assert.HasCount(1, originalExecutorUriProperties);
Assert.AreEqual(originalExecutorUri, originalExecutorUriProperties[0].Value);
}

[TestMethod]
public void FixUpTestCase_ReplacesExecutorUriWithVSTestBridgeExecutorUri()
{
var testCase = new TestCase("SomeFqn", new("executor://original"), "source.cs");

testCase.FixUpTestCase();

Assert.AreEqual(new Uri(Constants.ExecutorUri), testCase.ExecutorUri);
}

[TestMethod]
public void FixUpTestCase_WhenOriginalExecutorUriPropertyHasNullValue_StillTreatsItAsExisting()
{
var testCase = new TestCase("SomeFqn", new("executor://original"), "source.cs");
object? nullValue = null;
testCase.SetPropertyValue(OriginalExecutorUriProperty, nullValue);

testCase.FixUpTestCase();

KeyValuePair<TestProperty, object?>[] originalExecutorUriProperties =
[.. testCase.GetProperties().Where(static property => property.Key.Id == VSTestTestNodeProperties.OriginalExecutorUriPropertyName)];
Assert.HasCount(1, originalExecutorUriProperties);
Assert.IsNull(originalExecutorUriProperties[0].Value);
}

private sealed class NamedFeatureCapabilityWithVSTestProvider : INamedFeatureCapability
{
public bool IsSupported(string featureName) => featureName is JsonRpcStrings.VSTestProviderSupport;
Expand Down