mirror of
https://github.com/aphrody-labs/NuGet.Client.git
synced 2026-10-15 05:49:05 +00:00
Resolves NuGet/Home#5258. Added tests for basic scenarios per each project model supporting LSL mode: `packages.config`, `project.json`, `PackageRef`. Updated E2E test infrastructure to support test extension cmdlets and running "theories". Added ability to skip tests for specific VS version. Also added missing templates for unit-test project and native C++ console application. Addressed PR feedback
51 lines
1.6 KiB
C#
51 lines
1.6 KiB
C#
// Copyright (c) .NET Foundation. All rights reserved.
|
|
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
|
|
|
|
using Microsoft;
|
|
using Microsoft.VisualStudio.ComponentModelHost;
|
|
using Microsoft.VisualStudio.Shell;
|
|
using Microsoft.VisualStudio.Shell.Interop;
|
|
using Microsoft.VisualStudio.Threading;
|
|
|
|
namespace API.Test
|
|
{
|
|
internal static class ServiceLocator
|
|
{
|
|
private static readonly AsyncLazy<IComponentModel> _componentModel;
|
|
|
|
public static EnvDTE.DTE GetDTE() => GetService<SDTE, EnvDTE.DTE>();
|
|
|
|
public static IComponentModel ComponentModel => ThreadHelper.JoinableTaskFactory.Run(_componentModel.GetValueAsync);
|
|
|
|
static ServiceLocator()
|
|
{
|
|
_componentModel = new AsyncLazy<IComponentModel>(
|
|
async () =>
|
|
{
|
|
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
|
|
return GetService<SComponentModel, IComponentModel>();
|
|
},
|
|
ThreadHelper.JoinableTaskFactory);
|
|
}
|
|
|
|
public static TInterface GetService<TService, TInterface>()
|
|
where TInterface : class
|
|
{
|
|
ThreadHelper.ThrowIfNotOnUIThread();
|
|
|
|
var instance = Package.GetGlobalService(typeof(TService)) as TInterface;
|
|
Assumes.Present(instance);
|
|
|
|
return instance;
|
|
}
|
|
|
|
public static TService GetComponent<TService>() where TService : class
|
|
{
|
|
var service = ComponentModel.GetService<TService>();
|
|
Assumes.Present(service);
|
|
|
|
return service;
|
|
}
|
|
}
|
|
}
|