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