Supporting SQL DW in Object explorer (#380)

* supporting sql dw in oe
This commit is contained in:
Leila Lali
2017-06-15 12:53:32 -07:00
committed by GitHub
parent d9e68831ab
commit 71b349f67b
20 changed files with 544 additions and 152 deletions

View File

@@ -0,0 +1,162 @@
//
// 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.Contracts;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class ServerVersionHelperTests
{
[Fact]
public void GetValidForFlagShouldReturnAllGivenUnKnownVersion()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.Unknown);
ValidForFlag expected = ValidForFlag.All;
Assert.Equal(validforFlag, expected);
}
[Fact]
public void GetValidForFlagShouldReturnTheFlagCorrectlyGivenValidVersion()
{
VerifyGetValidForFlag(SqlServerType.AzureV12, ValidForFlag.AzureV12);
VerifyGetValidForFlag(SqlServerType.Sql2005, ValidForFlag.Sql2005);
VerifyGetValidForFlag(SqlServerType.Sql2008, ValidForFlag.Sql2008);
VerifyGetValidForFlag(SqlServerType.Sql2012, ValidForFlag.Sql2012);
VerifyGetValidForFlag(SqlServerType.Sql2014, ValidForFlag.Sql2014);
VerifyGetValidForFlag(SqlServerType.Sql2016, ValidForFlag.Sql2016);
VerifyGetValidForFlag(SqlServerType.Sql2017, ValidForFlag.Sql2017);
}
[Fact]
public void GetValidForFlagShouldReturnTheFlagIncludingSqlDwGivenSqlDwdatabase()
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(SqlServerType.AzureV12, true);
ValidForFlag expected = ValidForFlag.SqlDw;
Assert.Equal(validforFlag, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2005Given2005Version()
{
string serverVersion = "9.1.2.3";
SqlServerType expected = SqlServerType.Sql2005;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2008Given2008Version()
{
string serverVersion = "10.1.2.3";
SqlServerType expected = SqlServerType.Sql2008;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2012Given2012Version()
{
string serverVersion = "11.1.2.3";
SqlServerType expected = SqlServerType.Sql2012;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2014Given2014Version()
{
string serverVersion = "12.1.2.3";
SqlServerType expected = SqlServerType.Sql2014;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2016Given2016Version()
{
string serverVersion = "13.1.2.3";
SqlServerType expected = SqlServerType.Sql2016;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void CalculateServerTypeShouldReturnSql2017Given2017Version()
{
string serverVersion = "14.1.2.3";
SqlServerType expected = SqlServerType.Sql2017;
VerifyCalculateServerType(serverVersion, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndAll()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.All;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndNone()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.None;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.SqlDw;
bool expected = true;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndNotSqlDw()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.NotSqlDw;
bool expected = false;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
[Fact]
public void IsValidForShouldReturnTrueGivenSqlDwAndAllOnPrem()
{
ValidForFlag serverValidFor = ValidForFlag.SqlDw;
ValidForFlag validFor = ValidForFlag.AllOnPrem;
bool expected = false;
VerifyIsValidFor(serverValidFor, validFor, expected);
}
private void VerifyIsValidFor(ValidForFlag serverValidFor, ValidForFlag validFor, bool expected)
{
bool actual = ServerVersionHelper.IsValidFor(serverValidFor, validFor);
Assert.Equal(expected, actual);
}
private void VerifyCalculateServerType(string serverVersion, SqlServerType expected)
{
ServerInfo serverInfo = new ServerInfo
{
ServerVersion = serverVersion
};
SqlServerType actual = ServerVersionHelper.CalculateServerType(serverInfo);
Assert.Equal(expected, actual);
}
private void VerifyGetValidForFlag(SqlServerType serverType, ValidForFlag validForFlag)
{
ValidForFlag validforFlag = ServerVersionHelper.GetValidForFlag(serverType);
ValidForFlag expected = validForFlag;
Assert.Equal(validforFlag, expected);
}
}
}

View File

@@ -1,65 +1,108 @@
//
// 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 System.Linq;
using Microsoft.SqlServer.Management.Smo;
//
// 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 System.Linq;
using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlTools.Extensibility;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class SmoQueryModelTests
{
[Fact]
public void ShouldFindDatabaseQuerierFromRealPath()
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a database compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database)));
// Then I expect to get back the SqlDatabaseQuerier
Assert.NotNull(querier);
Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType());
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider);
}
[Fact]
public void ShouldFindQuerierIfInExtensionList()
{
VerifyQuerierLookup(typeof(Table), typeof(SqlTableQuerier), expectExists: true);
}
[Fact]
public void ShouldNotFindQuerierIfNotInExtensionList()
{
VerifyQuerierLookup(typeof(Database), null, expectExists: false);
}
private static void VerifyQuerierLookup(Type smoType, Type querierType, bool expectExists)
{
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.Create(new Type[] {
typeof(SqlTableQuerier),
typeof(SqlLinkedServerQuerier)
});
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(smoType));
if (expectExists)
{
Assert.NotNull(querier);
Assert.Equal(querierType, querier.GetType());
Assert.NotNull(querier.ServiceProvider);
}
else
{
Assert.Null(querier);
}
}
}
}
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer;
using Microsoft.SqlTools.ServiceLayer.ObjectExplorer.SmoModel;
using Xunit;
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.ObjectExplorer
{
public class SmoQueryModelTests
{
[Fact]
public void ShouldFindDatabaseQuerierFromRealPath()
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a database compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(typeof(Database)));
// Then I expect to get back the SqlDatabaseQuerier
Assert.NotNull(querier);
Assert.Equal(typeof(SqlDatabaseQuerier), querier.GetType());
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider);
}
[Fact]
public void ShouldFindQuerierIfInExtensionList()
{
VerifyQuerierLookup(typeof(Table), typeof(SqlTableQuerier), expectExists: true);
}
[Fact]
public void ShouldNotFindQuerierIfNotInExtensionList()
{
VerifyQuerierLookup(typeof(Database), null, expectExists: false);
}
[Fact]
public void SqlServerDdlTriggerQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(ServerDdlTrigger));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
public void SqlSynonymQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(Synonym));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
public void SqlTriggerQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(Trigger));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
[Fact]
public void SqlFullTextIndexQuerierShouldNotBeAvailableForSqlDw()
{
SmoQuerier querier = GetSmoQuerier(typeof(FullTextIndex));
Assert.False(querier.ValidFor.HasFlag(ValidForFlag.SqlDw));
}
private SmoQuerier GetSmoQuerier(Type querierType)
{
// Given the extension type loader is set to find SmoCollectionQuerier objects
IMultiServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
// When I request a compatible querier
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(querierType));
// Then I expect to get back the Querier
Assert.NotNull(querier);
// And I expect the service provider to have been set by the extension code
Assert.NotNull(querier.ServiceProvider);
return querier;
}
private static void VerifyQuerierLookup(Type smoType, Type querierType, bool expectExists)
{
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.Create(new Type[] {
typeof(SqlTableQuerier),
typeof(SqlLinkedServerQuerier)
});
SmoQuerier querier = serviceProvider.GetService<SmoQuerier>(q => q.SupportedObjectTypes.Contains(smoType));
if (expectExists)
{
Assert.NotNull(querier);
Assert.Equal(querierType, querier.GetType());
Assert.NotNull(querier.ServiceProvider);
}
else
{
Assert.Null(querier);
}
}
}
}