public void NetTest5_IPHostEntryBasic() { IPHostEntry ipHostEntry = Dns.GetHostEntry("192.168.1.1"); Assert.NotNull(ipHostEntry, "IPHostEntry is null"); Type typeOfIPHostEntry = ipHostEntry.GetType(); Assert.IsType(typeOfIPHostEntry, Type.GetType("System.Net.IPHostEntry"), "IPHostEntry Type is incorrect"); Assert.Equal(ipHostEntry.AddressList[0].ToString(), "192.168.1.1", "AddressList[0] is incorrect"); Assert.Throws(typeof(IndexOutOfRangeException), () => { ipHostEntry.AddressList[1].ToString(); }); }
public MFTestResults NetTest5_IPHostEntryBasic() { /// <summary> /// 1. Creates an IPHostEntry for localhost /// 2. Verifies that it exists and contains the right data /// </summary> /// bool testResult = true; try { IPHostEntry ipHostEntry = Dns.GetHostEntry("192.168.1.1"); if (ipHostEntry == null) { throw new Exception("IPHostEntry is null"); } Type typeOfIPHostEntry = ipHostEntry.GetType(); if (typeOfIPHostEntry != Type.GetType("System.Net.IPHostEntry")) { throw new Exception("IPHostEntry Type is incorrect"); } if (ipHostEntry.AddressList[0].ToString() != "192.168.1.1") { throw new Exception("AddressList[0] is incorrect"); } try { ipHostEntry.AddressList[1].ToString(); throw new Exception("AddressList[1] is not null"); } catch (System.IndexOutOfRangeException) { } } catch (Exception e) { Log.Comment("Caught exception: " + e.Message); testResult = false; } return(testResult ? MFTestResults.Pass : MFTestResults.Fail); }