-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added testing for toml builder and snowflakedbconnection
- Loading branch information
1 parent
3a24629
commit 9c94717
Showing
5 changed files
with
345 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
Snowflake.Data.Tests/UnitTests/ConnectionTomlReaderTest.cs
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
Snowflake.Data.Tests/UnitTests/SnowflakeDbConnectionTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
|
||
namespace Snowflake.Data.Tests.UnitTests | ||
{ | ||
using Core; | ||
using Core.Tools; | ||
using Moq; | ||
using NUnit.Framework; | ||
using Snowflake.Data.Client; | ||
|
||
public class SnowflakeDbConnectionTest | ||
{ | ||
[Test] | ||
public void TestFillConnectionStringFromTomlConfig() | ||
{ | ||
// Arrange | ||
var mockFileOperations = new Mock<FileOperations>(); | ||
var mockEnvironmentOperations = new Mock<EnvironmentOperations>(); | ||
mockEnvironmentOperations.Setup(e => e.GetEnvironmentVariable(It.IsAny<string>(), It.IsAny<string>())) | ||
.Returns((string v, string d) => d); | ||
mockFileOperations.Setup(f => f.Exists(It.IsAny<string>())).Returns(true); | ||
mockFileOperations.Setup(f => f.ReadAllText(It.IsAny<string>())) | ||
.Returns("[default]\naccount=\"testaccount\"\nuser=\"testuser\"\npassword=\"testpassword\"\n"); | ||
var tomlConnectionBuilder = new SnowflakeTomlConnectionBuilder(mockFileOperations.Object, mockEnvironmentOperations.Object); | ||
|
||
// Act | ||
using (var conn = new SnowflakeDbConnection(tomlConnectionBuilder)) | ||
{ | ||
conn.ConnectionString = "account=user1account;user=user1;password=user1password;"; | ||
conn.FillConnectionStringFromTomlConfigIfNotSet(); | ||
// Assert | ||
Assert.AreNotEqual("account=testaccount;user=testuser;password=testpassword;", conn.ConnectionString); | ||
Assert.AreNotEqual("account=testaccount;user=testuser;password=testpassword;", conn.ConnectionString); | ||
} | ||
} | ||
|
||
[Test] | ||
public void TestFillConnectionStringFromTomlConfigShouldNotBeExecutedIfAlreadySetConnectionString() | ||
{ | ||
// Arrange | ||
var connectionTest = "account=user1account;user=user1;password=user1password;"; | ||
var mockFileOperations = new Mock<FileOperations>(); | ||
var mockEnvironmentOperations = new Mock<EnvironmentOperations>(); | ||
mockEnvironmentOperations.Setup(e => e.GetEnvironmentVariable(It.IsAny<string>(), It.IsAny<string>())) | ||
.Returns((string v, string d) => d); | ||
mockFileOperations.Setup(f => f.Exists(It.IsAny<string>())).Returns(true); | ||
mockFileOperations.Setup(f => f.ReadAllText(It.IsAny<string>())) | ||
.Returns("[default]\naccount=\"testaccount\"\nuser=\"testuser\"\npassword=\"testpassword\"\n"); | ||
var tomlConnectionBuilder = new SnowflakeTomlConnectionBuilder(mockFileOperations.Object, mockEnvironmentOperations.Object); | ||
|
||
// Act | ||
using (var conn = new SnowflakeDbConnection(tomlConnectionBuilder)) | ||
{ | ||
conn.ConnectionString = connectionTest; | ||
conn.FillConnectionStringFromTomlConfigIfNotSet(); | ||
// Assert | ||
Assert.AreEqual(connectionTest, conn.ConnectionString); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.