Skip to content

Commit

Permalink
Consider readonly TestContext as valid
Browse files Browse the repository at this point in the history
  • Loading branch information
Youssef1313 committed Nov 12, 2024
1 parent be23aac commit 63779e2
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/Adapter/MSTest.TestAdapter/Discovery/TypeValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,14 @@ internal static bool HasCorrectTestContextSignature(Type type)

foreach (PropertyInfo pinfo in propertyInfo)
{
MethodInfo? setInfo = pinfo.SetMethod;
if (setInfo == null)
MethodInfo? getInfo = pinfo.GetMethod;
if (getInfo == null)
{
// we have a getter, but not a setter.
return false;
}

if (setInfo.IsPrivate || setInfo.IsStatic || setInfo.IsAbstract)
if (getInfo.IsPrivate || getInfo.IsStatic || getInfo.IsAbstract)
{
return false;
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/Adapter/MSTest.TestAdapter/Resources/Resource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
<value>(Failed to get the message for an exception of type {0} due to an exception.)</value>
</data>
<data name="UTA_ErrorInValidTestContextSignature" xml:space="preserve">
<value>UTA031: class {0} does not have valid TestContext property. TestContext must be of type TestContext, must be non-static, public and must not be read-only. For example: public TestContext TestContext.</value>
<value>UTA031: class {0} does not have valid TestContext property. TestContext must be of type TestContext, must be non-static, and must be public. For example: public TestContext TestContext.</value>
</data>
<data name="UTA_ErrorNonPublicTestClass" xml:space="preserve">
<value>UTA001: TestClass attribute defined on non-public class {0}</value>
Expand Down Expand Up @@ -417,4 +417,4 @@ but received {4} argument(s), with types '{5}'.</value>
<data name="DuplicateConfigurationError" xml:space="preserve">
<value>Both '.runsettings' and '.testconfig.json' files have been detected. Please select only one of these test configuration files.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ public void IsValidTestClassShouldReturnFalseForGenericAbstractTestClasses()

public void HasCorrectTestContextSignatureShouldReturnTrueForClassesWithNoTestContextProperty() => Verify(TypeValidator.HasCorrectTestContextSignature(typeof(PublicTestClass)));

public void HasCorrectTestContextSignatureShouldReturnFalseForTestContextsWithNoSetters() => Verify(!TypeValidator.HasCorrectTestContextSignature(typeof(ClassWithTestContextGetterOnly)));
public void HasCorrectTestContextSignatureShouldReturnTrueForTestContextsWithNoSetters() => Verify(TypeValidator.HasCorrectTestContextSignature(typeof(ClassWithTestContextGetterOnly)));

public void HasCorrectTestContextSignatureShouldReturnFalseForTestContextsWithPrivateSetter() => Verify(!TypeValidator.HasCorrectTestContextSignature(typeof(ClassWithTestContextPrivateSetter)));
public void HasCorrectTestContextSignatureShouldReturnTrueForTestContextsWithPrivateSetter() => Verify(TypeValidator.HasCorrectTestContextSignature(typeof(ClassWithTestContextPrivateSetter)));

public void HasCorrectTestContextSignatureShouldReturnFalseForTestContextsWithStaticSetter() => Verify(!TypeValidator.HasCorrectTestContextSignature(typeof(ClassWithStaticTestContext)));

Expand Down

0 comments on commit 63779e2

Please sign in to comment.