Example #1
0
        public void TryExcludeAll_Tail_Test()
        {
            // Arrange
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.100"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.50"), IPAddress.Parse("192.168.1.100"))
            };

            // Act
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out var results);

            // Assert
            Assert.True(success);
            Assert.NotNull(results);
            var collection = results.ToList();

            Assert.Single(collection);

            var result = collection.Single();

            Assert.Equal(IPAddress.Parse("192.168.1.0"), result.Head);
            Assert.Equal(IPAddress.Parse("192.168.1.49"), result.Tail);
        }
Example #2
0
        public void TryExcludeAll_ConsecutiveCarve_Test()
        {
            // Arrange
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.200"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.1"), IPAddress.Parse("192.168.1.100")),
                new IPAddressRange(IPAddress.Parse("192.168.1.101"), IPAddress.Parse("192.168.1.199"))
            };

            // Act
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out var results);

            // Assert
            Assert.True(success);
            Assert.NotNull(results);
            var enumerable = results.ToList();

            Assert.Equal(2, enumerable.Count);

            Assert.Equal(enumerable,
                         new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.0")),
                new IPAddressRange(IPAddress.Parse("192.168.1.200"), IPAddress.Parse("192.168.1.200"))
            }.ToList());
        }
Example #3
0
        public void TryExcludeNoExclusionsTest()
        {
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.200"));

            IList <IPAddressRange> results;
            var success = IPAddressRange.TryExcludeAll(initialRange, Enumerable.Empty <IPAddressRange>(), out results);

            Assert.IsTrue(success);
            Assert.AreEqual(1, results.Count);

            CollectionAssert.AreEquivalent(results, new[]
            {
                initialRange
            }.ToList());
        }
Example #4
0
        public void TryExcludeInitialMissMatchAddressFamilyCarveTest()
        {
            var initialRange = new IPAddressRange(IPAddress.Parse("::"), IPAddress.Parse("ffff::ffff"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.10"))
            };

            IList <IPAddressRange> results;
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out results);

            Assert.IsFalse(success);
            Assert.IsFalse(results.Any());
        }
Example #5
0
        public void TryExcludeAllOverlapTest()
        {
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.100"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.49")),
                new IPAddressRange(IPAddress.Parse("192.168.1.50"), IPAddress.Parse("192.168.1.75")),
                new IPAddressRange(IPAddress.Parse("192.168.1.75"), IPAddress.Parse("192.168.1.100"))
            };

            IList <IPAddressRange> results;
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out results);

            Assert.IsTrue(success);
            Assert.AreEqual(0, results.Count);
        }
Example #6
0
        public void TryExcludeAll_InitialMissMatchedAddressFamily_Test()
        {
            // Arrange
            var initialRange = new IPAddressRange(IPAddress.Parse("::"), IPAddress.Parse("ffff::ffff"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.10"))
            };

            // Act
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out var results);

            // Assert
            Assert.False(success);
            Assert.Empty(results);
        }
Example #7
0
        public void TryExcludeAll_NoExclusions_Test()
        {
            // Arrange
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.200"));

            // Act
            var success = IPAddressRange.TryExcludeAll(initialRange, Enumerable.Empty <IPAddressRange>(), out var results);

            // Assert
            Assert.True(success);
            Assert.NotNull(results);
            var collection = results.ToList();

            Assert.Single(collection);

            Assert.Equal(initialRange, collection.Single());
        }
Example #8
0
        public void TryExcludeAll_Overlap_Test()
        {
            // Arrange
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.100"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.49")),
                new IPAddressRange(IPAddress.Parse("192.168.1.50"), IPAddress.Parse("192.168.1.75")),
                new IPAddressRange(IPAddress.Parse("192.168.1.75"), IPAddress.Parse("192.168.1.100"))
            };

            // Act
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out var results);

            //Assert
            Assert.True(success);
            Assert.Empty(results);
        }
Example #9
0
        public void TryExcludeAllTailTest()
        {
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.100"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.50"), IPAddress.Parse("192.168.1.100"))
            };

            IList <IPAddressRange> results;
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out results);

            Assert.IsTrue(success);
            Assert.AreEqual(1, results.Count);

            var result = results.First();

            Assert.AreEqual(IPAddress.Parse("192.168.1.0"), result.Head);
            Assert.AreEqual(IPAddress.Parse("192.168.1.49"), result.Tail);
        }
Example #10
0
        public void TryExcludeAllConsecutiveCarveTest()
        {
            var initialRange = new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.200"));

            var ranges = new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.1"), IPAddress.Parse("192.168.1.100")),
                new IPAddressRange(IPAddress.Parse("192.168.1.101"), IPAddress.Parse("192.168.1.199"))
            };

            IList <IPAddressRange> results;
            var success = IPAddressRange.TryExcludeAll(initialRange, ranges, out results);

            Assert.IsTrue(success);
            Assert.AreEqual(2, results.Count);

            CollectionAssert.AreEquivalent(results, new[]
            {
                new IPAddressRange(IPAddress.Parse("192.168.1.0"), IPAddress.Parse("192.168.1.0")),
                new IPAddressRange(IPAddress.Parse("192.168.1.200"), IPAddress.Parse("192.168.1.200"))
            }.ToList());
        }