-
Notifications
You must be signed in to change notification settings - Fork 812
InvalidCastException
thrown in AssertEqualShouldNotBeUsedForCollectionSizeCheck
#1502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Analyzers
https://github.com/xunit/xunit.analyzers
Bug
A fault in an existing feature
help wanted
Comments
dougbu
added a commit
to aspnet/AspNetWebStack
that referenced
this issue
Oct 25, 2017
….Web.Razor.Test to end - part of #65 Few manual changes: - work around xunit/xunit#1502 - use `Assert.IsAssignableFrom<T>(...)`, `Assert.IsType<T>(...)` and `Assert.Single(...)` return values - suppress xUnit1013, Public method should be marked as test - helper method is called from multiple test classes; none inherit from defining class - fix xUnit1026, `[Theory]` method doesn't use all parameters - add new data set properties - suppress xUnit2013, Do not use equality check to check for collection size. - calls `Count` because the `Mock<T>` does not set up `GetEnumerable()` - `Assert.Equal<T>(...)` -> `Assert.Equal(...)` - avoid Linq's `.Where` inside `Assert.Contains(...)` and similar
This was referenced Oct 25, 2017
dougbu
added a commit
to aspnet/AspNetWebStack
that referenced
this issue
Oct 31, 2017
….Web.Razor.Test to end - part of #65 Few manual changes: - work around xunit/xunit#1502 - use `Assert.IsAssignableFrom<T>(...)`, `Assert.IsType<T>(...)` and `Assert.Single(...)` return values - suppress xUnit1013, Public method should be marked as test - helper method is called from multiple test classes; none inherit from defining class - fix xUnit1026, `[Theory]` method doesn't use all parameters - add new data set properties - suppress xUnit2013, Do not use equality check to check for collection size. - calls `Count` because the `Mock<T>` does not set up `GetEnumerable()` - `Assert.Equal<T>(...)` -> `Assert.Equal(...)` - avoid Linq's `.Where` inside `Assert.Contains(...)` and similar
dougbu
added a commit
to aspnet/AspNetWebStack
that referenced
this issue
Oct 31, 2017
- work around xunit/xunit#1502 - should restore as part of a #96 fix
dougbu
added a commit
to aspnet/AspNetWebStack
that referenced
this issue
Nov 1, 2017
….Web.Razor.Test to end - part of #65 Few manual changes: - temporarily remove xUnit analyzers from System.Web.Razor.Test - work around xunit/xunit#1502 - should restore analyzers as part of a #96 fix - use `Assert.IsAssignableFrom<T>(...)`, `Assert.IsType<T>(...)` and `Assert.Single(...)` return values - avoid xUnit1013, Public method should be marked as test - mark a helper method `internal` - fix xUnit1026, `[Theory]` method doesn't use all parameters - add new data set properties - suppress xUnit2013, Do not use equality check to check for collection size. - calls `Count` because the `Mock<T>` does not set up `GetEnumerable()` - `Assert.Equal<T>(...)` -> `Assert.Equal(...)` - avoid Linq's `.Where` inside `Assert.Contains(...)` and similar
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Analyzers
https://github.com/xunit/xunit.analyzers
Bug
A fault in an existing feature
help wanted
This relates to #1491 because both issues lead to an AD0001 report. However the underlying
Exception
is different.Consider an expression in the analyzed test code such as
Assert.Equal('b', reader.Peek());
wherereader
is aTextReader
. This assertion compareschar
andint
expressions. However the semantic model contains (boxed)object
s for both. The firstobject
cannot be converted directly to anint
, causing anInvalidCastException
when(int)size.Value
is evaluated here.Workaround is to convert the
char
argument to anint
up front e.g.Assert.Equal('b' - '\0', reader.Peek());
.Fixes include ignoring all non-
int
first arguments, converting non-int
arguments toint
when necessary, or unconditionally doing the conversion e.g.var value = Convert.ToInt32(size.Value);
.The text was updated successfully, but these errors were encountered: