public bool EqualsTest(string xHead, string xTail, string yHead, string yTail) { // Arrange IPAddress xHeadAddress; if (!IPAddress.TryParse(xHead, out xHeadAddress)) { xHeadAddress = null; } IPAddress xTailAddress; if (!IPAddress.TryParse(xTail, out xTailAddress)) { xTailAddress = null; } IPAddress yHeadAddress; if (!IPAddress.TryParse(yHead, out yHeadAddress)) { yHeadAddress = null; } IPAddress yTailAddress; if (!IPAddress.TryParse(yTail, out yTailAddress)) { yTailAddress = null; } var xAddressRange = new IPAddressRange { Head = xHeadAddress, Tail = xTailAddress }; var yAddressRange = new IPAddressRange { Head = yHeadAddress, Tail = yTailAddress }; // Act var result = xAddressRange.Equals((object)yAddressRange); // Assert return(result); }
private static void TestFilterIPAddressRangesHelper(IPAddressRange[] expected, string message, IPAddressRange[] filter, params IPAddressRange[] ranges) { int index = 0; foreach (IPAddressRange range in IPBanFirewallUtility.FilterRanges(ranges, filter)) { if (index >= expected.Length) { Assert.Fail("Too many filtered results, expected max count of {0}", expected.Length - 1); } // nunit areequal is strange, it calls enumerators and other crap, why it doesn't just do .Equals is beyond me... IPAddressRange existing = expected[index++]; IPAddressRange actual = range; Assert.That(existing.Equals(actual), message); } }
public void Equals_Object_Test(bool expected, string xHead, string xTail, string yHead, string yTail) { // Arrange _ = IPAddress.TryParse(xHead, out var xHeadAddress); _ = IPAddress.TryParse(xTail, out var xTailAddress); var xAddressRange = new IPAddressRange(xHeadAddress, xTailAddress); var yAddressRange = IPAddress.TryParse(yHead, out var yHeadAddress) && IPAddress.TryParse(yTail, out var yTailAddress) ? new IPAddressRange(yHeadAddress, yTailAddress) : null; // Act var result = xAddressRange.Equals((object)yAddressRange); // Assert Assert.Equal(expected, result); }