Skip to content

Commit

Permalink
Added sample for lduchosal#97
Browse files Browse the repository at this point in the history
  • Loading branch information
lduchosal committed Mar 17, 2020
1 parent 1464a26 commit d217568
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/System.Net.IPNetwork.TestProject.Source/IPNetworkUnitTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,39 @@ public void Example9()

}

[TestMethod]
public void When_TrySupernet_192_168_0_0_cidr24_add_192_168_10_0_cidr24_Then_Should_Invalid()
{

IPNetwork network = IPNetwork.Parse("192.168.0.0/24");
IPNetwork network2 = IPNetwork.Parse("192.168.10.0/24");

bool supernetted = network.TrySupernet(network2, out var ipnetwork);
Assert.AreEqual(false, supernetted);


}

[TestMethod]
public void When_TryWideSubnet_192_168_0_0_cidr24_add_192_168_10_0_cidr24_Then_Should_Invalid()
{

IPNetwork network = IPNetwork.Parse("192.168.0.0/24");
IPNetwork network2 = IPNetwork.Parse("192.168.10.0/24");

bool wideSubnetted = IPNetwork.TryWideSubnet(new[] { network, network2 }, out IPNetwork ipnetwork);
Assert.AreEqual(true, wideSubnetted);
Assert.AreEqual("192.168.0.0/20", ipnetwork.ToString());

Console.WriteLine("Network : {0}", ipnetwork.Network);
Console.WriteLine("Netmask : {0}", ipnetwork.Netmask);
Console.WriteLine("Broadcast : {0}", ipnetwork.Broadcast);
Console.WriteLine("FirstUsable : {0}", ipnetwork.FirstUsable);
Console.WriteLine("LastUsable : {0}", ipnetwork.LastUsable);
Console.WriteLine("Usable : {0}", ipnetwork.Usable);
Console.WriteLine("Cidr : {0}", ipnetwork.Cidr);

}

[TestMethod]
public void Example10() {
Expand Down
4 changes: 3 additions & 1 deletion src/System.Net.IPNetwork/IPNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1690,12 +1690,14 @@ public static bool TryWideSubnet(IPNetwork[] ipnetworks, out IPNetwork ipnetwork
return true;
}

public static IPNetwork WideSubnet(IPNetwork[] ipnetworks) {
public static IPNetwork WideSubnet(IPNetwork[] ipnetworks)
{
IPNetwork ipn = null;
IPNetwork.InternalWideSubnet(false, ipnetworks, out ipn);
return ipn;
}


internal static void InternalWideSubnet(bool tryWide, IPNetwork[] ipnetworks, out IPNetwork ipnetwork) {

if (ipnetworks == null) {
Expand Down

0 comments on commit d217568

Please sign in to comment.