-
-
Notifications
You must be signed in to change notification settings - Fork 970
Replace Assert.IsTrue with CollectionAssert.AreEqual for collection comparisons #1730
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
base: develop
Are you sure you want to change the base?
Conversation
Replace Assert.IsTrue(xxx.IsEqualTo(yyy)) and Assert.IsTrue(xxx.SequenceEqual(yyy)) with CollectionAssert.AreEqual(expected, actual) across 55 test files Co-authored-by: Rob-Hague <[email protected]>
Rob-Hague
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot there are multiple build errors of the form "Using directive is unnecessary", and some review comments to address:
| CollectionAssert.AreEqual(m.HostKey, new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61, 0x00, 0x00, 0x00, 0x03, 0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x01, 0x00, 0xce, 0x38, 0xdf, 0x0d, 0x04, 0x2c, 0x10, 0x45, 0x8f, 0x5e, 0xeb, 0xc2, 0x35, 0x01, 0xd5, 0x4d, 0x09, 0xa3, 0xee, 0x74, 0x3d, 0x75, 0xcf, 0xf4, 0xf3, 0x4f, 0xc9, 0xf9, 0x2e, 0x59, 0xd6, 0xb8, 0x69, 0x85, 0x16, 0xac, 0x33, 0x5b, 0x2a, 0x2a, 0xf8, 0x9c, 0xc4, 0xc3, 0x87, 0xd6, 0xb8, 0x50, 0x6c, 0xed, 0x60, 0x9c, 0x0f, 0x83, 0x37, 0xb3, 0xa2, 0x25, 0xbe, 0x07, 0xde, 0xb6, 0x1f, 0x28, 0xab, 0x05, 0x21, 0xc0, 0x23, 0xf7, 0xd6, 0xca, 0xcb, 0x03, 0x42, 0x69, 0x31, 0x93, 0x2b, 0x3b, 0x94, 0xb8, 0x3b, 0x90, 0xe6, 0x25, 0x7c, 0x23, 0xc5, 0x24, 0x89, 0x65, 0x37, 0x7b, 0x56, 0x54, 0xa2, 0x23, 0xcb, 0xeb, 0xf0, 0xe9, 0xd1, 0x07, 0x88, 0x36, 0x8f, 0xef, 0x65, 0x71, 0xac, 0x80, 0x5c, 0x81, 0x0a, 0x95, 0x1c, 0xf5, 0xc0, 0x5d, 0xd3, 0xd4, 0x10, 0x0e, 0x4f, 0xcf, 0x87, 0x80, 0xa5, 0xde, 0x6e, 0xff, 0x89, 0x9c, 0xfc, 0x2f, 0x85, 0xf5, 0x93, 0xff, 0x70, 0x8e, 0x48, 0xb6, 0x6e, 0x6e, 0x0a, 0x18, 0xa3, 0xbb, 0x1c, 0x56, 0x60, 0xf1, 0x9d, 0x2a, 0xca, 0xbf, 0xa0, 0x84, 0x73, 0xb1, 0x6d, 0x10, 0x75, 0xcc, 0xa3, 0x20, 0xed, 0x00, 0x52, 0xd0, 0x84, 0x5a, 0xc9, 0xbb, 0x17, 0x84, 0x96, 0x40, 0x48, 0xe2, 0x8e, 0x84, 0x30, 0x82, 0x3b, 0x87, 0xa4, 0x54, 0x55, 0x8c, 0xb5, 0x62, 0x97, 0xd7, 0xf1, 0xa3, 0x8b, 0x44, 0xaa, 0x34, 0xfd, 0xe9, 0xad, 0xda, 0xeb, 0x45, 0x27, 0xfb, 0xad, 0xea, 0x9a, 0x0c, 0x38, 0x30, 0x27, 0x6a, 0x82, 0xc2, 0xc2, 0x0a, 0xa0, 0xed, 0x30, 0x2f, 0x50, 0x9f, 0xdb, 0x1a, 0xfb, 0x29, 0x1c, 0x8a, 0x28, 0x3f, 0xd6, 0xf6, 0xa9, 0xeb, 0x76, 0x60, 0xa2, 0x56, 0xa2, 0x90, 0x32, 0xcd, 0x25, 0x41, 0xb7, 0xc0, 0x9e, 0x13, 0x97, 0xaf }); | ||
| CollectionAssert.AreEqual(m.Signature, new byte[] { 0x00, 0x00, 0x00, 0x07, 0x73, 0x73, 0x68, 0x2d, 0x72, 0x73, 0x61,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6, 0x13, 0xfb, 0x7a, 0xf5, 0xad, 0xbf, 0xa6, 0x74, 0x75, 0xfa, 0x70, 0x59, 0xae, 0x22, 0xbb, 0xfb, 0x09, 0x68, 0xae, 0xe5, 0x26, 0x5c, 0xbd, 0xe0, 0xae, 0x39, 0xbb, 0xaa, 0x59, 0x4c, 0x73, 0x11, 0x01, 0x64, 0x6d, 0xc1, 0x95, 0x1b, 0x93, 0x6b, 0x14, 0x83, 0x4a, 0xdc, 0x16, 0x67, 0x7b, 0x85, 0xd0, 0x89, 0x2e, 0x3c, 0xa1, 0x05, 0x34, 0xf0, 0xd2, 0xb9, 0x3b, 0x83, 0xf4, 0x02, 0xd4, 0x7f, 0x73, 0x76, 0x5d, 0xc2, 0x67, 0xb9, 0xac, 0x8a, 0xd1, 0xab, 0xd4, 0x82 }); | ||
| CollectionAssert.AreEqual(m.F, new byte[] { 0x00, 0xc6, 0x58, 0xb9, 0xa8, 0x11, 0xfd, 0xb6, 0xd6, 0xe9, 0x0c, 0x51, 0x45, 0xac, 0x51, 0x8a, 0x25, 0x6e, 0x1d, 0x9e, 0xbb, 0x7f, 0x98, 0xe3, 0x94, 0xd5, 0xac, 0x97, 0xd6, 0x35, 0x2e, 0xcc, 0x34, 0x85, 0xe2, 0x29, 0x2c, 0xba, 0x45, 0x6b, 0x39, 0xce, 0xd2, 0xae, 0x2e, 0x9a, 0x30, 0x43, 0x45, 0x09, 0xd2, 0xeb, 0x21, 0x46, 0x95, 0xa8, 0xb9, 0xbc, 0xb4, 0x21, 0xcd, 0x65, 0xeb, 0x0f, 0x48, 0x3c, 0x82, 0xdb, 0x52, 0x0e, 0xa5, 0xa8, 0xca, 0x29, 0x2d, 0xf8, 0x54, 0x38, 0xe4, 0x8f, 0x2c, 0x2d, 0x45, 0x2d, 0x2c, 0xf7, 0x1a, 0x41, 0xef, 0xd4, 0xec, 0x0f, 0xa5, 0xa8, 0xa7, 0x64, 0xb3, 0xe8, 0x7b, 0xa1, 0x40, 0x41, 0x69, 0x70, 0x4d, 0x95, 0x91, 0x8b, 0x5f, 0x28, 0xa2, 0xfc, 0xa7, 0x12, 0x2b, 0x94, 0xf0, 0x0a, 0x82, 0x92, 0x65, 0xdf, 0x8a, 0x35, 0xfb, 0xcc, 0xbe, 0xbd, 0x2d }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the arguments on these lines are the wrong way round - the constant array is the "expected"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 2821526. The constant arrays are now the first argument (expected) in all three CollectionAssert.AreEqual calls on lines 26-28.
| CollectionAssert.AreEqual(m.CompressionAlgorithmsClientToServer, new[] { "none", "[email protected]" }); | ||
| CollectionAssert.AreEqual(m.CompressionAlgorithmsServerToClient, new[] { "none", "[email protected]" }); | ||
| CollectionAssert.AreEqual(m.EncryptionAlgorithmsClientToServer, new[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "[email protected]" }); | ||
| CollectionAssert.AreEqual(m.EncryptionAlgorithmsServerToClient, new[] { "aes128-ctr", "aes192-ctr", "aes256-ctr", "arcfour256", "arcfour128", "aes128-cbc", "3des-cbc", "blowfish-cbc", "cast128-cbc", "aes192-cbc", "aes256-cbc", "arcfour", "[email protected]" }); | ||
| CollectionAssert.AreEqual(m.KeyExchangeAlgorithms, new[] { "ecdh-sha2-nistp256", "ecdh-sha2-nistp384", "ecdh-sha2-nistp521", "diffie-hellman-group-exchange-sha256", "diffie-hellman-group-exchange-sha1", "diffie-hellman-group14-sha1", "diffie-hellman-group1-sha1" }); | ||
| CollectionAssert.AreEqual(m.LanguagesClientToServer, new[] { "" }); | ||
| CollectionAssert.AreEqual(m.LanguagesServerToClient, new[] { "" }); | ||
| CollectionAssert.AreEqual(m.MacAlgorithmsClientToServer, new[] { "hmac-md5", "hmac-sha1", "[email protected]", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "[email protected]", "hmac-sha1-96", "hmac-md5-96" }); | ||
| CollectionAssert.AreEqual(m.MacAlgorithmsServerToClient, new[] { "hmac-md5", "hmac-sha1", "[email protected]", "hmac-sha2-256", "hmac-sha2-256-96", "hmac-sha2-512", "hmac-sha2-512-96", "hmac-ripemd160", "[email protected]", "hmac-sha1-96", "hmac-md5-96" }); | ||
| CollectionAssert.AreEqual(m.ServerHostKeyAlgorithms, new[] { "ssh-rsa", "ssh-dss", "ecdsa-sha2-nistp256" }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, arguments wrong way round
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in commit 2821526. The constant arrays are now the first argument (expected) in all CollectionAssert.AreEqual calls on lines 28-37.
…y using directives - Fixed argument order in KeyExchangeDhGroupExchangeReplyTest.cs (expected first, actual second) - Fixed argument order in KeyExchangeInitMessageTest.cs (expected first, actual second) - Removed unnecessary 'using System.Linq' directives from all affected test files Co-authored-by: Rob-Hague <[email protected]>
Fixed in commit 2821526. All IDE0005 warnings have been resolved by removing unnecessary using directives, and the argument order issues in the review comments have been corrected. The build now succeeds with 0 warnings and 0 errors. |
Replace collection equality assertions with CollectionAssert.AreEqual
Summary
Successfully refactored 96 collection equality assertions across 55 test files:
Assert.IsTrue(xxx.IsEqualTo(yyy))withCollectionAssert.AreEqual(expected, actual)Assert.IsTrue(xxx.SequenceEqual(yyy))withCollectionAssert.AreEqual(expected, actual)using System.LinqdirectivesChanges from review feedback
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.