Esempio n. 1
0
        public int CompareTest(string x,
                               string y)
        {
            // Arrange
            IPAddressRange addressRangeX = null;
            Subnet         subnetX;

            if (Subnet.TryParse(x, out subnetX))
            {
                addressRangeX = new IPAddressRange(subnetX.Head, subnetX.Tail);
            }

            IPAddressRange addressRangeY = null;
            Subnet         subnetY;

            if (Subnet.TryParse(y, out subnetY))
            {
                addressRangeY = new IPAddressRange(subnetY.Head, subnetY.Tail);
            }

            var comparer = new DefaultIPAddressRangeComparer();

            // Act

            var result = comparer.Compare(addressRangeX, addressRangeY);

            // Assert
            return(result);
        }
        public void Compare_Test(int expected,
                                 IIPAddressRange x,
                                 IIPAddressRange y)
        {
            // Arrange
            var comparer = new DefaultIPAddressRangeComparer();

            // Act

            var result = comparer.Compare(x, y);

            // Assert
            Assert.Equal(expected, result);
        }
Esempio n. 3
0
        public void DeferToIPAddressComparerTest()
        {
            // Arrange
            var address1 = IPAddress.Any;
            var address2 = IPAddress.IPv6Any;

            var subnet1 = new IPAddressRange(address1, address1);
            var subnet2 = new IPAddressRange(address2, address2);

            var mockIPAddressComparer = MockRepository.GenerateStub <IComparer <IPAddress> >();

            mockIPAddressComparer.Expect(c => c.Compare(Arg <IPAddress> .Is.Same(address1), Arg <IPAddress> .Is.Same(address2)))
            .Return(0);

            var comparer = new DefaultIPAddressRangeComparer(mockIPAddressComparer);

            // Act
            var result = comparer.Compare(subnet1, subnet2);

            // Assert
            mockIPAddressComparer.VerifyAllExpectations();
        }
        public void DeferToIPAddressComparerTest()
        {
            // Arrange
            const int expectedResult = 42;

            var xHead = IPAddress.Parse("0.0.0.0");
            var yHead = IPAddress.Parse("abc::");

            var x = CreateIIPAddressRange(xHead);
            var y = CreateIIPAddressRange(yHead);

            var mockIPAddressComparer = new Mock <IComparer <IPAddress> >();

            mockIPAddressComparer.Setup(c => c.Compare(xHead, yHead))
            .Returns(expectedResult);

            var comparer = new DefaultIPAddressRangeComparer(mockIPAddressComparer.Object);

            // Act
            var result = comparer.Compare(x, y);

            // Assert
            Assert.Equal(expectedResult, result);
            mockIPAddressComparer.Verify(c => c.Compare(xHead, yHead), Times.Once);

            IIPAddressRange CreateIIPAddressRange(IPAddress head)
            {
                var xMock = new Mock <IIPAddressRange>(MockBehavior.Strict);

                xMock.Setup(m => m.ToString());
                xMock.Setup(m => m.Head)
                .Returns(head);

                return(xMock.Object);
            }
        }