Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
42fe72da
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
42fe72da
编写于
4月 17, 2019
作者:
G
Gen Lu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests for experiment service
上级
0160f431
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
87 addition
and
16 deletion
+87
-16
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs
.../CompletionProviders/TypeImportCompletionProviderTests.cs
+68
-5
src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs
...stUtilities/Completion/AbstractCompletionProviderTests.cs
+4
-1
src/EditorFeatures/TestUtilities/Workspaces/CSharpTestWorkspaceFixture.cs
...es/TestUtilities/Workspaces/CSharpTestWorkspaceFixture.cs
+4
-2
src/EditorFeatures/TestUtilities/Workspaces/TestWorkspaceFixture.cs
...Features/TestUtilities/Workspaces/TestWorkspaceFixture.cs
+7
-6
src/EditorFeatures/TestUtilities/Workspaces/VisualBasicTestWorkspaceFixture.cs
...stUtilities/Workspaces/VisualBasicTestWorkspaceFixture.cs
+4
-2
未找到文件。
src/EditorFeatures/CSharpTest/Completion/CompletionProviders/TypeImportCompletionProviderTests.cs
浏览文件 @
42fe72da
// 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.Composition
;
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.Completion
;
using
Microsoft.CodeAnalysis.CSharp.Completion.Providers
;
using
Microsoft.CodeAnalysis.Editor.UnitTests
;
using
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
;
using
Microsoft.CodeAnalysis.Experiments
;
using
Microsoft.CodeAnalysis.Host.Mef
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.VisualStudio.Composition
;
using
Roslyn.Test.Utilities
;
using
Xunit
;
namespace
Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.Completion.CompletionProviders
{
[
UseExportProvider
]
public
class
TypeImportCompletionProviderTests
:
AbstractCSharpCompletionProviderTests
{
public
TypeImportCompletionProviderTests
(
CSharpTestWorkspaceFixture
workspaceFixture
)
:
base
(
workspaceFixture
)
...
...
@@ -29,25 +35,63 @@ protected override void SetWorkspaceOptions(TestWorkspace workspace)
.
WithChangedOption
(
CompletionOptions
.
ShowItemsFromUnimportedNamespaces
,
LanguageNames
.
CSharp
,
ShowImportCompletionItemsOptionValue
);
}
ExportProvider
_exportProvider
=
null
;
protected
override
ExportProvider
ExportProvider
{
get
{
if
(
_exportProvider
==
null
)
{
_exportProvider
=
ExportProviderCache
.
GetOrCreateExportProviderFactory
(
TestExportProvider
.
EntireAssemblyCatalogWithCSharpAndVisualBasic
.
WithPart
(
typeof
(
MockTypeImportCompletionExperimentationService
)))
.
CreateExportProvider
();
}
return
_exportProvider
;
}
}
#
region
"Option tests"
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
OptionSetToNull
()
public
async
Task
OptionSetToNull
_ExpEnabled
()
{
var
mockExperimentService
=
ExportProvider
.
GetExportedValue
<
MockTypeImportCompletionExperimentationService
>();
mockExperimentService
.
ExperimentEnabled
=
true
;
ShowImportCompletionItemsOptionValue
=
null
;
var
markup
=
@"
class Bar
{
$$
}"
;
await
Verify
NoItemsExist
Async
(
markup
);
await
Verify
AnyItemExists
Async
(
markup
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
OptionSetTo
False
()
public
async
Task
OptionSetTo
Null_ExpDisabled
()
{
ShowImportCompletionItemsOptionValue
=
null
;
var
markup
=
@"
class Bar
{
$$
}"
;
await
VerifyNoItemsExistAsync
(
markup
);
}
[
InlineData
(
true
)]
[
InlineData
(
false
)]
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
OptionSetToFalse
(
bool
isExperimentEnabled
)
{
var
mockExperimentService
=
ExportProvider
.
GetExportedValue
<
MockTypeImportCompletionExperimentationService
>();
mockExperimentService
.
ExperimentEnabled
=
isExperimentEnabled
;
ShowImportCompletionItemsOptionValue
=
false
;
var
markup
=
@"
class Bar
{
...
...
@@ -57,10 +101,16 @@ class Bar
await
VerifyNoItemsExistAsync
(
markup
);
}
[
Fact
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
OptionSetToTrue
()
[
InlineData
(
true
)]
[
InlineData
(
false
)]
[
Theory
,
Trait
(
Traits
.
Feature
,
Traits
.
Features
.
Completion
)]
public
async
Task
OptionSetToTrue
(
bool
isExperimentEnabled
)
{
var
mockExperimentService
=
ExportProvider
.
GetExportedValue
<
MockTypeImportCompletionExperimentationService
>();
mockExperimentService
.
ExperimentEnabled
=
isExperimentEnabled
;
ShowImportCompletionItemsOptionValue
=
true
;
var
markup
=
@"
class Bar
{
...
...
@@ -816,5 +866,18 @@ private Task VerifyTypeImportItemIsAbsentAsync(string markup, string expectedIte
{
return
VerifyItemIsAbsentAsync
(
markup
,
expectedItem
,
displayTextSuffix
:
displayTextSuffix
,
inlineDescription
:
inlineDescription
);
}
[
Shared
]
[
Export
(
typeof
(
MockTypeImportCompletionExperimentationService
))]
[
ExportWorkspaceService
(
typeof
(
IExperimentationService
),
WorkspaceKind
.
Test
)]
private
class
MockTypeImportCompletionExperimentationService
:
IExperimentationService
{
public
bool
ExperimentEnabled
{
get
;
set
;
}
=
false
;
public
bool
IsExperimentEnabled
(
string
experimentName
)
{
return
ExperimentEnabled
&&
WellKnownExperimentNames
.
TypeImportCompletion
.
Equals
(
experimentName
);
}
}
}
}
src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs
浏览文件 @
42fe72da
...
...
@@ -15,6 +15,7 @@
using
Microsoft.CodeAnalysis.Shared.Extensions
;
using
Microsoft.CodeAnalysis.Test.Utilities
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.VisualStudio.Composition
;
using
Microsoft.VisualStudio.Language.Intellisense
;
using
Microsoft.VisualStudio.Text
;
using
Microsoft.VisualStudio.Text.Editor
;
...
...
@@ -149,12 +150,14 @@ internal static CompletionHelper GetCompletionHelper(Document document)
}
}
protected
virtual
ExportProvider
ExportProvider
=>
null
;
private
Task
VerifyAsync
(
string
markup
,
string
expectedItemOrNull
,
string
expectedDescriptionOrNull
,
SourceCodeKind
sourceCodeKind
,
bool
usePreviousCharAsTrigger
,
bool
checkForAbsence
,
int
?
glyph
,
int
?
matchPriority
,
bool
?
hasSuggestionModeItem
,
string
displayTextSuffix
,
string
inlineDescription
)
{
var
workspace
=
WorkspaceFixture
.
GetWorkspace
(
markup
);
var
workspace
=
WorkspaceFixture
.
GetWorkspace
(
markup
,
ExportProvider
);
var
code
=
WorkspaceFixture
.
Code
;
var
position
=
WorkspaceFixture
.
Position
;
SetWorkspaceOptions
(
workspace
);
...
...
src/EditorFeatures/TestUtilities/Workspaces/CSharpTestWorkspaceFixture.cs
浏览文件 @
42fe72da
...
...
@@ -2,16 +2,18 @@
using
System.Threading.Tasks
;
using
Microsoft.CodeAnalysis.CSharp
;
using
Microsoft.VisualStudio.Composition
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
{
public
class
CSharpTestWorkspaceFixture
:
TestWorkspaceFixture
{
protected
override
TestWorkspace
CreateWorkspace
()
protected
override
TestWorkspace
CreateWorkspace
(
ExportProvider
exportProvider
=
null
)
{
return
TestWorkspace
.
CreateCSharp2
(
new
string
[]
{
string
.
Empty
,
},
new
CSharpParseOptions
[]
{
new
CSharpParseOptions
(
kind
:
SourceCodeKind
.
Regular
),
});
new
CSharpParseOptions
[]
{
new
CSharpParseOptions
(
kind
:
SourceCodeKind
.
Regular
),
},
exportProvider
:
exportProvider
);
}
}
}
src/EditorFeatures/TestUtilities/Workspaces/TestWorkspaceFixture.cs
浏览文件 @
42fe72da
...
...
@@ -5,6 +5,7 @@
using
System.Linq
;
using
System.Xml
;
using
System.Xml.Linq
;
using
Microsoft.VisualStudio.Composition
;
using
Microsoft.VisualStudio.Text
;
using
Roslyn.Test.Utilities
;
...
...
@@ -20,17 +21,17 @@ public abstract class TestWorkspaceFixture : IDisposable
public
TestHostDocument
CurrentDocument
=>
_currentDocument
??
_workspace
.
Documents
.
Single
();
public
TestWorkspace
GetWorkspace
()
public
TestWorkspace
GetWorkspace
(
ExportProvider
exportProvider
=
null
)
{
_workspace
=
_workspace
??
CreateWorkspace
();
_workspace
=
_workspace
??
CreateWorkspace
(
exportProvider
);
return
_workspace
;
}
public
TestWorkspace
GetWorkspace
(
string
markup
)
public
TestWorkspace
GetWorkspace
(
string
markup
,
ExportProvider
exportProvider
=
null
)
{
if
(
TryParseXElement
(
markup
,
out
var
workspaceElement
)
&&
workspaceElement
.
Name
==
"Workspace"
)
{
_workspace
=
TestWorkspace
.
CreateWorkspace
(
workspaceElement
);
_workspace
=
TestWorkspace
.
CreateWorkspace
(
workspaceElement
,
exportProvider
:
exportProvider
);
_currentDocument
=
_workspace
.
Documents
.
First
(
d
=>
d
.
CursorPosition
.
HasValue
);
Position
=
_currentDocument
.
CursorPosition
.
Value
;
Code
=
_currentDocument
.
TextBuffer
.
CurrentSnapshot
.
GetText
();
...
...
@@ -39,7 +40,7 @@ public TestWorkspace GetWorkspace(string markup)
else
{
MarkupTestFile
.
GetPosition
(
markup
.
NormalizeLineEndings
(),
out
Code
,
out
Position
);
var
workspace
=
GetWorkspace
();
var
workspace
=
GetWorkspace
(
exportProvider
);
_currentDocument
=
workspace
.
Documents
.
Single
();
return
workspace
;
}
...
...
@@ -49,7 +50,7 @@ public TestWorkspaceFixture()
{
}
protected
abstract
TestWorkspace
CreateWorkspace
();
protected
abstract
TestWorkspace
CreateWorkspace
(
ExportProvider
exportProvider
);
public
void
Dispose
()
{
...
...
src/EditorFeatures/TestUtilities/Workspaces/VisualBasicTestWorkspaceFixture.cs
浏览文件 @
42fe72da
...
...
@@ -6,17 +6,19 @@
using
Microsoft.CodeAnalysis
;
using
Microsoft.CodeAnalysis.Text
;
using
Microsoft.CodeAnalysis.VisualBasic
;
using
Microsoft.VisualStudio.Composition
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces
{
public
class
VisualBasicTestWorkspaceFixture
:
TestWorkspaceFixture
{
protected
override
TestWorkspace
CreateWorkspace
()
protected
override
TestWorkspace
CreateWorkspace
(
ExportProvider
exportProvider
=
null
)
{
return
TestWorkspace
.
CreateVisualBasic
(
new
string
[]
{
string
.
Empty
},
new
VisualBasicParseOptions
[]
{
new
VisualBasicParseOptions
(
kind
:
SourceCodeKind
.
Regular
)
},
new
VisualBasicCompilationOptions
(
OutputKind
.
DynamicallyLinkedLibrary
));
new
VisualBasicCompilationOptions
(
OutputKind
.
DynamicallyLinkedLibrary
),
exportProvider
:
exportProvider
);
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录