Skip to content

Commit 5e7d90f

Browse files
Jimmyshargon
andauthored
[Core UT] remove FluentAssertions (#3703)
* remove FluentAssertions * Update UT_OrderedDictionary.cs * Removed dummy new code * Update tests/Neo.UnitTests/Wallets/UT_Wallet.cs * add missing files back and apply shargon suggestion --------- Co-authored-by: Shargon <[email protected]>
1 parent 805678d commit 5e7d90f

File tree

129 files changed

+2247
-2288
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

129 files changed

+2247
-2288
lines changed

tests/Directory.Build.props

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
</PropertyGroup>
1616

1717
<ItemGroup>
18-
<PackageReference Include="FluentAssertions" Version="8.0.1" />
1918
<PackageReference Include="coverlet.collector" Version="6.0.4">
2019
<PrivateAssets>all</PrivateAssets>
2120
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>

tests/Neo.Extensions.Tests/Net/UT_IpAddressExtensions.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12-
using FluentAssertions;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
1313
using Neo.Extensions;
1414
using System.Net;
1515

@@ -22,22 +22,22 @@ public class UT_IpAddressExtensions
2222
public void TestUnmapForIPAddress()
2323
{
2424
var addr = new IPAddress(new byte[] { 127, 0, 0, 1 });
25-
addr.UnMap().Should().Be(addr);
25+
Assert.AreEqual(addr, addr.UnMap());
2626

2727
var addr2 = addr.MapToIPv6();
28-
addr2.UnMap().Should().Be(addr);
28+
Assert.AreEqual(addr, addr2.UnMap());
2929
}
3030

3131
[TestMethod]
3232
public void TestUnmapForIPEndPoin()
3333
{
3434
var addr = new IPAddress(new byte[] { 127, 0, 0, 1 });
3535
var endPoint = new IPEndPoint(addr, 8888);
36-
endPoint.UnMap().Should().Be(endPoint);
36+
Assert.AreEqual(endPoint, endPoint.UnMap());
3737

3838
var addr2 = addr.MapToIPv6();
3939
var endPoint2 = new IPEndPoint(addr2, 8888);
40-
endPoint2.UnMap().Should().Be(endPoint);
40+
Assert.AreEqual(endPoint, endPoint2.UnMap());
4141
}
4242
}
4343
}

tests/Neo.Extensions.Tests/UT_AssemblyExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12-
using FluentAssertions;
12+
using Microsoft.VisualStudio.TestTools.UnitTesting;
1313
using System;
1414
using System.Linq;
1515

@@ -27,7 +27,7 @@ public void TestGetVersion()
2727
.Where(u => u.FullName == "Anonymously Hosted DynamicMethods Assembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
2828
.FirstOrDefault();
2929
string version = asm?.GetVersion() ?? "";
30-
version.Should().Be("0.0.0");
30+
Assert.AreEqual("0.0.0", version);
3131
}
3232
}
3333
}

tests/Neo.Extensions.Tests/UT_BigIntegerExtensions.cs

Lines changed: 45 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12-
using FluentAssertions;
1312
using Neo.Extensions;
1413
using Neo.Json;
1514
using System;
@@ -25,53 +24,53 @@ public class UT_BigIntegerExtensions
2524
public void TestGetLowestSetBit()
2625
{
2726
var big1 = new BigInteger(0);
28-
big1.GetLowestSetBit().Should().Be(-1);
27+
Assert.AreEqual(-1, big1.GetLowestSetBit());
2928

3029
var big2 = new BigInteger(512);
31-
big2.GetLowestSetBit().Should().Be(9);
30+
Assert.AreEqual(9, big2.GetLowestSetBit());
3231

3332
var big3 = new BigInteger(int.MinValue);
34-
big3.GetLowestSetBit().Should().Be(31);
33+
Assert.AreEqual(31, big3.GetLowestSetBit());
3534

3635
var big4 = new BigInteger(long.MinValue);
37-
big4.GetLowestSetBit().Should().Be(63);
36+
Assert.AreEqual(63, big4.GetLowestSetBit());
3837

3938
var big5 = new BigInteger(-18);
40-
big5.GetLowestSetBit().Should().Be(1);
39+
Assert.AreEqual(1, big5.GetLowestSetBit());
4140

4241
var big6 = BigInteger.Pow(2, 1000);
43-
big6.GetLowestSetBit().Should().Be(1000);
42+
Assert.AreEqual(1000, big6.GetLowestSetBit());
4443
}
4544

4645
[TestMethod]
4746
public void TestGetLowestSetBit_EdgeCases()
4847
{
49-
BigInteger.MinusOne.GetLowestSetBit().Should().Be(0);
50-
BigInteger.One.GetLowestSetBit().Should().Be(0);
51-
new BigInteger(ulong.MaxValue).GetLowestSetBit().Should().Be(0);
52-
(BigInteger.One << 1000).GetLowestSetBit().Should().Be(1000);
48+
Assert.AreEqual(0, BigInteger.MinusOne.GetLowestSetBit());
49+
Assert.AreEqual(0, BigInteger.One.GetLowestSetBit());
50+
Assert.AreEqual(0, new BigInteger(ulong.MaxValue).GetLowestSetBit());
51+
Assert.AreEqual(1000, (BigInteger.One << 1000).GetLowestSetBit());
5352
}
5453

5554
[TestMethod]
5655
public void TestToByteArrayStandard()
5756
{
5857
BigInteger number = BigInteger.Zero;
59-
number.ToByteArrayStandard().Should().BeEmpty();
58+
CollectionAssert.AreEqual(Array.Empty<byte>(), number.ToByteArrayStandard());
6059

6160
number = BigInteger.One;
62-
number.ToByteArrayStandard().Should().Equal(new byte[] { 0x01 });
61+
CollectionAssert.AreEqual(new byte[] { 0x01 }, number.ToByteArrayStandard());
6362

6463
number = new BigInteger(256); // Binary: 100000000
65-
number.ToByteArrayStandard().Should().Equal(new byte[] { 0x00, 0x01 });
64+
CollectionAssert.AreEqual(new byte[] { 0x00, 0x01 }, number.ToByteArrayStandard());
6665
}
6766

6867
[TestMethod]
6968
public void TestToByteArrayStandard_EdgeCases()
7069
{
71-
BigInteger.MinusOne.ToByteArrayStandard().Should().Equal(new byte[] { 0xFF });
72-
new BigInteger(byte.MaxValue).ToByteArrayStandard().Should().Equal(new byte[] { 0xFF, 0x00 });
73-
new BigInteger(ushort.MaxValue).ToByteArrayStandard().Should().Equal(new byte[] { 0xFF, 0xFF, 0x00 });
74-
new BigInteger(JNumber.MIN_SAFE_INTEGER).ToByteArrayStandard().Should().Equal(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0 });
70+
CollectionAssert.AreEqual(new byte[] { 0xFF }, BigInteger.MinusOne.ToByteArrayStandard());
71+
CollectionAssert.AreEqual(new byte[] { 0xFF, 0x00 }, new BigInteger(byte.MaxValue).ToByteArrayStandard());
72+
CollectionAssert.AreEqual(new byte[] { 0xFF, 0xFF, 0x00 }, new BigInteger(ushort.MaxValue).ToByteArrayStandard());
73+
CollectionAssert.AreEqual(new byte[] { 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0 }, new BigInteger(JNumber.MIN_SAFE_INTEGER).ToByteArrayStandard());
7574
}
7675

7776
[TestMethod]
@@ -80,35 +79,35 @@ public void TestMod()
8079
var x = new BigInteger(-13);
8180
var y = new BigInteger(5);
8281
var result = x.Mod(y);
83-
result.Should().Be(2); // -13 % 5 is -3, but Mod method should return 2
82+
Assert.AreEqual(2, result); // -13 % 5 is -3, but Mod method should return 2
8483
}
8584

8685
[TestMethod]
8786
public void TestMod_EdgeCases()
8887
{
8988
// Test case 1: Mod of zero
90-
BigInteger.Zero.Mod(5).Should().Be(0, "Mod of zero should always be zero");
89+
Assert.AreEqual(0, BigInteger.Zero.Mod(5), "Mod of zero should always be zero");
9190

9291
// Test case 2: Mod of -1
93-
BigInteger.MinusOne.Mod(5).Should().Be(4, "Mod of -1 should return the modulus minus 1");
92+
Assert.AreEqual(4, BigInteger.MinusOne.Mod(5), "Mod of -1 should return the modulus minus 1");
9493

9594
// Test case 3: Mod with large numbers
9695
BigInteger minValue = new BigInteger(long.MinValue);
9796
BigInteger maxValue = new BigInteger(long.MaxValue);
98-
minValue.Mod(maxValue).Should().Be(9223372036854775806, "Mod with large numbers should be calculated correctly");
97+
Assert.AreEqual(9223372036854775806, minValue.Mod(maxValue), "Mod with large numbers should be calculated correctly");
9998

10099
// Test case 4: Comparing Mod with % operator
101100
BigInteger result = minValue.Mod(maxValue);
102-
result.Should().NotBe(long.MinValue % long.MaxValue, "Mod should always return non-negative values, unlike % operator");
101+
Assert.AreNotEqual(long.MinValue % long.MaxValue, result, "Mod should always return non-negative values, unlike % operator");
103102

104103
// Test case 5: Verifying % operator behavior
105-
(long.MinValue % long.MaxValue).Should().Be((long)(minValue % maxValue), "% operator should behave consistently for BigInteger and long");
104+
Assert.AreEqual((long)(minValue % maxValue), long.MinValue % long.MaxValue, "% operator should behave consistently for BigInteger and long");
106105

107106
// Test case 6: Mod with prime numbers
108-
new BigInteger(17).Mod(19).Should().Be(17, "Mod with a larger prime should return the original number");
107+
Assert.AreEqual(17, new BigInteger(17).Mod(19), "Mod with a larger prime should return the original number");
109108

110109
// Test case 7: Mod with powers of 2
111-
new BigInteger(1024).Mod(16).Should().Be(0, "Mod with powers of 2 should utilize bitwise operations efficiently");
110+
Assert.AreEqual(0, new BigInteger(1024).Mod(16), "Mod with powers of 2 should utilize bitwise operations efficiently");
112111
}
113112

114113
[TestMethod]
@@ -117,76 +116,70 @@ public void TestModInverse()
117116
var a = new BigInteger(3);
118117
var n = new BigInteger(11);
119118
var result = a.ModInverse(n);
120-
result.Should().Be(4); // 3 * 4 % 11 == 1
119+
Assert.AreEqual(4, result); // 3 * 4 % 11 == 1
121120

122121
a = new BigInteger(1);
123122
n = new BigInteger(11);
124123
result = a.ModInverse(n);
125-
result.Should().Be(1); // 1 * 1 % 11 == 1
124+
Assert.AreEqual(1, result); // 1 * 1 % 11 == 1
126125

127126
a = new BigInteger(13);
128127
n = new BigInteger(11);
129128
result = a.ModInverse(n);
130-
result.Should().Be(6); // 13 % 11 = 2, and 2 * 6 % 11 == 1
129+
Assert.AreEqual(6, result); // 13 % 11 = 2, and 2 * 6 % 11 == 1
131130

132131
a = new BigInteger(6);
133132
n = new BigInteger(12); // 6 and 12 are not coprime
134-
Action act = () => a.ModInverse(n);
135-
act.Should().Throw<ArithmeticException>()
136-
.WithMessage("No modular inverse exists for the given inputs.");
133+
Assert.ThrowsException<ArithmeticException>(() => a.ModInverse(n));
137134
}
138135

139136
[TestMethod]
140137
public void TestModInverse_EdgeCases()
141138
{
142-
Action act = () => BigInteger.Zero.ModInverse(11);
143-
act.Should().Throw<ArithmeticException>();
139+
Assert.ThrowsException<ArithmeticException>(() => BigInteger.Zero.ModInverse(11));
144140

145-
BigInteger.One.ModInverse(2).Should().Be(1);
141+
Assert.AreEqual(1, BigInteger.One.ModInverse(2));
146142

147-
act = () => new BigInteger(2).ModInverse(4);
148-
act.Should().Throw<ArithmeticException>();
143+
Assert.ThrowsException<ArithmeticException>(() => new BigInteger(2).ModInverse(4));
149144

150-
new BigInteger(long.MaxValue - 1).ModInverse(long.MaxValue).Should().Be(long.MaxValue - 1);
145+
Assert.AreEqual(long.MaxValue - 1, new BigInteger(long.MaxValue - 1).ModInverse(long.MaxValue));
151146
}
152147

153148
[TestMethod]
154149
public void TestBit()
155150
{
156151
var bigInteger = new BigInteger(5); // Binary: 101
157-
var result = bigInteger.TestBit(2);
158-
result.Should().BeTrue(); // Bit at index 2 is set (1)
152+
Assert.IsTrue(bigInteger.TestBit(2)); // Bit at index 2 is set (1)
159153

160154
bigInteger = new BigInteger(5); // Binary: 101
161-
result = bigInteger.TestBit(1);
162-
result.Should().BeFalse(); // Bit at index 1 is not set (0)
155+
Assert.IsFalse(bigInteger.TestBit(1)); // Bit at index 1 is not set (0)
163156
}
164157

165158
[TestMethod]
166159
public void TestBit_EdgeCases()
167160
{
168-
BigInteger.Zero.TestBit(0).Should().BeFalse();
169-
BigInteger.Zero.TestBit(100).Should().BeFalse();
170-
BigInteger.MinusOne.TestBit(0).Should().BeTrue();
171-
BigInteger.MinusOne.TestBit(1000).Should().BeTrue();
172-
(BigInteger.One << 1000).TestBit(1000).Should().BeTrue();
173-
(BigInteger.One << 1000).TestBit(999).Should().BeFalse();
161+
Assert.IsFalse(BigInteger.Zero.TestBit(0));
162+
Assert.IsFalse(BigInteger.Zero.TestBit(100));
163+
Assert.IsTrue(BigInteger.MinusOne.TestBit(0));
164+
Assert.IsTrue(BigInteger.MinusOne.TestBit(1000));
165+
Assert.IsTrue((BigInteger.One << 1000).TestBit(1000));
166+
Assert.IsFalse((BigInteger.One << 1000).TestBit(999));
174167
}
175168

176169
[TestMethod]
177170
public void TestSum()
178171
{
179172
var bigIntegers = new List<BigInteger> { 1, 2, 3, 4 };
180173
var result = bigIntegers.Sum();
181-
result.Should().Be(10);
174+
Assert.AreEqual(10, result);
182175
}
183176

184177
[TestMethod]
185178
public void TestSum_EdgeCases()
186179
{
187-
new List<BigInteger>().Sum().Should().Be(0);
188-
new List<BigInteger> { JNumber.MIN_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum().Should().Be(0);
189-
new List<BigInteger> { JNumber.MAX_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum().Should().Be(JNumber.MAX_SAFE_INTEGER * 2);
180+
Assert.AreEqual(0, new List<BigInteger>().Sum());
181+
Assert.AreEqual(0, new List<BigInteger> { JNumber.MIN_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum());
182+
Assert.AreEqual(JNumber.MAX_SAFE_INTEGER * 2, new List<BigInteger> { JNumber.MAX_SAFE_INTEGER, JNumber.MAX_SAFE_INTEGER }.Sum());
190183
}
191184
}
192185
}

tests/Neo.Extensions.Tests/UT_ByteArrayComparer.cs

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// Redistribution and use in source and binary forms with or without
1010
// modifications are permitted.
1111

12-
using FluentAssertions;
1312
using System;
1413

1514
namespace Neo.Extensions.Tests
@@ -22,64 +21,64 @@ public void TestCompare()
2221
{
2322
ByteArrayComparer comparer = ByteArrayComparer.Default;
2423
byte[]? x = null, y = null;
25-
comparer.Compare(x, y).Should().Be(0);
24+
Assert.AreEqual(0, comparer.Compare(x, y));
2625

2726
x = new byte[] { 1, 2, 3, 4, 5 };
2827
y = x;
29-
comparer.Compare(x, y).Should().Be(0);
30-
comparer.Compare(x, x).Should().Be(0);
28+
Assert.AreEqual(0, comparer.Compare(x, y));
29+
Assert.AreEqual(0, comparer.Compare(x, x));
3130

3231
y = null;
33-
comparer.Compare(x, y).Should().BeGreaterThan(0);
32+
Assert.IsTrue(comparer.Compare(x, y) > 0);
3433

3534
y = x;
3635
x = null;
37-
comparer.Compare(x, y).Should().BeLessThan(0);
36+
Assert.IsTrue(comparer.Compare(x, y) < 0);
3837

3938
x = new byte[] { 1 };
4039
y = Array.Empty<byte>();
41-
comparer.Compare(x, y).Should().BeGreaterThan(0);
40+
Assert.IsTrue(comparer.Compare(x, y) > 0);
4241
y = x;
43-
comparer.Compare(x, y).Should().Be(0);
42+
Assert.AreEqual(0, comparer.Compare(x, y));
4443

4544
x = new byte[] { 1 };
4645
y = new byte[] { 2 };
47-
comparer.Compare(x, y).Should().BeLessThan(0);
46+
Assert.IsTrue(comparer.Compare(x, y) < 0);
4847

49-
comparer.Compare(null, Array.Empty<byte>()).Should().Be(0);
50-
comparer.Compare(Array.Empty<byte>(), null).Should().Be(0);
48+
Assert.AreEqual(0, comparer.Compare(null, Array.Empty<byte>()));
49+
Assert.AreEqual(0, comparer.Compare(Array.Empty<byte>(), null));
5150

5251
x = new byte[] { 1, 2, 3, 4, 5 };
5352
y = new byte[] { 1, 2, 3 };
54-
comparer.Compare(x, y).Should().BeGreaterThan(0);
53+
Assert.IsTrue(comparer.Compare(x, y) > 0);
5554

5655
x = new byte[] { 1, 2, 3, 4, 5 };
5756
y = new byte[] { 1, 2, 3, 4, 5, 6 };
58-
comparer.Compare(x, y).Should().BeLessThan(0);
57+
Assert.IsTrue(comparer.Compare(x, y) < 0);
5958

6059
// cases for reverse comparer
6160
comparer = ByteArrayComparer.Reverse;
6261

6362
x = new byte[] { 3 };
64-
comparer.Compare(x, y).Should().BeLessThan(0);
63+
Assert.IsTrue(comparer.Compare(x, y) < 0);
6564

6665
y = x;
67-
comparer.Compare(x, y).Should().Be(0);
66+
Assert.AreEqual(0, comparer.Compare(x, y));
6867

6968
x = new byte[] { 1 };
7069
y = new byte[] { 2 };
71-
comparer.Compare(x, y).Should().BeGreaterThan(0);
70+
Assert.IsTrue(comparer.Compare(x, y) > 0);
7271

73-
comparer.Compare(null, Array.Empty<byte>()).Should().Be(0);
74-
comparer.Compare(Array.Empty<byte>(), null).Should().Be(0);
72+
Assert.AreEqual(0, comparer.Compare(null, Array.Empty<byte>()));
73+
Assert.AreEqual(0, comparer.Compare(Array.Empty<byte>(), null));
7574

7675
x = new byte[] { 1, 2, 3, 4, 5 };
7776
y = new byte[] { 1, 2, 3 };
78-
comparer.Compare(x, y).Should().BeLessThan(0);
77+
Assert.IsTrue(comparer.Compare(x, y) < 0);
7978

8079
x = new byte[] { 1, 2, 3, 4, 5 };
8180
y = new byte[] { 1, 2, 3, 4, 5, 6 };
82-
comparer.Compare(x, y).Should().BeGreaterThan(0);
81+
Assert.IsTrue(comparer.Compare(x, y) > 0);
8382
}
8483
}
8584
}

0 commit comments

Comments
 (0)