2018-12-19 20:50:56 +01:00
|
|
|
|
using Tapeti.Helpers;
|
2017-06-26 11:43:55 +02:00
|
|
|
|
using Xunit;
|
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
namespace Tapeti.Tests
|
2017-06-26 11:43:55 +02:00
|
|
|
|
{
|
|
|
|
|
// ReSharper disable InconsistentNaming
|
|
|
|
|
public class ConnectionStringParserTest
|
|
|
|
|
{
|
|
|
|
|
[Fact]
|
|
|
|
|
public void EmptyConnectionString()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("", new TapetiConnectionParams());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void SimpleHostname()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void LongHostname()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.1234.internal.prod.Uname-IT.com", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.1234.internal.prod.Uname-IT.com"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndPort()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Port=60001", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Port = 60001
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndVirtualHost()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;VirtualHost=/staging", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
VirtualHost = "/staging"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndPrefetchCount()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;PrefetchCount=5", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
PrefetchCount = 5
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndUsername()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=myApplication", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndUsernameAndPassword()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=myApplication;Password=abcd1234", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "abcd1234"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void HostnameAndUsernameAndFunnyPassword()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=myApplication;Password=a#$%h^5Gs!`~EE357(-+)=_\\/&*|6$<>{}[]MyFaFoRiTePeTnAmE", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "a#$%h^5Gs!`~EE357(-+)=_\\/&*|6$<>{}[]MyFaFoRiTePeTnAmE"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ExtraSemicolon()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=myApplication;Password=abcd1234;", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "abcd1234"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void ExtraMultipleSemicolon()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;;;;;;;;;;;;;;Username=myApplication;Password=abcd1234;;;", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "abcd1234"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void OnlySemicolons()
|
|
|
|
|
{
|
2018-12-19 20:50:56 +01:00
|
|
|
|
AssertConnectionString(";;;", new TapetiConnectionParams());
|
2017-06-26 11:43:55 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DoubleQuotes()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=\"myApplication\"", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DoubleQuotesInDoubleQuotes()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=\"\"\"myApplication\"\"\";Password=abcd1234", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "\"myApplication\"",
|
|
|
|
|
Password = "abcd1234"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void CharactersInDoubleQuotes()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("HostName=rabbit.com;Username=\"Application?culture=\"\"nl-NL\"\";nr=5;\";Password=abcd1234", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "rabbit.com",
|
|
|
|
|
Username = "Application?culture=\"nl-NL\";nr=5;",
|
|
|
|
|
Password = "abcd1234"
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DifferentOrder()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("Username=myApplication;PrefetchCount=10;Password=1234;Port=80;VirtualHost=/test;HostName=messagebus.universe.local", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "messagebus.universe.local",
|
|
|
|
|
Port = 80,
|
2018-06-11 09:51:15 +02:00
|
|
|
|
VirtualHost = "/test",
|
2017-06-26 11:43:55 +02:00
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "1234",
|
2018-06-11 09:51:15 +02:00
|
|
|
|
PrefetchCount = 10
|
2017-06-26 11:43:55 +02:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
public void DifferentOrderAndQuotes()
|
|
|
|
|
{
|
|
|
|
|
AssertConnectionString("Port=80;Username=myApplication;PrefetchCount=\"10\";Password=\"ab\"\"cd\";VirtualHost=\"/test\";HostName=\"messagebus.universe.local\"", new TapetiConnectionParams
|
|
|
|
|
{
|
|
|
|
|
HostName = "messagebus.universe.local",
|
|
|
|
|
Port = 80,
|
|
|
|
|
VirtualHost = "/test",
|
|
|
|
|
Username = "myApplication",
|
|
|
|
|
Password = "ab\"cd",
|
|
|
|
|
PrefetchCount = 10
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-19 20:50:56 +01:00
|
|
|
|
// ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Local
|
|
|
|
|
private static void AssertConnectionString(string connectionstring, TapetiConnectionParams expected)
|
2017-06-26 11:43:55 +02:00
|
|
|
|
{
|
|
|
|
|
var parsed = ConnectionStringParser.Parse(connectionstring);
|
|
|
|
|
|
|
|
|
|
Assert.Equal(expected.HostName, parsed.HostName);
|
|
|
|
|
Assert.Equal(expected.Port, parsed.Port);
|
|
|
|
|
Assert.Equal(expected.VirtualHost, parsed.VirtualHost);
|
|
|
|
|
Assert.Equal(expected.Username, parsed.Username);
|
|
|
|
|
Assert.Equal(expected.Password, parsed.Password);
|
|
|
|
|
Assert.Equal(expected.PrefetchCount, parsed.PrefetchCount);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|