Skip to content

Commit

Permalink
Naming convention for private properties.
Browse files Browse the repository at this point in the history
Review fixes
  • Loading branch information
sfc-gh-mhofman committed Nov 6, 2023
1 parent f674e86 commit 30a3c7c
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 73 deletions.
24 changes: 24 additions & 0 deletions CodingConventions.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ public class ExampleClass
}
```

#### Public property

Use PascalCase, eg. `SomeProperty`.

```csharp
public ExampleProperty
{
get => _exampleProperty;
set => _exampleProperty = value;
}
```

### Local variables

Use camelCase, eg. `someVariable`.
Expand All @@ -105,6 +117,18 @@ Use PascalCase, eg. `SomeConst`.
}
```

#### Private or internal property

Use camelCase, eg. `someProperty`.

```csharp
private exampleProperty
{
get;
set;
}
```

### Method names

Use PascalCase, eg. `SomeMethod` for all methods (normal, object members, static members, public, internal, private).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ public class ConnectionPoolManagerSwitchTest
[Test]
public void TestRevertPoolToPreviousVersion()
{
// act
SnowflakeDbConnectionPool.SetOldConnectionPoolVersion();

// assert
var sessionPool1 = SnowflakeDbConnectionPool.GetPool(_connectionString1);
var sessionPool2 = SnowflakeDbConnectionPool.GetPool(_connectionString2);
Assert.AreEqual(ConnectionPoolType.SingleConnectionCache, SnowflakeDbConnectionPool.GetConnectionPoolVersion());
Assert.AreEqual(sessionPool1, sessionPool2);
}
}
}
}

85 changes: 42 additions & 43 deletions Snowflake.Data.Tests/UnitTests/ConnectionPoolManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ namespace Snowflake.Data.Tests.UnitTests
class ConnectionPoolManagerTest
{
private readonly ConnectionPoolManager _connectionPoolManager = new ConnectionPoolManager();
private readonly string _connectionString1 = "database=D1;warehouse=W1;account=A1;user=U1;password=P1;role=R1;";
private readonly string _connectionString2 = "database=D2;warehouse=W2;account=A2;user=U2;password=P2;role=R2;";
private const string ConnectionString1 = "database=D1;warehouse=W1;account=A1;user=U1;password=P1;role=R1;";
private const string ConnectionString2 = "database=D2;warehouse=W2;account=A2;user=U2;password=P2;role=R2;";
private readonly SecureString _password = new SecureString();
private static PoolConfig s_poolConfig;

Expand All @@ -29,35 +29,35 @@ public static void BeforeAllTests()
{
s_poolConfig = new PoolConfig();
SnowflakeDbConnectionPool.SetConnectionPoolVersion(ConnectionPoolType.MultipleConnectionPool);
SessionPool.SessionFactory = new MockSessionFactory();
SessionPool.sessionFactory = new MockSessionFactory();
}

[OneTimeTearDown]
public void AfterAllTests()
{
s_poolConfig.Reset();
SessionPool.SessionFactory = new SessionFactory();
SessionPool.sessionFactory = new SessionFactory();
}

[Test]
public void TestPoolManagerReturnsSessionPoolForGivenConnectionString()
{
// Act
var sessionPool = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool = _connectionPoolManager.GetPool(ConnectionString1, _password);

// Assert
Assert.AreEqual(_connectionString1, sessionPool.ConnectionString);
Assert.AreEqual(_password, sessionPool.Password);
Assert.AreEqual(ConnectionString1, sessionPool._connectionString);
Assert.AreEqual(_password, sessionPool._password);
}

[Test]
public void TestPoolManagerReturnsSamePoolForGivenConnectionString()
{
// Arrange
var anotherConnectionString = _connectionString1;
var anotherConnectionString = ConnectionString1;

// Act
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(anotherConnectionString, _password);

// Assert
Expand All @@ -68,38 +68,38 @@ public void TestPoolManagerReturnsSamePoolForGivenConnectionString()
public void TestDifferentPoolsAreReturnedForDifferentConnectionStrings()
{
// Arrange
Assert.AreNotSame(_connectionString1, _connectionString2);
Assert.AreNotSame(ConnectionString1, ConnectionString2);

// Act
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);

// Assert
Assert.AreNotSame(sessionPool1, sessionPool2);
Assert.AreEqual(_connectionString1, sessionPool1.ConnectionString);
Assert.AreEqual(_connectionString2, sessionPool2.ConnectionString);
Assert.AreEqual(ConnectionString1, sessionPool1._connectionString);
Assert.AreEqual(ConnectionString2, sessionPool2._connectionString);
}


[Test]
public void TestGetSessionWorksForSpecifiedConnectionString()
{
// Act
var sfSession = _connectionPoolManager.GetSession(_connectionString1, _password);
var sfSession = _connectionPoolManager.GetSession(ConnectionString1, _password);

// Assert
Assert.AreEqual(_connectionString1, sfSession.ConnectionString);
Assert.AreEqual(ConnectionString1, sfSession.ConnectionString);
Assert.AreEqual(_password, sfSession.Password);
}

[Test]
public async Task TestGetSessionAsyncWorksForSpecifiedConnectionString()
{
// Act
var sfSession = await _connectionPoolManager.GetSessionAsync(_connectionString1, _password, CancellationToken.None);
var sfSession = await _connectionPoolManager.GetSessionAsync(ConnectionString1, _password, CancellationToken.None);

// Assert
Assert.AreEqual(_connectionString1, sfSession.ConnectionString);
Assert.AreEqual(ConnectionString1, sfSession.ConnectionString);
Assert.AreEqual(_password, sfSession.Password);
}

Expand All @@ -108,33 +108,33 @@ public async Task TestGetSessionAsyncWorksForSpecifiedConnectionString()
public void TestCountingOfSessionProvidedByPool()
{
// Act
_connectionPoolManager.GetSession(_connectionString1, _password);
_connectionPoolManager.GetSession(ConnectionString1, _password);

// Assert
var sessionPool = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool = _connectionPoolManager.GetPool(ConnectionString1, _password);
Assert.AreEqual(1, sessionPool.GetCurrentPoolSize());
}

[Test]
public void TestCountingOfSessionReturnedBackToPool()
{
// Arrange
var sfSession = _connectionPoolManager.GetSession(_connectionString1, _password);
var sfSession = _connectionPoolManager.GetSession(ConnectionString1, _password);

// Act
_connectionPoolManager.AddSession(sfSession);

// Assert
var sessionPool = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool = _connectionPoolManager.GetPool(ConnectionString1, _password);
Assert.AreEqual(1, sessionPool.GetCurrentPoolSize());
}

[Test]
public void TestSetMaxPoolSizeForAllPools()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);

// Act
_connectionPoolManager.SetMaxPoolSize(3);
Expand All @@ -148,8 +148,8 @@ public void TestSetMaxPoolSizeForAllPools()
public void TestSetTimeoutForAllPools()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);

// Act
_connectionPoolManager.SetTimeout(3000);
Expand All @@ -163,7 +163,7 @@ public void TestSetTimeoutForAllPools()
public void TestSetPoolingDisabledForAllPools()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);

// Act
_connectionPoolManager.SetPooling(false);
Expand All @@ -176,7 +176,7 @@ public void TestSetPoolingDisabledForAllPools()
public void TestSetPoolingEnabledBack()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
_connectionPoolManager.SetPooling(false);

// Act
Expand All @@ -190,8 +190,8 @@ public void TestSetPoolingEnabledBack()
public void TestGetPoolingOnManagerLevelWhenNotAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetPooling(true);
sessionPool2.SetPooling(false);

Expand All @@ -206,8 +206,8 @@ public void TestGetPoolingOnManagerLevelWhenNotAllPoolsEqual()
public void TestGetPoolingOnManagerLevelWorksWhenAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetPooling(true);
sessionPool2.SetPooling(true);

Expand All @@ -219,8 +219,8 @@ public void TestGetPoolingOnManagerLevelWorksWhenAllPoolsEqual()
public void TestGetTimeoutOnManagerLevelWhenNotAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetTimeout(299);
sessionPool2.SetTimeout(1313);

Expand All @@ -235,8 +235,8 @@ public void TestGetTimeoutOnManagerLevelWhenNotAllPoolsEqual()
public void TestGetTimeoutOnManagerLevelWhenAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetTimeout(3600);
sessionPool2.SetTimeout(3600);

Expand All @@ -248,8 +248,8 @@ public void TestGetTimeoutOnManagerLevelWhenAllPoolsEqual()
public void TestGetMaxPoolSizeOnManagerLevelWhenNotAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetMaxPoolSize(1);
sessionPool2.SetMaxPoolSize(17);

Expand All @@ -264,8 +264,8 @@ public void TestGetMaxPoolSizeOnManagerLevelWhenNotAllPoolsEqual()
public void TestGetMaxPoolSizeOnManagerLevelWhenAllPoolsEqual()
{
// Arrange
var sessionPool1 = _connectionPoolManager.GetPool(_connectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(_connectionString2, _password);
var sessionPool1 = _connectionPoolManager.GetPool(ConnectionString1, _password);
var sessionPool2 = _connectionPoolManager.GetPool(ConnectionString2, _password);
sessionPool1.SetMaxPoolSize(33);
sessionPool2.SetMaxPoolSize(33);

Expand All @@ -277,8 +277,8 @@ public void TestGetMaxPoolSizeOnManagerLevelWhenAllPoolsEqual()
public void TestGetCurrentPoolSizeThrowsExceptionWhenNotAllPoolsEqual()
{
// Arrange
EnsurePoolSize(_connectionString1, 2);
EnsurePoolSize(_connectionString2, 3);
EnsurePoolSize(ConnectionString1, 2);
EnsurePoolSize(ConnectionString2, 3);

// Act/Assert
var exception = Assert.Throws<SnowflakeDbException>(() => _connectionPoolManager.GetCurrentPoolSize());
Expand Down Expand Up @@ -320,5 +320,4 @@ public SFSession NewSession(string connectionString, SecureString password)
return mockSfSession.Object;
}
}

}
2 changes: 1 addition & 1 deletion Snowflake.Data.Tests/Util/PoolConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ public PoolConfig()

public void Reset()
{
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolType);
SnowflakeDbConnectionPool.SetMaxPoolSize(_maxPoolSize);
SnowflakeDbConnectionPool.SetTimeout(_timeout);
SnowflakeDbConnectionPool.SetPooling(_pooling);
SnowflakeDbConnectionPool.SetConnectionPoolVersion(_connectionPoolType);
}
}
}
Loading

0 comments on commit 30a3c7c

Please sign in to comment.