예제 #1
0
        public int CompareTest(string x,
                               string y)
        {
            // Arrange
            IPAddress addressX;

            if (!IPAddress.TryParse(x, out addressX))
            {
                addressX = null;
            }

            IPAddress addressY;

            if (!IPAddress.TryParse(y, out addressY))
            {
                addressY = null;
            }

            var comparer = new DefaultIPAddressComparer();

            // Act

            var result = comparer.Compare(addressX, addressY);

            // Assert
            return(result);
        }
예제 #2
0
        public void Compare_Test(int expected,
                                 IPAddress x,
                                 IPAddress y)
        {
            // Arrange
            var comparer = new DefaultIPAddressComparer();

            // Act

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

            // Assert
            Assert.Equal(expected, result);
        }
예제 #3
0
        public void DeferToAddressFamilyComparerTest()
        {
            // Arrange
            var address1 = IPAddress.Any;
            var address2 = IPAddress.IPv6Any;

            var mockAddressFamilyComparer = MockRepository.GenerateStub <IComparer <AddressFamily> >();

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

            var comparer = new DefaultIPAddressComparer(mockAddressFamilyComparer);

            // Act

            var result = comparer.Compare(address1, address2);

            // Assert
            mockAddressFamilyComparer.VerifyAllExpectations();
        }
예제 #4
0
        public void Compare_DeferToAddressFamilyComparer_Test()
        {
            // Arrange
            const int expectedResult = 42;
            var       x = IPAddress.Any;
            var       y = IPAddress.IPv6Any;

            var mockAddressFamilyComparer = new Mock <IComparer <AddressFamily> >();

            mockAddressFamilyComparer.Setup(c => c.Compare(x.AddressFamily, y.AddressFamily))
            .Returns(expectedResult);

            var comparer = new DefaultIPAddressComparer(mockAddressFamilyComparer.Object);

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

            // Assert
            Assert.Equal(expectedResult, result);
            mockAddressFamilyComparer.Verify(c => c.Compare(x.AddressFamily, y.AddressFamily), Times.Once);
        }