public void TestIpv6() { IDeviceSpecsValidator deviceSpecsValidator = ServiceProvider.GetService <IDeviceSpecsValidator>(); Assert.True(deviceSpecsValidator.IsValidIPv6Address("f1ac:5242:1b9b:fcf1:de3a:2391:f8e8:fd5a")); Assert.True(deviceSpecsValidator.IsValidIPv6Address("04b2:0dd8:f211:2efd:64cc:6bbb:7d08:91cc")); Assert.True(deviceSpecsValidator.IsValidIPv6Address("2001:0db8:85a3:0000:0000:8a2e:0370:7334")); Assert.True(deviceSpecsValidator.IsValidIPv6Address("2001:0db8:85a3::8a2e:0370:7334")); Assert.False(deviceSpecsValidator.IsValidIPv6Address(null)); Assert.False(deviceSpecsValidator.IsValidIPv6Address("")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("8a2e")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("2001:0db8")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("64cc:6bbb:7d08:91cc")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("12.563.21.3")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("04b2:0dd8:f211:2efd:64cc:6bbb:7d08:91cc:425d")); Assert.False(deviceSpecsValidator.IsValidIPv6Address("122.33.5.56")); }
private GatewayDto GetInputModel() { GatewayDto gatewayDto = new GatewayDto(); Console.Write("\nSerial number: "); gatewayDto.SerialNumber = Console.ReadLine(); while (string.IsNullOrEmpty(gatewayDto.SerialNumber)) { Console.WriteLine("\nSerial number must not be empty"); Console.Write("\nSerial number: "); gatewayDto.SerialNumber = Console.ReadLine(); } Console.Write("\nFirmware version: "); gatewayDto.FirmwareVersion = Console.ReadLine(); if (string.IsNullOrEmpty(gatewayDto.FirmwareVersion)) { gatewayDto.FirmwareVersion = null; } Console.Write("\nState: "); gatewayDto.State = Console.ReadLine(); if (string.IsNullOrEmpty(gatewayDto.State)) { gatewayDto.State = null; } Console.Write("\nIP: "); gatewayDto.IP = Console.ReadLine(); if (string.IsNullOrEmpty(gatewayDto.IP)) { gatewayDto.IP = null; } if (gatewayDto.IP != null) { while (!_deviceSpecsValidator.IsValidIPv4Address(gatewayDto.IP) && !_deviceSpecsValidator.IsValidIPv6Address(gatewayDto.IP)) { Console.WriteLine("\nInvalid IP address"); Console.Write("\nIP: "); gatewayDto.IP = Console.ReadLine(); } } Console.Write("\nPort: "); string portInput = Console.ReadLine(); if (!string.IsNullOrEmpty(portInput)) { bool validPort = int.TryParse(portInput, out int port) && _deviceSpecsValidator.IsValidPort(port); while (!validPort) { Console.WriteLine("\nInvalid port number"); Console.Write("\nPort: "); portInput = Console.ReadLine(); validPort = int.TryParse(portInput, out port) && _deviceSpecsValidator.IsValidPort(port); } gatewayDto.Port = port; } Console.WriteLine("Registering...\n"); return(gatewayDto); }