提交 d1770cc9 编写于 作者: S Sam Harwell

Use IClassificationTypeRegistryService instead of faking the behavior

This change suggested by @jasonmalinowski makes the ClassificationTypeExported test
simpler and more accurate.
上级 ad0a00bb
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using Microsoft.CodeAnalysis.Classification;
using Microsoft.VisualStudio.Text.Classification;
......@@ -29,26 +27,11 @@ public static IEnumerable<object[]> AllClassificationTypeNames
[WorkItem(25716, "https://github.com/dotnet/roslyn/issues/25716")]
public void ClassificationTypeExported(string fieldName, object constantValue)
{
Assert.IsType<string>(constantValue);
string classificationTypeName = (string)constantValue;
var classificationTypeName = Assert.IsType<string>(constantValue);
var exportProvider = TestExportProvider.ExportProviderWithCSharpAndVisualBasic;
var exports = exportProvider.GetExports<ClassificationTypeDefinition, IClassificationTypeDefinitionMetadata>();
var export = exports.FirstOrDefault(x => x.Metadata.Name == classificationTypeName);
Assert.True(export != null, $"{nameof(ClassificationTypeNames)}.{fieldName} has value \"{classificationTypeName}\", but no matching {nameof(ClassificationTypeDefinition)} was exported.");
}
public interface IClassificationTypeDefinitionMetadata
{
string Name
{
get;
}
[DefaultValue(null)]
IEnumerable<string> BaseDefinition
{
get;
}
var classificationTypeRegistryService = exportProvider.GetExport<IClassificationTypeRegistryService>().Value;
var classificationType = classificationTypeRegistryService.GetClassificationType(classificationTypeName);
Assert.True(classificationType != null, $"{nameof(ClassificationTypeNames)}.{fieldName} has value \"{classificationTypeName}\", but no matching {nameof(ClassificationTypeDefinition)} was exported.");
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册