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); }
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()); }
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()); }
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()); }
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); }
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); }
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()); }
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); }
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); }
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()); }