Skip to content

Commit

Permalink
Enable xunit1024 (#34512)
Browse files Browse the repository at this point in the history
* Enable analyzer rule xUnit1024

* Remove redundant test in System.Text.Json

The very next method is a Theory with inline data that tests this
exact scenario.

* Rename test methods in System.Text.Json

* Rename test methods in System.ComponentModel.Annotations

* Private methods -> local functions in System.Text.Json

* Rename test methods in System.Collections.Immutable

For RemoveNonExistingTest, just moved the logic from the single-use
helper into the method with the Fact attribute.

* Rename test methods in System.Globalization

* Rename test methods in System.Runtime.Extensions

In Math.cs, removed Round_Decimal_Digits Fact which manually tested
cases included in the MemberData of a Theory with the same name.

* Rename test methods in System.Private.Uri

* Rename test methods in System.Runtime.WindowsRuntime.UI.Xaml

* Rename test methods in System.Security.Cryptography.X509Certificates

* Rename test methods in System.Reflection

* Remove redundant test in System.IO.FileSystem.Watcher

Theory EndInit_ResumesPausedEnableRaisingEvents alredy tests
the same scenario as the removed Fact of the same name.

* Rename test methods in System.IO.FileSystem.Watcher

* Rename test methods in System.Composition.Runtime

* Rename test methods in System.Drawing.Primitives

* Rename test methods in System.Reflection.Emit

* Rename test methods in System.Text.RegularExpressions

* Private methods -> local functions in System.Threading.Tasks.Parallel

* Rename test methods in System.Threading.Tasks.Parallel

* Rename test methods in System.Threading.Tasks

* Simplify tests in System.Threading

* Rename test methods in System.Threading

* Rename test methods in Microsoft.VisualBasic.Core

* Rename test methods in System.DirectoryServices.AccountManagement

* Private methods -> local functions in System.Text.Encoding

* Rename test methods in System.Text.Encoding

* Rename test methods in System.Security.Cryptography.Primitives

* Rename test methods in System.Runtime.Numeric

* Rename test methods in System.CodeDom.Tests

* Rename test methods in System.Reflection.Emit.ILGeneration

* Rename test methods in System.Composition.AttributedModel

* Rename test methods in System.Data.DataSetExtensions

* Rename test methods in System.Runtime

* Rename test methods in System.Runtime.InteropServices

* Remove redundant test in System.ServiceModel.Syndication

* Rename test methods in System.ServiceModel.Syndication

* Rename test methods in System.Data.Common

* Rename test methods in System.Security.Cryptography.Xml

* Private methods -> local functions in System.Security.Cryptography.Xml

* Simplify tests in System.Security.Cryptography.ProtectedData

* Replace private methods with local functions...

In System.Security.Cryptography.Algorithms

* Rename test methods in System.Security.Cryptography.Algorithms

* Simplify tests code in System.Collections.Concurrent

* Rename test methods in System.Drawing.Common

* Rename test methods in System.Data.OleDb

* Rename test methods in System.ComponentModel.TypeConverter

* Rename test methods in System.Web.HttpUtility

* Rename test methods in System.Linq

* Private method -> local function in System.Linq

* Rename test methods in System.Memory

* Rename test methods in System.IO.IsolatedStorage

* Rename test methods in System.DirectoryServices.Protocols

* Rename test methods in System.Globalization.Extensions

* Private methods -> local functions in System.Globalization.Extensions

* Rename test methods in System.IO.Compression

* Rename test methods in System.Security.Cryptography.Encoding

* Rename test methods in Microsoft.Win32.Registry

* Rename test methods in System.IO.UnmanagedMemoryStream

* Rename test methods in System.Collections

* Rename test methods in System.Collections.Specialized

* Rename test methods in System.Private.Xml

* Rename test methods in System.IO.FileSystem

* Rename test methods in System.Diagnostics.StackTrace

* Rename test methods in System.Diagnostics

* Improve some test method renames

* Minor nit fixing

* More improvements to test method names
  • Loading branch information
alexvy86 committed Apr 8, 2020
1 parent ad0ea43 commit 61733e2
Show file tree
Hide file tree
Showing 198 changed files with 1,624 additions and 1,823 deletions.
1 change: 0 additions & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@
<Rule Id="SA1649" Action="None" /> <!-- File name should match first type name -->
</Rules>
<Rules AnalyzerId="xunit.analyzers" RuleNamespace="xunit.analyzers">
<Rule Id="xUnit1024" Action="None" /> <!-- Test methods cannot have overloads -->
<Rule Id="xUnit2013" Action="None" /> <!-- Do not use equality check to check for collection size. -->
<Rule Id="xUnit2017" Action="None" /> <!-- Do not use Contains() to check if a value exists in a collection -->
</Rules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,18 @@ public static IEnumerable<object[]> RoundtripCompressDecompressOuterData
[Fact]
public async Task CompressDecompress_RoundTrip()
{
await CompressDecompress_RoundTrip(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip(ReadWriteMode.SyncSpan, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip(ReadWriteMode.AsyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip(ReadWriteMode.AsyncMemory, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip(ReadWriteMode.AsyncBeginEnd, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.SyncSpan, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.AsyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.AsyncMemory, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.AsyncBeginEnd, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
}

[OuterLoop]
[Theory]
[MemberData(nameof(RoundtripCompressDecompressOuterData))]
public async Task CompressDecompress_RoundTrip(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
public async Task CompressDecompress_RoundTrip_OuterLoop(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
{
byte[] data = new byte[totalSize];
new Random(42).NextBytes(data);
Expand Down Expand Up @@ -715,14 +715,14 @@ public async Task Flush_RoundTrip()
{
if (FlushNoOps)
return;
await Flush_RoundTrip(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_RoundTrip(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
await Flush_RoundTrip_OuterLoop(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_RoundTrip_OuterLoop(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
}

[OuterLoop]
[Theory]
[MemberData(nameof(RoundtripCompressDecompressOuterData))]
public async Task Flush_RoundTrip(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
public async Task Flush_RoundTrip_OuterLoop(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
{
if (FlushNoOps)
return;
Expand Down Expand Up @@ -777,14 +777,14 @@ public async Task Flush_Consecutive()
{
if (FlushNoOps)
return;
await Flush_Consecutive(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_Consecutive(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
await Flush_Consecutive_OuterLoop(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_Consecutive_OuterLoop(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
}

[OuterLoop]
[Theory]
[MemberData(nameof(RoundtripCompressDecompressOuterData))]
public async Task Flush_Consecutive(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
public async Task Flush_Consecutive_OuterLoop(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
{
if (FlushNoOps)
return;
Expand Down Expand Up @@ -851,14 +851,14 @@ public async Task Flush_BeforeFirstWrites()
{
if (FlushNoOps)
return;
await Flush_BeforeFirstWrites(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_BeforeFirstWrites(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
await Flush_BeforeFirstWrites_OuterLoop(ReadWriteMode.SyncArray, chunkSize: 1, totalSize: 10, level: CompressionLevel.Fastest);
await Flush_BeforeFirstWrites_OuterLoop(ReadWriteMode.AsyncArray, chunkSize: 1024, totalSize: 8192, level: CompressionLevel.Optimal);
}

[OuterLoop]
[Theory]
[MemberData(nameof(RoundtripCompressDecompressOuterData))]
public async Task Flush_BeforeFirstWrites(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
public async Task Flush_BeforeFirstWrites_OuterLoop(ReadWriteMode readWriteMode, int chunkSize, int totalSize, CompressionLevel level)
{
if (FlushNoOps)
return;
Expand Down Expand Up @@ -1168,7 +1168,7 @@ private async Task CopyTo_Roundtrip_OutputMatchesInput_Verify(byte[] expectedDec
[Theory]
[InlineData(CompressionMode.Compress)]
[InlineData(CompressionMode.Decompress)]
public void BaseStream(CompressionMode mode)
public void BaseStreamTest(CompressionMode mode)
{
using (var baseStream = new MemoryStream())
using (var compressor = CreateStream(baseStream, mode))
Expand Down
24 changes: 12 additions & 12 deletions src/libraries/Common/tests/Tests/System/StringTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ public static void CompareOrdinal_NegativeLength_ThrowsArgumentOutOfRangeExcepti
[InlineData("", "", true)]
[InlineData("", "hello", false)]
[InlineData("Hello", "", true)]
public static void Contains(string s, string value, bool expected)
public static void Contains_String(string s, string value, bool expected)
{
Assert.Equal(expected, s.Contains(value));
Assert.Equal(expected, s.AsSpan().Contains(value.AsSpan(), StringComparison.Ordinal));
Expand Down Expand Up @@ -1666,7 +1666,7 @@ public static void MakeSureNoSequenceEqualChecksGoOutOfRange_Char()
[InlineData("Hello", "llo" + SoftHyphen, StringComparison.OrdinalIgnoreCase, false)]
[InlineData("", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("", "a", StringComparison.OrdinalIgnoreCase, false)]
public static void EndsWith(string s, string value, StringComparison comparisonType, bool expected)
public static void EndsWith_StringComparison(string s, string value, StringComparison comparisonType, bool expected)
{
if (comparisonType == StringComparison.CurrentCulture)
{
Expand Down Expand Up @@ -2482,7 +2482,7 @@ public static void GetHashCode_EmbeddedNull_ReturnsDifferentHashCodes()
[InlineData("", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("123", 123, StringComparison.OrdinalIgnoreCase, false)] // Not a string
[InlineData("\0AAAAAAAAA", "\0BBBBBBBBBBBB", StringComparison.OrdinalIgnoreCase, false)]
public static void Equals(string s1, object obj, StringComparison comparisonType, bool expected)
public static void EqualsTest(string s1, object obj, StringComparison comparisonType, bool expected)
{
string s2 = obj as string;
if (s1 != null)
Expand Down Expand Up @@ -4516,7 +4516,7 @@ public static void Remove_Invalid()
"Mauris nulla sapien, convallis et quam quis, accumsan sodales mi. Praesent dapibus urna fermentum, sollicitudin posuere.",
'e', 'E',
"LorEm ipsum dolor sit amEt, consEctEtur adipiscing Elit. Proin maximus convallis luctus. Curabitur porttitor mi blandit tEllus maximus varius. " +
"Mauris nulla sapiEn, convallis Et quam quis, accumsan sodalEs mi. PraEsEnt dapibus urna fErmEntum, sollicitudin posuErE.")]
"Mauris nulla sapiEn, convallis Et quam quis, accumsan sodalEs mi. PraEsEnt dapibus urna fErmEntum, sollicitudin posuErE.")]
public static void Replace_Char_Char(string s, char oldChar, char newChar, string expected)
{
Assert.Equal(expected, s.Replace(oldChar, newChar));
Expand Down Expand Up @@ -4637,7 +4637,7 @@ public void Replace_EmptyOldValue_ThrowsArgumentException()
[InlineData("Hello", SoftHyphen + "Hel", StringComparison.OrdinalIgnoreCase, false)]
[InlineData("", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("", "hello", StringComparison.OrdinalIgnoreCase, false)]
public static void StartsWith(string s, string value, StringComparison comparisonType, bool expected)
public static void StartsWith_StringComparison(string s, string value, StringComparison comparisonType, bool expected)
{
if (comparisonType == StringComparison.CurrentCulture)
{
Expand Down Expand Up @@ -5016,7 +5016,7 @@ public static void ToCharArray_Invalid()
[InlineData("hElLo", "hello")]
[InlineData("HeLlO", "hello")]
[InlineData("", "")]
public static void ToLower(string s, string expected)
public static void ToLower_String(string s, string expected)
{
Assert.Equal(expected, s.ToLower());

Expand Down Expand Up @@ -5123,7 +5123,7 @@ public static void SameSpanToLower()
Assert.Equal(expected, s1.ToLower(CultureInfo.CurrentCulture).ToArray());
Assert.Equal(expected, s1.ToLowerInvariant().ToArray());
{
AssertExtensions.AssertThrows<InvalidOperationException, char>(a, a =>
AssertExtensions.AssertThrows<InvalidOperationException, char>(a, a =>
{
ReadOnlySpan<char> source = a;
Span<char> destination = a;
Expand Down Expand Up @@ -5156,7 +5156,7 @@ public static void ToLowerOverlapping()
var source = new ReadOnlySpan<char>(a, 1, 3);

AssertExtensions.AssertThrows<InvalidOperationException,char>(source, source =>
{
{
var destination = new Span<char>(a, 3, 3);
source.ToLower(destination, CultureInfo.CurrentCulture);
});
Expand Down Expand Up @@ -5220,7 +5220,7 @@ public static void LengthMismatchToLower()
}

[Fact]
public static void ToLower()
public static void ToLower_CharArray()
{
var expectedSource = new char[3] { 'a', 'B', 'c' };
var expectedDestination = new char[3] { 'a', 'b', 'c' };
Expand Down Expand Up @@ -5432,7 +5432,7 @@ public static void LengthMismatchToUpper()
}

[Fact]
public static void ToUpper()
public static void ToUpper_CharArray()
{
var expectedSource = new char[3] { 'a', 'B', 'c' };
var expectedDestination = new char[3] { 'A', 'B', 'C' };
Expand Down Expand Up @@ -5542,7 +5542,7 @@ public static void Test_ToUpper_Culture(string actual, string expected, CultureI
[Theory]
[InlineData("")]
[InlineData("hello")]
public static void ToString(string s)
public static void ToStringTest(string s)
{
Assert.Same(s, s.ToString());
Assert.Same(s, s.ToString(null));
Expand All @@ -5557,7 +5557,7 @@ public static void ToString(string s)
[InlineData("hElLo", "HELLO")]
[InlineData("HeLlO", "HELLO")]
[InlineData("", "")]
public static void ToUpper(string s, string expected)
public static void ToUpper_String(string s, string expected)
{
Assert.Equal(expected, s.ToUpper());

Expand Down
Loading

0 comments on commit 61733e2

Please sign in to comment.