Skip to content

Commit e160522

Browse files
authored
Feat/substract (#355)
* Feat: Substract IPv6 and IPv4 * Feat: ipnetwork logo * Fix: typos * Fix: warnings * Fix: formatting * Fix: sonarqube * Fix: upgrade nuget * Fix: missing TestClass * Fix: Assert.Throws * Fix: assert expected order
1 parent 376dfbb commit e160522

File tree

55 files changed

+564
-357
lines changed

Some content is hidden

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

55 files changed

+564
-357
lines changed

ipnetwork.png

46.4 KB
Loading

src/System.Net.IPNetwork/System.Net.IPNetwork.csproj

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<Nullable>disable</Nullable>
3030
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
3131
<WarningLevel>5</WarningLevel>
32+
<PackageIcon>ipnetwork.png</PackageIcon>
3233
</PropertyGroup>
3334

3435
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
@@ -40,17 +41,20 @@
4041
</PropertyGroup>
4142

4243
<ItemGroup>
44+
<None Include="..\..\ipnetwork.png">
45+
<Pack>True</Pack>
46+
<PackagePath></PackagePath>
47+
<Link>ipnetwork.png</Link>
48+
</None>
4349
<None Include="..\..\LICENSE" Pack="true" PackagePath="." />
4450
</ItemGroup>
4551

4652
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
47-
<PackageReference Include="System.Memory" Version="4.5.5">
48-
</PackageReference>
53+
<PackageReference Include="System.Memory" Version="4.6.3" />
4954
</ItemGroup>
5055

5156
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.1'">
52-
<PackageReference Include="System.Memory" Version="4.5.5">
53-
</PackageReference>
57+
<PackageReference Include="System.Memory" Version="4.6.3" />
5458
</ItemGroup>
5559

5660
</Project>

src/TestProject/ContainsUnitTest.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,18 @@ public void TestContainsAdrress(string network1, string networkOrAddress, bool e
5353
/// Test.
5454
/// </summary>
5555
[TestMethod]
56-
[ExpectedException(typeof(ArgumentNullException))]
5756
public void TestContainsStatic3()
5857
{
58+
Assert.ThrowsExactly<ArgumentNullException>(() =>
59+
{
5960
IPNetwork2 ipnetwork = null;
6061
IPNetwork2 ipnetwork2 = null;
6162

6263
#pragma warning disable 0618
6364
IPNetwork2.Contains(ipnetwork, ipnetwork2);
6465
#pragma warning restore 0618
65-
}
66+
});
67+
}
6668

6769
/// <summary>
6870
/// Test.
@@ -84,29 +86,33 @@ public void TestContainsStatic4()
8486
/// Test.
8587
/// </summary>
8688
[TestMethod]
87-
[ExpectedException(typeof(ArgumentNullException))]
8889
public void TestContains8()
8990
{
91+
Assert.ThrowsExactly<ArgumentNullException>(() =>
92+
{
9093
var ipnetwork = IPNetwork2.Parse("0.0.0.0/0");
9194
IPNetwork2 ipnetwork2 = null;
9295

9396
ipnetwork.Contains(ipnetwork2);
94-
}
97+
});
98+
}
9599

96100
/// <summary>
97101
/// Test.
98102
/// </summary>
99103
[TestMethod]
100-
[ExpectedException(typeof(ArgumentNullException))]
101104
public void TestContainsStatic1()
102105
{
106+
Assert.ThrowsExactly<ArgumentNullException>(() =>
107+
{
103108
IPNetwork2 ipnetwork = null;
104109
IPAddress ipaddress = null;
105110

106111
#pragma warning disable 0618
107112
IPNetwork2.Contains(ipnetwork, ipaddress);
108113
#pragma warning restore 0618
109-
}
114+
});
115+
}
110116

111117
/// <summary>
112118
/// Test.
@@ -127,14 +133,16 @@ public void TestContainsStatic2()
127133
/// Test.
128134
/// </summary>
129135
[TestMethod]
130-
[ExpectedException(typeof(ArgumentNullException))]
131136
public void TestContains10()
132137
{
138+
Assert.ThrowsExactly<ArgumentNullException>(() =>
139+
{
133140
var ipnetwork = IPNetwork2.Parse("0.0.0.0/0");
134141
IPAddress ipaddress = null;
135142

136143
ipnetwork.Contains(ipaddress);
137-
}
144+
});
145+
}
138146

139147
/// <summary>
140148
/// Test.

src/TestProject/IPAddressCollectionUnitTest.cs

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,14 @@ public void TestIterateIPAddress()
148148
/// Test.
149149
/// </summary>
150150
[TestMethod]
151-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
152151
public void TestOutOfRangeIPAddress()
153152
{
154-
var ipn = IPNetwork2.Parse("192.168.1.0/29");
155-
using IPAddressCollection ips = ipn.ListIPAddress();
156-
Console.Write("This is out of range : {0} ", ips[8]);
153+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
154+
{
155+
var ipn = IPNetwork2.Parse("192.168.1.0/29");
156+
using IPAddressCollection ips = ipn.ListIPAddress();
157+
Console.Write("This is out of range : {0} ", ips[8]);
158+
});
157159
}
158160

159161
/// <summary>
@@ -203,18 +205,20 @@ public void TestResetEnumerator()
203205
/// Test.
204206
/// </summary>
205207
[TestMethod]
206-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
207208
public void TestEnumeratorFailed()
208209
{
209-
var ipn = IPNetwork2.Parse("192.168.1.0/29");
210-
using IEnumerator<IPAddress> ips = ipn.ListIPAddress();
211-
ips.Reset();
212-
while (ips.MoveNext())
210+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
213211
{
214-
Assert.IsNotNull(ips.Current);
215-
}
212+
var ipn = IPNetwork2.Parse("192.168.1.0/29");
213+
using IEnumerator<IPAddress> ips = ipn.ListIPAddress();
214+
ips.Reset();
215+
while (ips.MoveNext())
216+
{
217+
Assert.IsNotNull(ips.Current);
218+
}
216219

217-
Console.WriteLine("This is out of range : {0}", ips.Current);
220+
Console.WriteLine("This is out of range : {0}", ips.Current);
221+
});
218222
}
219223

220224
/// <summary>
@@ -284,17 +288,19 @@ public void TestEnumeratorCurrent()
284288
/// Test.
285289
/// </summary>
286290
[TestMethod]
287-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
288291
public void TestEnumeratorCurrentOor()
289292
{
290-
var ipn = IPNetwork2.Parse("192.168.1.0/31");
291-
IEnumerator ips = ipn.ListIPAddress();
292-
Assert.IsNotNull(ips.Current);
293-
Assert.IsTrue(ips.MoveNext());
294-
Assert.IsNotNull(ips.Current);
295-
Assert.IsTrue(ips.MoveNext());
296-
Assert.IsFalse(ips.MoveNext());
297-
Console.WriteLine("This is out of range : {0} ", ips.Current);
293+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
294+
{
295+
var ipn = IPNetwork2.Parse("192.168.1.0/31");
296+
IEnumerator ips = ipn.ListIPAddress();
297+
Assert.IsNotNull(ips.Current);
298+
Assert.IsTrue(ips.MoveNext());
299+
Assert.IsNotNull(ips.Current);
300+
Assert.IsTrue(ips.MoveNext());
301+
Assert.IsFalse(ips.MoveNext());
302+
Console.WriteLine("This is out of range : {0} ", ips.Current);
303+
});
298304
}
299305

300306
/// <summary>
@@ -358,12 +364,14 @@ public void Test_ipv6_IterateIPAddress()
358364
/// Test.
359365
/// </summary>
360366
[TestMethod]
361-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
362367
public void Test_ipv6_OutOfRangeIPAddress()
363368
{
364-
var ipn = IPNetwork2.Parse("::/125");
365-
using IPAddressCollection ips = ipn.ListIPAddress();
366-
Console.Write("This is out of range : {0} ", ips[8]);
369+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
370+
{
371+
var ipn = IPNetwork2.Parse("::/125");
372+
using IPAddressCollection ips = ipn.ListIPAddress();
373+
Console.Write("This is out of range : {0} ", ips[8]);
374+
});
367375
}
368376

369377
/// <summary>
@@ -425,18 +433,19 @@ public void Tes_ipv6_tResetEnumerator()
425433
/// Test.
426434
/// </summary>
427435
[TestMethod]
428-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
429436
public void Test_ipv6_EnumeratorFailed()
430437
{
431-
var ipn = IPNetwork2.Parse("::/125");
432-
using IEnumerator<IPAddress> ips = ipn.ListIPAddress();
433-
ips.Reset();
434-
while (ips.MoveNext())
438+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
435439
{
436-
Assert.IsNotNull(ips.Current);
437-
}
438-
439-
Console.WriteLine("This is out of range : {0}", ips.Current);
440+
var ipn = IPNetwork2.Parse("::/125");
441+
using IEnumerator<IPAddress> ips = ipn.ListIPAddress();
442+
ips.Reset();
443+
while (ips.MoveNext())
444+
{
445+
Assert.IsNotNull(ips.Current);
446+
}
447+
Console.WriteLine("This is out of range : {0}", ips.Current);
448+
});
440449
}
441450

442451
/// <summary>
@@ -495,17 +504,19 @@ public void Test_ipv6_EnumeratorCurrent()
495504
/// Test.
496505
/// </summary>
497506
[TestMethod]
498-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
499507
public void Test_ipv6_EnumeratorCurrentOor()
500508
{
501-
var ipn = IPNetwork2.Parse("::/127");
502-
IEnumerator ips = ipn.ListIPAddress();
503-
Assert.IsNotNull(ips.Current);
504-
Assert.IsTrue(ips.MoveNext());
505-
Assert.IsNotNull(ips.Current);
506-
Assert.IsTrue(ips.MoveNext());
507-
Assert.IsFalse(ips.MoveNext());
508-
Console.WriteLine("This is out of range : {0} ", ips.Current);
509+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
510+
{
511+
var ipn = IPNetwork2.Parse("::/127");
512+
IEnumerator ips = ipn.ListIPAddress();
513+
Assert.IsNotNull(ips.Current);
514+
Assert.IsTrue(ips.MoveNext());
515+
Assert.IsNotNull(ips.Current);
516+
Assert.IsTrue(ips.MoveNext());
517+
Assert.IsFalse(ips.MoveNext());
518+
Console.WriteLine("This is out of range : {0} ", ips.Current);
519+
});
509520
}
510521

511522
/// <summary>

src/TestProject/IPNetworkCollectionCtorTests.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,23 @@ public class IPNetworkCollectionCtorTests
1414
/// Test ctor with too big cidr.
1515
/// </summary>
1616
[TestMethod]
17-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
1817
public void TestCtor1()
1918
{
20-
var ipn = new IPNetworkCollection(IPNetwork2.IANA_ABLK_RESERVED1, 33);
19+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
20+
{
21+
var ipn = new IPNetworkCollection(IPNetwork2.IANA_ABLK_RESERVED1, 33);
22+
});
2123
}
2224

2325
/// <summary>
2426
/// Test with invalid params.
2527
/// </summary>
2628
[TestMethod]
27-
[ExpectedException(typeof(ArgumentException))]
2829
public void TestCtor2()
2930
{
30-
var ipn = new IPNetworkCollection(IPNetwork2.IANA_ABLK_RESERVED1, 2);
31+
Assert.ThrowsExactly<ArgumentException>(() =>
32+
{
33+
var ipn = new IPNetworkCollection(IPNetwork2.IANA_ABLK_RESERVED1, 2);
34+
});
3135
}
3236
}

src/TestProject/IPNetworkTest/IPNetworkCompareTests.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,15 @@ public void TestCompareTo4()
7070
/// Test.
7171
/// </summary>
7272
[TestMethod]
73-
[ExpectedException(typeof(ArgumentException))]
7473
public void TestCompareTo5()
7574
{
76-
var ipn1 = IPNetwork2.Parse("10.0.0.1/16");
77-
string ipn2 = string.Empty;
75+
Assert.ThrowsExactly<ArgumentException>(() =>
76+
{
77+
var ipn1 = IPNetwork2.Parse("10.0.0.1/16");
78+
string ipn2 = string.Empty;
7879

79-
ipn1.CompareTo(ipn2);
80+
ipn1.CompareTo(ipn2);
81+
});
8082
}
8183

8284
/// <summary>

src/TestProject/IPNetworkTest/IPNetworkCtorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ public class IPNetworkCtorTests
1414
/// Test Ctor with too big of a CIDR.
1515
/// </summary>
1616
[TestMethod]
17-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
1817
public void TestCtor1()
1918
{
20-
new IPNetwork2(BigInteger.Zero, AddressFamily.InterNetwork, 33);
19+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
20+
{
21+
var _ = new IPNetwork2(BigInteger.Zero, AddressFamily.InterNetwork, 33);
22+
});
2123
}
2224
}

src/TestProject/IPNetworkTest/IPNetworkCtorWithIpAndCidrTests.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,26 @@ public void CtorWithIpAndCidr1()
2626
/// Tests Ctor With null ip.
2727
/// </summary>
2828
[TestMethod]
29-
[ExpectedException(typeof(ArgumentNullException))]
3029
public void CtorWithIpAndCidr2()
3130
{
32-
IPAddress ip = null;
33-
var ipnetwork = new IPNetwork2(ip, 24);
31+
Assert.ThrowsExactly<ArgumentNullException>(() =>
32+
{
33+
IPAddress ip = null;
34+
var ipnetwork = new IPNetwork2(ip, 24);
35+
});
3436
}
3537

3638
/// <summary>
3739
/// Tests Ctor With too big cidr.
3840
/// </summary>
3941
[TestMethod]
40-
[ExpectedException(typeof(ArgumentOutOfRangeException))]
4142
public void CtorWithIpAndCidr3()
4243
{
43-
string ipaddress = "192.168.168.100";
44-
var ip = IPAddress.Parse(ipaddress);
45-
var ipnetwork = new IPNetwork2(ip, 33);
44+
Assert.ThrowsExactly<ArgumentOutOfRangeException>(() =>
45+
{
46+
string ipaddress = "192.168.168.100";
47+
var ip = IPAddress.Parse(ipaddress);
48+
var ipnetwork = new IPNetwork2(ip, 33);
49+
});
4650
}
4751
}

src/TestProject/IPNetworkTest/IPNetworkIanaBlocksTests.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,24 +92,28 @@ public void TestIana6()
9292
/// Test is a null ipaddress is in IANA block.
9393
/// </summary>
9494
[TestMethod]
95-
[ExpectedException(typeof(ArgumentNullException))]
9695
public void TestIana7()
9796
{
98-
IPAddress ipaddress = null;
99-
IPNetwork2.IsIANAReserved(ipaddress);
97+
Assert.ThrowsExactly<ArgumentNullException>(() =>
98+
{
99+
IPAddress ipaddress = null;
100+
IPNetwork2.IsIANAReserved(ipaddress);
101+
});
100102
}
101103

102104
/// <summary>
103105
/// Test is a null ipnetwork is in IANA block.
104106
/// </summary>
105107
[TestMethod]
106-
[ExpectedException(typeof(ArgumentNullException))]
107108
public void TestIana8()
108109
{
109-
IPNetwork2 ipnetwork = null;
110+
Assert.ThrowsExactly<ArgumentNullException>(() =>
111+
{
112+
IPNetwork2 ipnetwork = null;
110113
#pragma warning disable 0618
111-
IPNetwork2.IsIANAReserved(ipnetwork);
114+
IPNetwork2.IsIANAReserved(ipnetwork);
112115
#pragma warning restore 0618
116+
});
113117
}
114118

115119
/// <summary>

0 commit comments

Comments
 (0)