Skip to content

Commit fb924ce

Browse files
author
Zhen
committed
Add example code for 1.5 driver documentation
1 parent 88d249f commit fb924ce

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

Neo4j.Driver/Neo4j.Driver.IntegrationTests/Examples.cs

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,70 @@ public void TestBasicAuthExample()
8585
}
8686
}
8787

88+
public class ConfigConnectionPoolExample : BaseExample
89+
{
90+
public ConfigConnectionPoolExample(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
91+
: base(output, fixture)
92+
{
93+
}
94+
95+
// tag::config-connection-pool[]
96+
public IDriver CreateDriverWithCustomizedConnectionPool(string uri, string user, string password)
97+
{
98+
return GraphDatabase.Driver(uri, AuthTokens.Basic(user, password),
99+
new Config
100+
{
101+
MaxConnectionLifetime = TimeSpan.FromMinutes(30),
102+
MaxConnectionPoolSize = 50, MaxIdleConnectionPoolSize = 50,
103+
ConnectionAcquisitionTimeout = TimeSpan.FromMinutes(2)
104+
});
105+
}
106+
// end::config-connection-pool[]
107+
108+
[RequireServerFact]
109+
public void TestConfigConnectionPoolExample()
110+
{
111+
// Given
112+
using (var driver = CreateDriverWithCustomizedConnectionPool(Uri, User, Password))
113+
using (var session = driver.Session())
114+
{
115+
// When & Then
116+
session.Run("RETURN 1").Single()[0].As<int>().Should().Be(1);
117+
}
118+
}
119+
}
120+
121+
public class ConfigLoadBalancingStrategyExample : BaseExample
122+
{
123+
public ConfigLoadBalancingStrategyExample(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)
124+
: base(output, fixture)
125+
{
126+
}
127+
128+
// tag::config-load-balancing-strategy[]
129+
public IDriver CreateDriverWithCustomizedLoadBalancingStrategy(string uri, string user, string password)
130+
{
131+
return GraphDatabase.Driver(uri, AuthTokens.Basic(user, password),
132+
new Config
133+
{
134+
LoadBalancingStrategy = LoadBalancingStrategy.LeastConnected
135+
});
136+
}
137+
// end::config-load-balancing-strategy[]
138+
139+
[RequireServerFact]
140+
public void TestConfigLoadBalancingStrategyExample()
141+
{
142+
// Given
143+
using (var driver = CreateDriverWithCustomizedLoadBalancingStrategy(Uri, User, Password))
144+
using (var session = driver.Session())
145+
{
146+
// When & Then
147+
session.Run("RETURN 1").Single()[0].As<int>().Should().Be(1);
148+
}
149+
}
150+
}
151+
88152
public class ConfigConnectionTimeoutExample : BaseExample
89153
{
90154
public ConfigConnectionTimeoutExample(ITestOutputHelper output, StandAloneIntegrationTestFixture fixture)

0 commit comments

Comments
 (0)