mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:35:43 -05:00
* 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
82 lines
3.0 KiB
C#
82 lines
3.0 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 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));
|
|
}
|
|
}
|
|
} |