Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Get System.ComponentModel.Annotations tests passing with netfx #17874

Merged
merged 6 commits into from
Apr 19, 2017
Merged

Get System.ComponentModel.Annotations tests passing with netfx #17874

merged 6 commits into from
Apr 19, 2017

Conversation

hughbe
Copy link

@hughbe hughbe commented Apr 4, 2017

Commit 1

Fixes a regression from the full .NET framework when porting the library to .net core

Fixes #17872

Commit 2

Nerfs tests for fixed bugs and added features

See #2650, #4465 and #5203

Commit 3

Nerfs tests for .NET core bug. I'm not sure how to fix this one, though!

See #17873

Fixes: #18149
Fixes: #18150
Fixes: #18148
Fixes: #18145
Fixes: #18146
Fixes #18542

hughbe added 3 commits April 4, 2017 16:50
Fixed by using the code from referencesource. The RangeAttribute tests
now all pass with `msbuild /T:BuildAndTest /P:TargetGroup=netfx`
This is almost certainly a .NET core bug caused by
#4319
Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some comments. Thanks for doing this @hughbe

// MaxLengthAttribute in the full .NET framework doesn't support ICollection.Count.
// See https://github.com/dotnet/corefx/pull/2650".
if (!PlatformDetection.IsFullFramework)
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes it a little bit confusing and when this gets fixed in Desktop then we would not be testing that and would be "hard" to find why we are not testing it. It would be better to have 2 tests one for netcore and one for netfx where each one receives its supported input and add SkipOnTargetFramework with the reason why it is skipped.


// MaxLengthAttribute in the full .NET framework doesn't support ICollection.Count.
// See https://github.com/dotnet/corefx/pull/2650".
if (!PlatformDetection.IsFullFramework)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

[MemberData(nameof(ValidValues_ICollection))]
[MemberData(nameof(InvalidValues_ICollection))]
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "MaxLengthAttribute in the full .NET framework doesn't support ICollection.Count. See https://github.com/dotnet/corefx/pull/2650")]
public void Validate_ICollection_NetFx_ThrowsInvalidCastException(MaxLengthAttribute attribute, object value)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you have a Netfx test but I'm missing the netcoreapp tests using this collections.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I'm not sure I understand (this also applies to the comment about the confusion above)

It/when netfx adds the ICollection feature, then this test that is skipped on non-netfx frameworks (I.e runs for netfx) will fail.

The respective netcoreapp test uses the Invalid/Valid_ICollection_TestData in Valid/InvalidValues()

Maybe I could clarify this with a comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So what I meant is that we should have to tests (one for netcoreapp and one for netfx) and split the data Enumerable into to different data sets instead of constructing this data sets in runtime depending on the target that we are running on. While building this sets in runtime it makes it confusing to know which data sets work on netcoreapp and which ones on netfx.

See: #17618

Does this clarify my comment?

yield return new TestCase(new MinLengthAttribute(16), new Collection<string>(new string[16]));
// MinLengthAttribute in the full .NET framework doesn't support ICollection.Count.
// See https://github.com/dotnet/corefx/pull/2650".
if (!PlatformDetection.IsFullFramework)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here. Can it be done the other way I mentioned earlier?

// Certain invalid phone numbers are reported as valid with .NET core.
// The full .NET framework considers them invalid. This is likely a bug
// in .NET core.
if (!PlatformDetection.IsFullFramework)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we instead disable the tests with ActiveIssueAttribute? since this is likely a bug in .NET Core?

cc: @stephentoub

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to disable individual test data in MemberData, since this is part of a list of tests

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we break the test into two (possibly with a shared body) so they can have different member data.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think In the past we've just commented out the test and added a reference to the issue. I can do that if it helps - would also avoid us having to do a bunch of code movement.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@danmosemsft is that a suggestion or a comment in reply to the question?

Copy link
Member

@safern safern Apr 5, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I meant was to disable the test that is failing in netcoreapp due to bug: https://github.com/dotnet/corefx/issues/17873

Instead of making this test pass, as with doing that we would be testing a buggy behavior. So we should add [ActiveIssue(17873)] to the netcoreapp test itself instead of hacking the input to have the "expected" behavior which we claim it to be a bug.

Another approach would be skipping the test in netcoreapp and running it on netfx so that we don't loose test coverage in Desktop.

[EDIT] Actually I think it is better to just skip this test in netcoreapp and link it to the issue tracking this bug.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hughbe I just meant, if we need to disable a single member data, we've historically made two tests, possibly calling into a single body function, each taking a subset of the member data, and each annotated as necessray. But sure if it's just temporarily because of a .NET core bug, as opposed to some .NET Framework bug etc, perhaps it's not worth it.
I'll let @safern code review this and bow out :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I think it is better to just skip this test in netcoreapp and link it to the issue tracking this bug.

I went with that

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @hughbe

@safern
Copy link
Member

safern commented Apr 5, 2017

I will wait for one of the area owners to be ok with this changes before merging.

@danmoseley
Copy link
Member

@divega @lajones @ajcvickers look OK?

@safern
Copy link
Member

safern commented Apr 10, 2017

ping @divega @lajones @ajcvickers :)

@ajcvickers
Copy link

@safern We have some time allocated on Wednesday for Data Annotations issues.

@lajones
Copy link
Contributor

lajones commented Apr 11, 2017

I'm not sure we should follow this route. Basically what this does is accept that the NETCore and NETFx versions of this code produce different results (for the same input) and updates the tests to expect that. I think we should be fixing the code so that NETCore and NETFx always produce the same thing. the question then becomes should NETCore reflect NETFx or vice versa. To discuss in triage tomorrow.

@hughbe
Copy link
Author

hughbe commented Apr 12, 2017

I suggest NetCore aligns with netfx - this is typically what we've gone with for issues that aren't bugs in the .NET framework. These aren't really bugs - I've fixed the first incompatability with TypeDescriptor.

For features added and bugs fixed in .NET Core (e.g. ICollection, better validation of contexts) I believe we've been OK with nerfing the tests for .NET framework.

Copy link

@ajcvickers ajcvickers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good. However, we want to make sure that behavior differences between .NET Core and .NET Framework are intentional and still make sense given the evolved understanding of compatibility. Therefore, before we merge this, we are requesting that each behavior difference is tracked by an issue (not a closed PR) such that we can evaluate if we need to make any compat changes to either .NET Core or .NET Framework. I have tried to indicate in code review comments where I think issues are missing.

Assert.Equal(expected, attribute.RequiresValidationContext);

// The full .NET framework has a bug where CustomValidationAttribute doesn't
// validate the context. See https://github.com/dotnet/corefx/pull/5203.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please file an issue describing this difference in behavior. (#3794 and #5203 don't seem to have any associated issue.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18360

@@ -96,14 +106,24 @@ public static IEnumerable<object[]> BadlyFormed_TestData()
}

[Theory]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET core fixes a bug where CustomValidationAttribute doesn't validate the context. See https://github.com/dotnet/corefx/pull/5203")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, please file an issue for this behavior difference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as #18360

{
CustomValidationAttribute attribute = new CustomValidationAttribute(validatorType, method);
Assert.Throws<InvalidOperationException>(() => attribute.RequiresValidationContext);
}

[Theory]
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "The full .NET framework has a bug where CustomValidationAttribute doesn't validate the context. See https://github.com/dotnet/corefx/pull/5203")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as #18360

@@ -58,6 +66,34 @@ public static void Ctor_Int(int length)
}

[Theory]
[MemberData(nameof(ValidValues_ICollection))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "MaxLengthAttribute in the .NET Framework doesn't support ICollection.Count. See https://github.com/dotnet/corefx/pull/2650")]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise for these behavior differences. (#2650 doesn't seem to have an issue associated, unless I missed it.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18361

Assert.Equal(expected, attribute.RequiresValidationContext);

// The full .NET framework has a bug where CustomValidationAttribute doesn't
// validate the context. See https://github.com/dotnet/corefx/pull/5203.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18360

@@ -96,14 +106,24 @@ public static IEnumerable<object[]> BadlyFormed_TestData()
}

[Theory]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET core fixes a bug where CustomValidationAttribute doesn't validate the context. See https://github.com/dotnet/corefx/pull/5203")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as #18360

{
CustomValidationAttribute attribute = new CustomValidationAttribute(validatorType, method);
Assert.Throws<InvalidOperationException>(() => attribute.RequiresValidationContext);
}

[Theory]
[SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework, "The full .NET framework has a bug where CustomValidationAttribute doesn't validate the context. See https://github.com/dotnet/corefx/pull/5203")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the same as #18360

@@ -58,6 +66,34 @@ public static void Ctor_Int(int length)
}

[Theory]
[MemberData(nameof(ValidValues_ICollection))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "MaxLengthAttribute in the .NET Framework doesn't support ICollection.Count. See https://github.com/dotnet/corefx/pull/2650")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18361

@@ -49,6 +56,34 @@ public static void Ctor(int length)
Assert.Equal(length, new MinLengthAttribute(length).Length);
}

[Theory]
[MemberData(nameof(ValidValues_ICollection))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, "MinLengthAttribute in the .NET Framework doesn't support ICollection.Count. See https://github.com/dotnet/corefx/pull/2650")]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#18361

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you just please add the issue number to the SkipOnTargetFrameworkAttribute so that is easy to track when we look for the tests being skipped?

@hughbe
Copy link
Author

hughbe commented Apr 16, 2017

Friendly Ping?

@hughbe
Copy link
Author

hughbe commented Apr 19, 2017

Rebased to fix a merge conflict

@danmoseley danmoseley merged commit b372d61 into dotnet:master Apr 19, 2017
@hughbe hughbe deleted the componentmodel-netfx branch April 19, 2017 03:57
@karelz karelz added this to the 2.0.0 milestone Apr 20, 2017
@karelz karelz added this to the 2.0.0 milestone Apr 20, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.