100 lines
3.0 KiB
C#
100 lines
3.0 KiB
C#
|
|
using DTS.Common.Utils;
|
|||
|
|
using NUnit.Framework;
|
|||
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
|
|||
|
|
namespace DTS.Common.Tests
|
|||
|
|
{
|
|||
|
|
[TestFixture]
|
|||
|
|
class NetworkUtilsShould
|
|||
|
|
{
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnFalseWhenConnectionStringIsNull()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(null, out _);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.False);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnFalseWhenConnectionStringDoesNotContainIp()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
var connectionString = @"\\?\usb#vid_1cb9&pid_001b#6&284bed14&2&1#{fb10e3ff-ece3-410e-beeb-719096813fb9}";
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(connectionString, out _);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.False);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnTrueWhenConnectionStringContainsIpAndPort()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
var connectionString = @"192.168.1.61:8083";
|
|||
|
|
string ipAddress;
|
|||
|
|
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(connectionString, out ipAddress);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.True);
|
|||
|
|
Assert.That(ipAddress, Is.EqualTo("192.168.1.61"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnTrueWhenConnectionStringContainsOnlyIp()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
var connectionString = @"192.168.1.61";
|
|||
|
|
string ipAddress;
|
|||
|
|
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(connectionString, out ipAddress);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.True);
|
|||
|
|
Assert.That(ipAddress, Is.EqualTo("192.168.1.61"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnTrueWhenConnectionStringContainsOnlyIpWithProtocolUDP()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
var connectionString = @"udp://192.168.1.10:8200 ";
|
|||
|
|
string ipAddress;
|
|||
|
|
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(connectionString, out ipAddress);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.True);
|
|||
|
|
Assert.That(ipAddress, Is.EqualTo("192.168.1.10"));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
[Test]
|
|||
|
|
public void TryParseConnectionString_ShouldReturnTrueWhenConnectionStringContainsOnlyIpWithProtocolHTTP()
|
|||
|
|
{
|
|||
|
|
//Arrange
|
|||
|
|
var connectionString = @"http://192.168.1.10:8200 ";
|
|||
|
|
string ipAddress;
|
|||
|
|
|
|||
|
|
//Act
|
|||
|
|
var result = NetworkUtils.TryParseConnectionString(connectionString, out ipAddress);
|
|||
|
|
|
|||
|
|
//Assert
|
|||
|
|
Assert.That(result, Is.True);
|
|||
|
|
Assert.That(ipAddress, Is.EqualTo("192.168.1.10"));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|