mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 01:25:40 -05:00
Merge from Master
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
|
||||
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
||||
using Xunit;
|
||||
using System.Data.SqlClient;
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
{
|
||||
@@ -13,18 +14,70 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
/// </summary>
|
||||
public class CachedServerInfoTests
|
||||
{
|
||||
private CachedServerInfo cache;
|
||||
|
||||
public CachedServerInfoTests()
|
||||
{
|
||||
cache = new CachedServerInfo();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CacheMatchesNullDbNameToEmptyString()
|
||||
{
|
||||
// Set sqlDw result into cache
|
||||
string dataSource = "testDataSource";
|
||||
bool isSqlDwResult;
|
||||
SqlConnectionStringBuilder testSource = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = dataSource,
|
||||
InitialCatalog = string.Empty
|
||||
};
|
||||
cache.AddOrUpdateCache(testSource, true, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the same returned result
|
||||
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
||||
Assert.True(isSqlDwResult);
|
||||
|
||||
// And expect the same for the null string
|
||||
Assert.True(cache.TryGetIsSqlDw(new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = dataSource
|
||||
// Initial Catalog is null. Can't set explicitly as this throws
|
||||
}, out isSqlDwResult));
|
||||
Assert.True(isSqlDwResult);
|
||||
|
||||
// But expect false for a different DB
|
||||
Assert.False(cache.TryGetIsSqlDw(new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = dataSource,
|
||||
InitialCatalog = "OtherDb"
|
||||
}, out isSqlDwResult));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(true)] // is SqlDW instance
|
||||
[InlineData(false)] // is not a SqlDw Instance
|
||||
public void AddOrUpdateIsSqlDw(bool state)
|
||||
[InlineData(null, true)] // is SqlDW instance
|
||||
[InlineData("", true)] // is SqlDW instance
|
||||
[InlineData("myDb", true)] // is SqlDW instance
|
||||
[InlineData(null, false)] // is not a SqlDw Instance
|
||||
[InlineData("", false)] // is not a SqlDw Instance
|
||||
[InlineData("myDb", false)] // is not SqlDW instance
|
||||
public void AddOrUpdateIsSqlDw(string dbName, bool state)
|
||||
{
|
||||
// Set sqlDw result into cache
|
||||
bool isSqlDwResult;
|
||||
CachedServerInfo.AddOrUpdateCache("testDataSource", state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
SqlConnectionStringBuilder testSource = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSource"
|
||||
};
|
||||
if (dbName != null)
|
||||
{
|
||||
testSource.InitialCatalog = dbName;
|
||||
}
|
||||
|
||||
cache.AddOrUpdateCache(testSource, state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the same returned result
|
||||
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResult));
|
||||
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
||||
Assert.Equal(isSqlDwResult, state);
|
||||
}
|
||||
|
||||
@@ -35,18 +88,22 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
{
|
||||
// Set sqlDw result into cache
|
||||
bool isSqlDwResult;
|
||||
CachedServerInfo.AddOrUpdateCache("testDataSource", state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
SqlConnectionStringBuilder testSource = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSource"
|
||||
};
|
||||
cache.AddOrUpdateCache(testSource, state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the same returned result
|
||||
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResult));
|
||||
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
||||
Assert.Equal(isSqlDwResult, state);
|
||||
|
||||
// Toggle isSqlDw cache state
|
||||
bool isSqlDwResultToggle;
|
||||
CachedServerInfo.AddOrUpdateCache("testDataSource", !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
cache.AddOrUpdateCache(testSource, !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the oppisite returned result
|
||||
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResultToggle));
|
||||
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResultToggle));
|
||||
Assert.Equal(isSqlDwResultToggle, !state);
|
||||
|
||||
}
|
||||
@@ -55,19 +112,40 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
public void AddOrUpdateIsSqlDwFalseToggle()
|
||||
{
|
||||
bool state = true;
|
||||
|
||||
SqlConnectionStringBuilder testSource = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSource"
|
||||
};
|
||||
|
||||
SqlConnectionStringBuilder sameServerDifferentDb = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSource",
|
||||
InitialCatalog = "myDb"
|
||||
};
|
||||
SqlConnectionStringBuilder differentServerSameDb = new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSource2",
|
||||
InitialCatalog = ""
|
||||
};
|
||||
|
||||
cache.AddOrUpdateCache(testSource, state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
cache.AddOrUpdateCache(sameServerDifferentDb, !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
cache.AddOrUpdateCache(differentServerSameDb, !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the same returned result
|
||||
// Set sqlDw result into cache
|
||||
bool isSqlDwResult;
|
||||
bool isSqlDwResult2;
|
||||
CachedServerInfo.AddOrUpdateCache("testDataSource", state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
CachedServerInfo.AddOrUpdateCache("testDataSource2", !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
||||
|
||||
// Expect the same returned result
|
||||
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResult));
|
||||
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource2", out isSqlDwResult2));
|
||||
bool isSqlDwResult3;
|
||||
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
||||
Assert.True(cache.TryGetIsSqlDw(sameServerDifferentDb, out isSqlDwResult2));
|
||||
Assert.True(cache.TryGetIsSqlDw(differentServerSameDb, out isSqlDwResult3));
|
||||
|
||||
// Assert cache is set on a per connection basis
|
||||
Assert.Equal(isSqlDwResult, state);
|
||||
Assert.Equal(isSqlDwResult2, !state);
|
||||
Assert.Equal(isSqlDwResult3, !state);
|
||||
|
||||
}
|
||||
|
||||
@@ -75,7 +153,11 @@ namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
||||
public void AskforSqlDwBeforeCached()
|
||||
{
|
||||
bool isSqlDwResult;
|
||||
Assert.False(CachedServerInfo.TryGetIsSqlDw("testDataSourceWithNoCache", out isSqlDwResult));
|
||||
Assert.False(cache.TryGetIsSqlDw(new SqlConnectionStringBuilder
|
||||
{
|
||||
DataSource = "testDataSourceUnCached"
|
||||
},
|
||||
out isSqlDwResult));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user