Skip to content

Commit bc4ccd7

Browse files
author
Carlos Parra
committed
Fixed issue microsoft#437 - Removed discover warnings
1 parent 0f18a04 commit bc4ccd7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/Adapter/MSTest.CoreAdapter/Discovery/TypeValidator.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ internal virtual bool IsValidTestClass(Type type, ICollection<string> warnings)
4343
(this.reflectHelper.IsAttributeDefined(type, typeof(TestClassAttribute), false) ||
4444
this.reflectHelper.HasAttributeDerivedFrom(type, typeof(TestClassAttribute), false)))
4545
{
46-
var isPublic = type.GetTypeInfo().IsPublic || (type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPublic);
47-
4846
// non-public class
49-
if (!isPublic)
47+
if (type.GetTypeInfo().IsNotPublic ||
48+
(type.GetTypeInfo().IsNested && type.GetTypeInfo().IsNestedPrivate))
49+
{
50+
return false;
51+
}
52+
53+
// nested non-public class
54+
if (type.GetTypeInfo().IsNested && !type.GetTypeInfo().IsNestedPublic)
5055
{
5156
var warning = string.Format(CultureInfo.CurrentCulture, Resource.UTA_ErrorNonPublicTestClass, type.FullName);
5257
warnings.Add(warning);

test/UnitTests/MSTest.CoreAdapter.Unit.Tests/Discovery/TypeValidatorTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,12 @@ public void IsValidTestClassShouldReturnFalseForNonPublicTestClasses()
8080
}
8181

8282
[TestMethod]
83-
public void IsValidTestClassShouldReportWarningForNonPublicTestClasses()
83+
public void IsValidTestClassShouldNotReportWarningForNonPublicTestClasses()
8484
{
8585
this.SetupTestClass();
8686
this.typeValidator.IsValidTestClass(typeof(InternalTestClass), this.warnings);
87-
Assert.AreEqual(1, this.warnings.Count);
88-
CollectionAssert.Contains(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName));
87+
Assert.AreEqual(0, this.warnings.Count);
88+
CollectionAssert.DoesNotContain(this.warnings, string.Format(Resource.UTA_ErrorNonPublicTestClass, typeof(InternalTestClass).FullName));
8989
}
9090

9191
[TestMethod]

0 commit comments

Comments
 (0)