Example #1
0
 public void FewestConsecutiveSubnetsFor_Input_Null_ThrowsArgumentNullException_Test(IPAddress alpha,
                                                                                     IPAddress beta)
 {
     // Act
     // Assert
     Assert.Throws <ArgumentNullException>(() => SubnetUtilities.FewestConsecutiveSubnetsFor(alpha, beta));
 }
Example #2
0
 public void FewestConsecutiveSubnetsFor_MissMatchAddressFamilies_ThrowsInvalidOperationException_Test(IPAddress alpha,
                                                                                                       IPAddress beta)
 {
     // Act
     // Assert
     Assert.Throws <InvalidOperationException>(() => SubnetUtilities.FewestConsecutiveSubnetsFor(alpha, beta));
 }
Example #3
0
        public void FewestConsecutiveSubnetsForMissMatchAddressFamiliesTest(string alpha,
                                                                            string beta)
        {
            // Arrange
            var alphaAddress = IPAddress.Parse(alpha);
            var betaAddress  = IPAddress.Parse(beta);

            // Assert
            Assert.Throws <InvalidOperationException>(() => SubnetUtilities.FewestConsecutiveSubnetsFor(alphaAddress, betaAddress));
        }
Example #4
0
        public void FewestConsecutiveSubnetsFor_Example()
        {
            // Arrange
            var left  = IPAddress.Parse("192.168.1.3");
            var right = IPAddress.Parse("192.168.1.5");

            // Act
            var result = SubnetUtilities.FewestConsecutiveSubnetsFor(left, right)
                         .ToArray();

            // Assert
            Assert.Equal(2, result.Length);
            Assert.Contains(Subnet.Parse("192.168.1.4/31"), result);
            Assert.Contains(Subnet.Parse("192.168.1.3/32"), result);
        }
Example #5
0
        public void FewestConsecutiveSubnetsForTest(string alpha,
                                                    string beta,
                                                    string[] results)
        {
            var subnets = SubnetUtilities.FewestConsecutiveSubnetsFor(IPAddress.Parse(alpha), IPAddress.Parse(beta))
                          .ToList();

            var subnetExpectedResults = results.Select(Subnet.Parse)
                                        .ToList();

            Assert.IsNotNull(subnets);
            Assert.IsNotEmpty(subnets);
            Assert.AreEqual(results.Length, subnets.Distinct()
                            .Count());
            CollectionAssert.IsSubsetOf(subnets, subnetExpectedResults);
            CollectionAssert.IsOrdered(subnets.Select(s => s.NetworkPrefixAddress), new DefaultIPAddressComparer());
        }
Example #6
0
        public void FewestConsecutiveSubnetsFor_Test(IEnumerable <Subnet> expected,
                                                     IPAddress left,
                                                     IPAddress right)
        {
            // Arrange
            // Act
            var result = SubnetUtilities.FewestConsecutiveSubnetsFor(left, right)
                         .ToList();

            // Assert
            Assert.NotNull(result);
            Assert.NotEmpty(result);
            Assert.All(result, Assert.NotNull);

            var expectedList = expected.ToList();

            // Assert.Equal(expectedList, result); // directly calling Assert.Equals results in unexpected behavior; unwinding equality explicitly
            Assert.Equal(expectedList.Count, result.Count);
            Assert.All(expectedList, subnet => Assert.Contains(subnet, result));
            Assert.All(result, subnet => Assert.Contains(subnet, expectedList));

            Assert.True(result.SequenceEqual(new SortedSet <Subnet>(result, new DefaultIPAddressRangeComparer())));
        }
Example #7
0
 public void FewestConsecutiveSubnetsForNullBetaTest()
 {
     Assert.Throws <ArgumentNullException>(() => SubnetUtilities.FewestConsecutiveSubnetsFor(IPAddress.Any, null));
 }