diff --git a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs
index e5ae798c05..b625eebbfc 100644
--- a/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs
+++ b/src/Adapter/PlatformServices.Desktop/Services/DesktopTestContextImplementation.cs
@@ -118,11 +118,11 @@ public override DataRow DataRow
}
///
- public override IDictionary Properties
+ public override IDictionary Properties
{
get
{
- return this.properties;
+ return this.properties as IDictionary;
}
}
diff --git a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs
index ed341ce37b..48d1ffd431 100644
--- a/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs
+++ b/src/Adapter/PlatformServices.Shared/netstandard1.0/Services/ns10TestContextImplementation.cs
@@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -115,11 +116,11 @@ public override string TestName
/// An System.Collections.IDictionary object that contains key/value pairs that
/// represent the test properties.
///
- public override IDictionary Properties
+ public override IDictionary Properties
{
get
{
- return this.properties as IDictionary;
+ return this.properties as IDictionary;
}
}
diff --git a/src/TestFramework/Extension.Desktop/TestContext.cs b/src/TestFramework/Extension.Desktop/TestContext.cs
index 2cefc01d8f..a6f019bbcc 100644
--- a/src/TestFramework/Extension.Desktop/TestContext.cs
+++ b/src/TestFramework/Extension.Desktop/TestContext.cs
@@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
@@ -19,7 +20,7 @@ public abstract class TestContext
///
/// Gets test properties for a test.
///
- public abstract IDictionary Properties { get; }
+ public abstract IDictionary Properties { get; }
///
/// Gets the current data row when test is used for data driven testing.
diff --git a/src/TestFramework/Extension.Shared/TestContext.cs b/src/TestFramework/Extension.Shared/TestContext.cs
index 7902d37377..225a7f3c18 100644
--- a/src/TestFramework/Extension.Shared/TestContext.cs
+++ b/src/TestFramework/Extension.Shared/TestContext.cs
@@ -4,6 +4,7 @@
namespace Microsoft.VisualStudio.TestTools.UnitTesting
{
using System;
+ using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
@@ -18,7 +19,7 @@ public abstract class TestContext
///
/// Gets test properties for a test.
///
- public abstract IDictionary Properties { get; }
+ public abstract IDictionary Properties { get; }
///
/// Gets Fully-qualified name of the class containing the test method currently being executed
@@ -29,32 +30,17 @@ public abstract class TestContext
/// in the test results. Users can benefit from messages that include the fully-qualified
/// class name in addition to the name of the test method currently being executed.
///
- public virtual string FullyQualifiedTestClassName
- {
- get
- {
- return this.GetProperty("FullyQualifiedTestClassName");
- }
- }
+ public virtual string FullyQualifiedTestClassName => this.GetProperty("FullyQualifiedTestClassName");
///
/// Gets the Name of the test method currently being executed
///
- public virtual string TestName
- {
- get
- {
- return this.GetProperty("TestName");
- }
- }
+ public virtual string TestName => this.GetProperty("TestName");
///
/// Gets the current test outcome.
///
- public virtual UnitTestOutcome CurrentTestOutcome
- {
- get { return UnitTestOutcome.Unknown; }
- }
+ public virtual UnitTestOutcome CurrentTestOutcome => UnitTestOutcome.Unknown;
///
/// Used to write trace messages while the test is running
@@ -72,21 +58,18 @@ public virtual UnitTestOutcome CurrentTestOutcome
private T GetProperty(string name)
where T : class
{
- object o;
-
- if (!this.Properties.TryGetValue(name, out o))
+ if (!((IDictionary)this.Properties).TryGetValue(name, out object propertyValue))
{
return null;
}
- if (o != null && !(o is T))
+ if (propertyValue != null && !(propertyValue is T))
{
// If o has a value, but it's not the right type
- Debug.Assert(false, "How did an invalid value get in here?");
- throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, FrameworkMessages.InvalidPropertyType, name, o.GetType(), typeof(T)));
+ throw new InvalidCastException(string.Format(CultureInfo.CurrentCulture, FrameworkMessages.InvalidPropertyType, name, propertyValue.GetType(), typeof(T)));
}
- return (T)o;
+ return (T)propertyValue;
}
}
}
diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs
index 737129604c..f144f36826 100644
--- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs
+++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TestExecutionManagerTests.cs
@@ -883,7 +883,7 @@ public static IDictionary TestContextProperties
[UTF.TestCategory("Foo")]
public void PassingTest()
{
- TestContextProperties = this.TestContext.Properties;
+ TestContextProperties = this.TestContext.Properties as IDictionary;
}
[UTF.TestMethod]
diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs
index db1c33b763..8e2e4c8806 100644
--- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs
+++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Execution/TypeCacheTests.cs
@@ -922,7 +922,7 @@ public void GetTestMethodInfoShouldSetTestContextWithCustomProperty()
new Dictionary());
this.typeCache.GetTestMethodInfo(testMethod, testContext, false);
- var customProperty = testContext.Properties.FirstOrDefault(p => p.Key.Equals("WhoAmI"));
+ var customProperty = ((IDictionary)testContext.Properties).FirstOrDefault(p => p.Key.Equals("WhoAmI"));
Assert.IsNotNull(customProperty);
Assert.AreEqual("Me", customProperty.Value);
@@ -1009,7 +1009,7 @@ public void GetTestMethodInfoShouldNotAddDuplicateTestPropertiesToTestContext()
// Verify that the first value gets set.
object value;
- Assert.IsTrue(testContext.Properties.TryGetValue("WhoAmI", out value));
+ Assert.IsTrue(((IDictionary)testContext.Properties).TryGetValue("WhoAmI", out value));
Assert.AreEqual("Me", value);
}
diff --git a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/PlatformServiceProviderTests.cs b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/PlatformServiceProviderTests.cs
index a65a2226a9..3de25de523 100644
--- a/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/PlatformServiceProviderTests.cs
+++ b/test/UnitTests/MSTest.CoreAdapter.Unit.Tests/PlatformServiceProviderTests.cs
@@ -94,7 +94,8 @@ public void GetTestContextShouldReturnAValidTestContext()
// Assert.
Assert.AreEqual("A.C.M", testContext.Context.FullyQualifiedTestClassName);
Assert.AreEqual("M", testContext.Context.TestName);
- Assert.IsTrue(testContext.Context.Properties.Contains(properties.ToArray()[0]));
+ Assert.IsTrue(testContext.Context.Properties.Contains(properties.ToArray()[0].Key));
+ Assert.IsTrue(((IDictionary)testContext.Context.Properties).Contains(properties.ToArray()[0]));
}
}
}
diff --git a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs
index 005b9c1c3d..e5d26ae794 100644
--- a/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs
+++ b/test/UnitTests/PlatformServices.Desktop.Unit.Tests/Services/DesktopTestContextImplTests.cs
@@ -59,10 +59,10 @@ public void TestContextConstructorShouldInitializeDefaultProperties()
Assert.IsNotNull(this.testContextImplementation.Properties);
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("FullyQualifiedTestClassName", "A.C.M"));
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("TestName", "M"));
}
@@ -115,8 +115,8 @@ public void PropertiesShouldReturnPropertiesPassedToTestContext()
this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
- CollectionAssert.Contains(this.testContextImplementation.Properties.ToList(), property1);
- CollectionAssert.Contains(this.testContextImplementation.Properties.ToList(), property2);
+ CollectionAssert.Contains(this.testContextImplementation.Properties, property1);
+ CollectionAssert.Contains(this.testContextImplementation.Properties, property2);
}
[TestMethod]
@@ -158,11 +158,10 @@ public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
public void AddPropertyShouldAddPropertiesToThePropertyBag()
{
this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
-
this.testContextImplementation.AddProperty("SomeNewProperty", "SomeValue");
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("SomeNewProperty", "SomeValue"));
}
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 61e860d7ad..6e02a56289 100644
--- a/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs
+++ b/test/UnitTests/PlatformServices.Shared.Unit.Tests/netstandard1.0/ns10TestContextImplementationTests.cs
@@ -23,7 +23,6 @@ namespace MSTestAdapter.PlatformServices.Tests.Services
using System.Linq;
using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices;
- using Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel;
using Moq;
using ITestMethod = Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.ObjectModel.ITestMethod;
@@ -48,7 +47,7 @@ public void TestInit()
[TestMethod]
public void TestContextConstructorShouldInitializeProperties()
{
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.IsNotNull(this.testContextImplementation.Properties);
}
@@ -59,22 +58,22 @@ public void TestContextConstructorShouldInitializeDefaultProperties()
this.testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
this.testMethod.Setup(tm => tm.Name).Returns("M");
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.IsNotNull(this.testContextImplementation.Properties);
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("FullyQualifiedTestClassName", "A.C.M"));
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("TestName", "M"));
}
[TestMethod]
public void CurrentTestOutcomeShouldReturnDefaultOutcome()
{
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.AreEqual(UnitTestOutcome.Failed, this.testContextImplementation.CurrentTestOutcome);
}
@@ -82,7 +81,7 @@ public void CurrentTestOutcomeShouldReturnDefaultOutcome()
[TestMethod]
public void CurrentTestOutcomeShouldReturnOutcomeSet()
{
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
this.testContextImplementation.SetOutcome(UnitTestOutcome.InProgress);
@@ -94,7 +93,7 @@ public void FullyQualifiedTestClassNameShouldReturnTestMethodsFullClassName()
{
this.testMethod.Setup(tm => tm.FullClassName).Returns("A.C.M");
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.AreEqual("A.C.M", this.testContextImplementation.FullyQualifiedTestClassName);
}
@@ -104,7 +103,7 @@ public void TestNameShouldReturnTestMethodsName()
{
this.testMethod.Setup(tm => tm.Name).Returns("M");
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.AreEqual("M", this.testContextImplementation.TestName);
}
@@ -118,10 +117,10 @@ public void PropertiesShouldReturnPropertiesPassedToTestContext()
this.properties.Add(property1);
this.properties.Add(property2);
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
- CollectionAssert.Contains(this.testContextImplementation.Properties.ToList(), property1);
- CollectionAssert.Contains(this.testContextImplementation.Properties.ToList(), property2);
+ CollectionAssert.Contains(this.testContextImplementation.Properties, property1);
+ CollectionAssert.Contains(this.testContextImplementation.Properties, property2);
}
[TestMethod]
@@ -129,7 +128,7 @@ public void ContextShouldReturnTestContextObject()
{
this.testMethod.Setup(tm => tm.Name).Returns("M");
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
Assert.IsNotNull(this.testContextImplementation.Context);
Assert.AreEqual("M", this.testContextImplementation.Context.TestName);
@@ -140,34 +139,28 @@ public void TryGetPropertyValueShouldReturnTrueIfPropertyIsPresent()
{
this.testMethod.Setup(tm => tm.Name).Returns("M");
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
-
- object propValue;
-
- Assert.IsTrue(this.testContextImplementation.TryGetPropertyValue("TestName", out propValue));
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
+ Assert.IsTrue(this.testContextImplementation.TryGetPropertyValue("TestName", out object propValue));
Assert.AreEqual("M", propValue);
}
[TestMethod]
public void TryGetPropertyValueShouldReturnFalseIfPropertyIsNotPresent()
{
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
-
- object propValue;
-
- Assert.IsFalse(this.testContextImplementation.TryGetPropertyValue("Random", out propValue));
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
+ Assert.IsFalse(this.testContextImplementation.TryGetPropertyValue("Random", out object propValue));
Assert.IsNull(propValue);
}
[TestMethod]
public void AddPropertyShouldAddPropertiesToThePropertyBag()
{
- this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new System.IO.StringWriter(), this.properties);
+ this.testContextImplementation = new TestContextImplementation(this.testMethod.Object, new StringWriter(), this.properties);
this.testContextImplementation.AddProperty("SomeNewProperty", "SomeValue");
CollectionAssert.Contains(
- this.testContextImplementation.Properties.ToList(),
+ this.testContextImplementation.Properties,
new KeyValuePair("SomeNewProperty", "SomeValue"));
}