-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConnectionStringTest.cs
49 lines (45 loc) · 2.57 KB
/
ConnectionStringTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using SocialTalents.MongoSync.Console.Model;
using System;
using System.Collections.Generic;
using System.Text;
using Xunit;
namespace SocialTalents.MongoSync.XUnit
{
public class ConnectionStringTest
{
// mongo.exe requires database name as first parameter, in this way it is easier to fix parameters
[Theory]
[InlineData("mongodb://masterDev:[email protected]/master", new []{"127.0.0.1:27017"}, "masterDev", "BfkvYB", "master",
"--db master --host 127.0.0.1:27017 --username masterDev --password BfkvYB")]
[InlineData("mongodb://[email protected]:28017/master", new []{"127.0.0.1:28017"}, "masterDev", null, "master",
"--db master --host 127.0.0.1:28017 --username masterDev")]
[InlineData("mongodb://127.0.0.1:28017/master", new []{"127.0.0.1:28017"}, null, null, "master"
, "--db master --host 127.0.0.1:28017")]
[InlineData("mongodb://masterDev:[email protected]:28017/master", new []{"127.0.0.1:28017"}, "masterDev", "BfkvYB", "master"
, "--db master --host 127.0.0.1:28017 --username masterDev --password BfkvYB")]
// takes first host from the list if not replica set specified:
[InlineData("mongodb://127.0.0.1:28018,127.0.0.1:28019/master", new []{"127.0.0.1:28018", "127.0.0.1:28019"}, null, null, "master"
, "--db master --host 127.0.0.1:28018")]
// parses replica set:
[InlineData("mongodb://127.0.0.1:28018,127.0.0.1:28019/master?replicaSet=rs0", new []{"127.0.0.1:28018", "127.0.0.1:28019"}, null, null, "master"
, "--db master --host rs0/127.0.0.1:28018,127.0.0.1:28019")]
// ssl on
[InlineData("mongodb://127.0.0.1:28018,127.0.0.1:28019/master?replicaSet=rs0&ssl=true", new[] { "127.0.0.1:28018", "127.0.0.1:28019" }, null, null, "master"
, "--db master --host rs0/127.0.0.1:28018,127.0.0.1:28019 --ssl")]
public void TestParsing(string input, string[] hosts, string user, string password, string database, string expectedCommandLine)
{
var c = new ConnectionString(input);
Assert.Equal(hosts, c.Hosts);
Assert.Equal(user, c.UserName);
Assert.Equal(password, c.Password);
Assert.Equal(database, c.Database);
Assert.Equal(expectedCommandLine, c.ToCommandLine());
}
[Fact]
public void DbNameRequired()
{
string connectionWithoutDbName = "masterDev:[email protected]:28017";
Assert.Throws<ArgumentException>(() => new ConnectionString(connectionWithoutDbName));
}
}
}