mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-14 09:59:48 -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
88 lines
3.2 KiB
C#
88 lines
3.2 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 System.Composition;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using Microsoft.SqlTools.Extensibility;
|
|
using Microsoft.SqlTools.ServiceLayer.Formatter;
|
|
using Xunit;
|
|
|
|
namespace Microsoft.SqlTools.ServiceLayer.UnitTests.Extensibility
|
|
{
|
|
public class ExtensionTests
|
|
{
|
|
|
|
[Fact]
|
|
public void CreateAssemblyStoreShouldFindTypesInAssembly()
|
|
{
|
|
// Given a store for MyExportType
|
|
ExtensionStore store = ExtensionStore.CreateAssemblyStore<MyExportType>(GetType().GetTypeInfo().Assembly);
|
|
// Then should get any export for this type and subtypes
|
|
Assert.Equal(2, store.GetExports<MyExportType>().Count());
|
|
|
|
// But for a different type, expect throw as the store only contains MyExportType
|
|
Assert.Throws<InvalidCastException>(() => store.GetExports<MyOtherType>().Count());
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateDefaultLoaderShouldFindTypesOnlyInMainAssembly()
|
|
{
|
|
// Given a store created using CreateDefaultLoader
|
|
// Then not should find exports from a different assembly
|
|
ExtensionStore store = ExtensionStore.CreateDefaultLoader<MyExportType>();
|
|
Assert.Equal(0, store.GetExports<MyExportType>().Count());
|
|
|
|
// And should not find exports that are defined in the ServiceLayer assembly
|
|
store = ExtensionStore.CreateDefaultLoader<ASTNodeFormatterFactory>();
|
|
Assert.Empty(store.GetExports<ASTNodeFormatterFactory>());
|
|
}
|
|
|
|
[Fact]
|
|
public void CreateDefaultServiceProviderShouldFindTypesInAllKnownAssemblies()
|
|
{
|
|
// Given a default ExtensionServiceProvider
|
|
// Then we should not find exports from a test assembly
|
|
ExtensionServiceProvider serviceProvider = ExtensionServiceProvider.CreateDefaultServiceProvider();
|
|
Assert.Empty(serviceProvider.GetServices<MyExportType>());
|
|
|
|
// But should find exports that are defined in the main assembly
|
|
Assert.NotEmpty(serviceProvider.GetServices<ASTNodeFormatterFactory>());
|
|
}
|
|
|
|
// [Fact]
|
|
public void CreateStoreForCurrentDirectoryShouldFindExportsInDirectory()
|
|
{
|
|
// Given stores created for types in different assemblies
|
|
ExtensionStore myStore = ExtensionStore.CreateStoreForCurrentDirectory<MyExportType>();
|
|
ExtensionStore querierStore = ExtensionStore.CreateStoreForCurrentDirectory<ASTNodeFormatterFactory>();
|
|
|
|
// When I query exports
|
|
// Then exports for all assemblies should be found
|
|
Assert.Equal(2, myStore.GetExports<MyExportType>().Count());
|
|
Assert.NotEmpty(querierStore.GetExports<ASTNodeFormatterFactory>());
|
|
}
|
|
}
|
|
|
|
// Note: in order for the MEF lookup to succeed, one class must have
|
|
[Export(typeof(MyExportType))]
|
|
public class MyExportType
|
|
{
|
|
|
|
}
|
|
|
|
public class MyExportSubType : MyExportType
|
|
{
|
|
|
|
}
|
|
|
|
public class MyOtherType
|
|
{
|
|
|
|
}
|
|
}
|
|
|