public void From_AdapterTypeIsEmpty_ReturnsNetworkInterface() { //Arrange var networkInterface = new FakeNetworkInterface { IdToReturn = new Guid(new string('0', 32)).ToString(), NetworkInterfaceTypeToReturn = System.Net.NetworkInformation.NetworkInterfaceType.Ethernet, MAC = "FC-11-69-CB-BF-9E" }; var win32NetworkAdapter = new Win32_NetworkAdapter { AdapterType = string.Empty, Caption = "Caption", ProductName = "ProductName", GUID = new Guid(new string('0', 32)).ToString() }; //Act var result = NetworkInterfaceMapper.From(networkInterface, win32NetworkAdapter); //Asert Assert.NotNull(result); Assert.True(result.GUID == Guid.Parse(networkInterface.Id)); Assert.True(result.NetworkInterfaceType == networkInterface.NetworkInterfaceType); Assert.True(result.MAC == "FC-11-69-CB-BF-9E"); Assert.True(result.AdapterType == win32NetworkAdapter.AdapterType); Assert.True(result.Caption == win32NetworkAdapter.Caption); Assert.True(result.ProductName == win32NetworkAdapter.ProductName); }
public void From_Win32NetworkAdapterIsNull_ThrowsNullReferenceException() { //Arrange var networkInterface = new FakeNetworkInterface { IdToReturn = new Guid(new string('0', 32)).ToString(), NetworkInterfaceTypeToReturn = System.Net.NetworkInformation.NetworkInterfaceType.Ethernet, MAC = "FC-11-69-CB-BF-9E" }; Win32_NetworkAdapter win32NetworkAdapter = null; //Act //Asert Assert.Throws <NullReferenceException>(() => NetworkInterfaceMapper.From(networkInterface, win32NetworkAdapter)); }
public static Databases.RetrieverCore.Common.Models.NetworkInterface From(System.Net.NetworkInformation.NetworkInterface networkInterface, Win32_NetworkAdapter win32NetworkAdapter) { var output = new Databases.RetrieverCore.Common.Models.NetworkInterface(); output.AdapterType = win32NetworkAdapter.AdapterType; output.Caption = win32NetworkAdapter.Caption; output.GUID = string.IsNullOrWhiteSpace(networkInterface?.Id) ? null : Guid.Parse(networkInterface.Id); output.ProductName = win32NetworkAdapter.ProductName; output.NetworkInterfaceType = networkInterface?.NetworkInterfaceType ?? System.Net.NetworkInformation.NetworkInterfaceType.Unknown; var mac = networkInterface?.GetPhysicalAddress().GetAddressBytes(); output.MAC = mac == null || mac.Length == 0 ? null : Encoding.ASCII.GetString(mac); return(output); }
public void From_NetworkInterfaceIsNull_ReturnsNetworkInterface() { //Arrange FakeNetworkInterface networkInterface = null; var win32NetworkAdapter = new Win32_NetworkAdapter { AdapterType = "AdapterType", Caption = "Caption", ProductName = "ProductName", GUID = new Guid(new string('0', 32)).ToString() }; //Act var result = NetworkInterfaceMapper.From(networkInterface, win32NetworkAdapter); //Asert Assert.NotNull(result); Assert.True(result.GUID == null); Assert.True(result.NetworkInterfaceType == System.Net.NetworkInformation.NetworkInterfaceType.Unknown); Assert.True(result.MAC == null); Assert.True(result.AdapterType == win32NetworkAdapter.AdapterType); Assert.True(result.Caption == win32NetworkAdapter.Caption); Assert.True(result.ProductName == win32NetworkAdapter.ProductName); }