forked from samus/mongodb-csharp
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestConnectionStringBuilder.cs
85 lines (72 loc) · 3.99 KB
/
TestConnectionStringBuilder.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using System.Collections.Generic;
using NUnit.Framework;
namespace MongoDB.Driver
{
[TestFixture]
public class TestConnectionStringBuilder
{
[Test]
public void TestCreateEmptyInstance (){
new MongoConnectionStringBuilder ();
}
[Test]
public void TestDefaults (){
var builder = new MongoConnectionStringBuilder ();
Assert.IsNull (builder.Username);
Assert.IsNull (builder.Password);
Assert.AreEqual (builder.MaximumPoolSize, MongoConnectionStringBuilder.DefaultMaximumPoolSize);
Assert.AreEqual (builder.MinimumPoolSize, MongoConnectionStringBuilder.DefaultMinimumPoolSize);
Assert.AreEqual (builder.ConnectionLifetime, MongoConnectionStringBuilder.DefaultConnectionLifeTime);
Assert.AreEqual (builder.ConnectionTimeout, MongoConnectionStringBuilder.DefaultConnectionTimeout);
Assert.AreEqual (builder.Pooled, MongoConnectionStringBuilder.DefaultPooled);
var servers = new List<MongoServerEndPoint> (builder.Servers);
Assert.AreEqual (1, servers.Count);
Assert.AreEqual (MongoServerEndPoint.DefaultPort, servers[0].Port);
Assert.AreEqual (MongoServerEndPoint.DefaultHost, servers[0].Host);
}
[Test]
public void TestConnectionStringParsing (){
var builder = new MongoConnectionStringBuilder ("Username=testuser;Password=testpassword;Server=testserver:555;ConnectionLifetime=50;MaximumPoolSize=101;MinimumPoolSize=202;Pooled=false");
Assert.AreEqual ("testuser", builder.Username);
Assert.AreEqual ("testpassword", builder.Password);
Assert.AreEqual (101, builder.MaximumPoolSize);
Assert.AreEqual (202, builder.MinimumPoolSize);
Assert.AreEqual (TimeSpan.FromSeconds (50), builder.ConnectionLifetime);
Assert.AreEqual (false, builder.Pooled);
var servers = new List<MongoServerEndPoint>(builder.Servers);
Assert.AreEqual (1, servers.Count);
Assert.AreEqual ("testserver", servers[0].Host);
Assert.AreEqual (555, servers[0].Port);
}
[Test]
public void TestConnectionStringParsingServerWithoutPort (){
var builder = new MongoConnectionStringBuilder ("Username=testuser;Password=testpassword;Server=testserver");
Assert.AreEqual ("testuser", builder.Username);
Assert.AreEqual ("testpassword", builder.Password);
var servers = new List<MongoServerEndPoint> (builder.Servers);
Assert.AreEqual (1, servers.Count);
Assert.AreEqual ("testserver", servers[0].Host);
Assert.AreEqual (MongoServerEndPoint.DefaultPort, servers[0].Port);
}
[Test]
public void TestToStringOutput (){
var builder = new MongoConnectionStringBuilder { Password = "testpassword", Username = "testusername", ConnectionLifetime = TimeSpan.FromSeconds (50), MaximumPoolSize = 101, MinimumPoolSize = 202, ConnectionTimeout = TimeSpan.FromSeconds(60)};
builder.AddServer ("testserver1", 555);
builder.AddServer ("testserver2");
Assert.AreEqual ("Username=testusername;Password=testpassword;Server=testserver1:555,testserver2;MaximumPoolSize=101;MinimumPoolSize=202;ConnectionTimeout=60;ConnectionLifetime=50", builder.ToString ());
}
[Test]
public void TestToStringOutputWithoutUsernameAndPassword (){
var builder = new MongoConnectionStringBuilder ();
builder.AddServer ("testserver", 555);
Assert.AreEqual ("Server=testserver:555", builder.ToString ());
}
[Test]
public void TestToStringOutputWithDefaultServerPort (){
var builder = new MongoConnectionStringBuilder ();
builder.AddServer ("testserver");
Assert.AreEqual ("Server=testserver", builder.ToString ());
}
}
}