Fix: SqlDw connection setup change (#221)

* adding sqldw check and caching

* adding tests for caching layer

* simplifying caching logic and fixing tests

* cleaning up previous logic

* removing locale files i accidently pushed
This commit is contained in:
Raymond Martin
2017-02-01 10:15:52 -08:00
committed by GitHub
parent 857b526553
commit 8c6014b81c
5 changed files with 227 additions and 11 deletions

View File

@@ -0,0 +1,82 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using System;
using Xunit;
using Microsoft.SqlTools.ServiceLayer.Connection.ReliableConnection;
namespace Microsoft.SqlTools.ServiceLayer.Test.Connection
{
/// <summary>
/// Tests for Sever Information Caching Class
/// </summary>
public class CachedServerInfoTests
{
[Theory]
[InlineData(true)] // is SqlDW instance
[InlineData(false)] // is not a SqlDw Instance
public void AddOrUpdateIsSqlDw(bool state)
{
// Set sqlDw result into cache
bool isSqlDwResult;
CachedServerInfo.AddOrUpdateCache("testDataSource", state, CachedServerInfo.CacheVariable.IsSqlDw);
// Expect the same returned result
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", 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;
CachedServerInfo.AddOrUpdateCache("testDataSource", state, CachedServerInfo.CacheVariable.IsSqlDw);
// Expect the same returned result
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResult));
Assert.Equal(isSqlDwResult, state);
// Toggle isSqlDw cache state
bool isSqlDwResultToggle;
CachedServerInfo.AddOrUpdateCache("testDataSource", !state, CachedServerInfo.CacheVariable.IsSqlDw);
// Expect the oppisite returned result
Assert.True(CachedServerInfo.TryGetIsSqlDw("testDataSource", out isSqlDwResultToggle));
Assert.Equal(isSqlDwResultToggle, !state);
}
[Fact]
public void AddOrUpdateIsSqlDwFalseToggle()
{
bool state = true;
// 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));
// Assert cache is set on a per connection basis
Assert.Equal(isSqlDwResult, state);
Assert.Equal(isSqlDwResult2, !state);
}
[Fact]
public void AskforSqlDwBeforeCached()
{
bool isSqlDwResult;
Assert.False(CachedServerInfo.TryGetIsSqlDw("testDataSourceWithNoCache", out isSqlDwResult));
}
}
}