public void TryMergeResultTest(string expected, string alphaHead, string alphaTail, string betaHead, string betaTail) { // Arrange var alphaAddressRange = IPAddress.TryParse(alphaHead, out var alphaHeadAddress) && IPAddress.TryParse(alphaTail, out var alphaTailAddress) ? new IPAddressRange(alphaHeadAddress, alphaTailAddress) : null; var betaAddressRange = IPAddress.TryParse(betaHead, out var betaHeadAddress) && IPAddress.TryParse(betaTail, out var betaTailAddress) ? new IPAddressRange(betaHeadAddress, betaTailAddress) : null; // Act var successResult = IPAddressRange.TryMerge(alphaAddressRange, betaAddressRange, out var mergeResult); // Assert Assert.Equal(expected != null, successResult); if (expected == null) { Assert.Null(mergeResult); } else { Assert.NotNull(mergeResult); Assert.Equal(expected, $"{mergeResult.Head}-{mergeResult.Tail}"); } }
public string TryMergeResultTest(string alphaHead, string alphaTail, string betaHead, string betaTail) { // Arrange IPAddress alphaHeadAddress; if (!IPAddress.TryParse(alphaHead, out alphaHeadAddress)) { alphaHeadAddress = null; } IPAddress alphaTailAddress; if (!IPAddress.TryParse(alphaTail, out alphaTailAddress)) { alphaTailAddress = null; } var alphaAddressRange = new IPAddressRange(alphaHeadAddress, alphaTailAddress); // Arrange IPAddress betaHeadAddress; if (!IPAddress.TryParse(betaHead, out betaHeadAddress)) { betaHeadAddress = null; } IPAddress betaTailAddress; if (!IPAddress.TryParse(betaTail, out betaTailAddress)) { betaTailAddress = null; } var betaAddressRange = new IPAddressRange(betaHeadAddress, betaTailAddress); // Act IPAddressRange mergeResult; IPAddressRange.TryMerge(alphaAddressRange, betaAddressRange, out mergeResult); // Assert return(mergeResult == null ? null : string.Format("{0}-{1}", mergeResult.Head, mergeResult.Tail)); }
public bool TryMergeSuccessTest(string alphaHead, string alphaTail, string betaHead, string betaTail) { // Arrange IPAddress alphaHeadAddress; if (!IPAddress.TryParse(alphaHead, out alphaHeadAddress)) { alphaHeadAddress = null; } IPAddress alphaTailAddress; if (!IPAddress.TryParse(alphaTail, out alphaTailAddress)) { alphaTailAddress = null; } var alphaAddressRange = new IPAddressRange(alphaHeadAddress, alphaTailAddress); // Arrange IPAddress betaHeadAddress; if (!IPAddress.TryParse(betaHead, out betaHeadAddress)) { betaHeadAddress = null; } IPAddress betaTailAddress; if (!IPAddress.TryParse(betaTail, out betaTailAddress)) { betaTailAddress = null; } var betaAddressRange = new IPAddressRange(betaHeadAddress, betaTailAddress); // Act IPAddressRange mergeResult; var success = IPAddressRange.TryMerge(alphaAddressRange, betaAddressRange, out mergeResult); // Assert return(success); }