mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-13 17:23:02 -05:00
* Initial .net core 2.0 conversion * Convert a few more projects to .net core 2.0 * Convert a few more projects to .net core 2.0 * Fix build.cmd errors * Add mising nuget package * Remove dead code * Add checked in references to workaround nuget package issues * Update SLN file to refer to correct csproj files * Rename applications to workaround .net core tooling bug * Update nuget package with SQL Parser changes * Add PreserveCompliationContext to avoid MEF bug * Update smo version to pickup .net core 2 changes * Pickup latest SMO changes to fix merge break * Actually pickup correct SMO binaries * Add support for SLES 12.2 * Fix break running archiving on Linux * Revert "Add support for SLES 12.2" This reverts commit 95cdb6d0e35a425be5c0081345d214079cbdc3db. * Update to latest SMO build * Install .Net Core 2 during install phase * Move .Net Core install * Try to reference dotnet.exe directly * Fix code coverage script for CSPROJ instead of project.json * Turn off test that is unreliable in AppVeyor builds. * Fix appveyor.yml line feed. * Turn off another flaky test failing in AppVeyor
163 lines
5.9 KiB
C#
163 lines
5.9 KiB
C#
//
|
|
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
//
|
|
|
|
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
|
|
using Xunit;
|
|
using System.Data.SqlClient;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Connection
|
|
{
|
|
/// <summary>
|
|
/// Tests for Sever Information Caching Class
|
|
/// </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(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;
|
|
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(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
|
Assert.Equal(isSqlDwResult, state);
|
|
}
|
|
|
|
[Theory]
|
|
[InlineData(true)] // is SqlDW instance
|
|
[InlineData(false)] // is not a SqlDw Instance
|
|
public void AddOrUpdateIsSqlDwFalseToggle(bool state)
|
|
{
|
|
// Set sqlDw result into cache
|
|
bool isSqlDwResult;
|
|
SqlConnectionStringBuilder testSource = new SqlConnectionStringBuilder
|
|
{
|
|
DataSource = "testDataSource"
|
|
};
|
|
cache.AddOrUpdateCache(testSource, state, CachedServerInfo.CacheVariable.IsSqlDw);
|
|
|
|
// Expect the same returned result
|
|
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResult));
|
|
Assert.Equal(isSqlDwResult, state);
|
|
|
|
// Toggle isSqlDw cache state
|
|
bool isSqlDwResultToggle;
|
|
cache.AddOrUpdateCache(testSource, !state, CachedServerInfo.CacheVariable.IsSqlDw);
|
|
|
|
// Expect the oppisite returned result
|
|
Assert.True(cache.TryGetIsSqlDw(testSource, out isSqlDwResultToggle));
|
|
Assert.Equal(isSqlDwResultToggle, !state);
|
|
|
|
}
|
|
|
|
// [Fact]
|
|
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;
|
|
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);
|
|
|
|
}
|
|
|
|
[Fact]
|
|
public void AskforSqlDwBeforeCached()
|
|
{
|
|
bool isSqlDwResult;
|
|
Assert.False(cache.TryGetIsSqlDw(new SqlConnectionStringBuilder
|
|
{
|
|
DataSource = "testDataSourceUnCached"
|
|
},
|
|
out isSqlDwResult));
|
|
}
|
|
}
|
|
} |