Skip to content
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

xUnit2013(Do not use Assert.Equal() to check collection size) should special-case ArraySegment<T> #1970

Closed
Gnbrkm41 opened this issue Jun 20, 2019 · 1 comment

Comments

@Gnbrkm41
Copy link

Gnbrkm41 commented Jun 20, 2019

Similar issue (in fact, the root cause might be the same): #1206

Consider the following code:

        [Fact]
        public static void AsMemory_TryGetArray_ReturnsFalse()
        {
            ReadOnlyMemory<char> m = "0123456789".AsMemory();
            Assert.False(MemoryMarshal.TryGetArray(m, out ArraySegment<char> array));
            Assert.Null(array.Array);
            Assert.Equal(0, array.Offset);
            Assert.Equal(0, array.Count);
        }

The analyzer suggests that the last line should be changed to Assert.Empty(array.Count). However, because ArraySegment<T>.GetEnumerator() throws InvalidOperationException when the underlying array is null, the test fails with an uncaught InvalidOperationException.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants