Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
2960d57f
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,发现更多精彩内容 >>
提交
2960d57f
编写于
9月 24, 2020
作者:
S
Sam Harwell
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract helper class TestFixtureHelper<TFixture>
上级
5d594694
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
62 addition
and
52 deletion
+62
-52
src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs
...stUtilities/Completion/AbstractCompletionProviderTests.cs
+2
-13
src/EditorFeatures/TestUtilities/RefactoringHelpers/RefactoringHelpersTestBase.cs
...tilities/RefactoringHelpers/RefactoringHelpersTestBase.cs
+2
-13
src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs
...ities/SignatureHelp/AbstractSignatureHelpProviderTests.cs
+2
-13
src/EditorFeatures/TestUtilities/TypeInferrer/TypeInferrerTestBase.cs
...atures/TestUtilities/TypeInferrer/TypeInferrerTestBase.cs
+2
-13
src/EditorFeatures/TestUtilities/Utilities/TestFixtureHelper`1.cs
...orFeatures/TestUtilities/Utilities/TestFixtureHelper`1.cs
+54
-0
未找到文件。
src/EditorFeatures/TestUtilities/Completion/AbstractCompletionProviderTests.cs
浏览文件 @
2960d57f
...
...
@@ -38,8 +38,7 @@ public abstract class AbstractCompletionProviderTests<TWorkspaceFixture> : TestB
{
private
static
readonly
TestComposition
s_baseComposition
=
EditorTestCompositions
.
EditorFeatures
.
AddExcludedPartTypes
(
typeof
(
CompletionProvider
));
private
readonly
object
_workspaceFixtureGate
=
new
();
private
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
_weakWorkspaceFixture
;
private
readonly
TestFixtureHelper
<
TWorkspaceFixture
>
_fixtureHelper
=
new
();
protected
readonly
Mock
<
ICompletionSession
>
MockCompletionSession
;
private
ExportProvider
_lazyExportProvider
;
...
...
@@ -56,17 +55,7 @@ protected virtual TestComposition GetComposition()
=>
s_baseComposition
.
AddParts
(
GetCompletionProviderType
());
private
protected
ReferenceCountedDisposable
<
TWorkspaceFixture
>
GetOrCreateWorkspaceFixture
()
{
lock
(
_workspaceFixtureGate
)
{
if
(
_weakWorkspaceFixture
.
TryAddReference
()
is
{
}
workspaceFixture
)
return
workspaceFixture
;
var
result
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>(
new
TWorkspaceFixture
());
_weakWorkspaceFixture
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
(
result
);
return
result
;
}
}
=>
_fixtureHelper
.
GetOrCreateFixture
();
protected
static
async
Task
<
bool
>
CanUseSpeculativeSemanticModelAsync
(
Document
document
,
int
position
)
{
...
...
src/EditorFeatures/TestUtilities/RefactoringHelpers/RefactoringHelpersTestBase.cs
浏览文件 @
2960d57f
...
...
@@ -22,21 +22,10 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.RefactoringHelpers
public
abstract
class
RefactoringHelpersTestBase
<
TWorkspaceFixture
>
:
TestBase
where
TWorkspaceFixture
:
TestWorkspaceFixture
,
new
()
{
private
readonly
object
_workspaceFixtureGate
=
new
();
private
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
_weakWorkspaceFixture
;
private
readonly
TestFixtureHelper
<
TWorkspaceFixture
>
_fixtureHelper
=
new
();
private
protected
ReferenceCountedDisposable
<
TWorkspaceFixture
>
GetOrCreateWorkspaceFixture
()
{
lock
(
_workspaceFixtureGate
)
{
if
(
_weakWorkspaceFixture
.
TryAddReference
()
is
{
}
workspaceFixture
)
return
workspaceFixture
;
var
result
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>(
new
TWorkspaceFixture
());
_weakWorkspaceFixture
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
(
result
);
return
result
;
}
}
=>
_fixtureHelper
.
GetOrCreateFixture
();
protected
Task
TestAsync
<
TNode
>(
string
text
)
where
TNode
:
SyntaxNode
=>
TestAsync
<
TNode
>(
text
,
Functions
<
TNode
>.
True
);
...
...
src/EditorFeatures/TestUtilities/SignatureHelp/AbstractSignatureHelpProviderTests.cs
浏览文件 @
2960d57f
...
...
@@ -28,23 +28,12 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.SignatureHelp
public
abstract
class
AbstractSignatureHelpProviderTests
<
TWorkspaceFixture
>
:
TestBase
where
TWorkspaceFixture
:
TestWorkspaceFixture
,
new
()
{
private
readonly
object
_workspaceFixtureGate
=
new
();
private
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
_weakWorkspaceFixture
;
private
readonly
TestFixtureHelper
<
TWorkspaceFixture
>
_fixtureHelper
=
new
();
internal
abstract
Type
GetSignatureHelpProviderType
();
private
protected
ReferenceCountedDisposable
<
TWorkspaceFixture
>
GetOrCreateWorkspaceFixture
()
{
lock
(
_workspaceFixtureGate
)
{
if
(
_weakWorkspaceFixture
.
TryAddReference
()
is
{
}
workspaceFixture
)
return
workspaceFixture
;
var
result
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>(
new
TWorkspaceFixture
());
_weakWorkspaceFixture
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
(
result
);
return
result
;
}
}
=>
_fixtureHelper
.
GetOrCreateFixture
();
/// <summary>
/// Verifies that sighelp comes up at the indicated location in markup ($$), with the indicated span [| ... |].
...
...
src/EditorFeatures/TestUtilities/TypeInferrer/TypeInferrerTestBase.cs
浏览文件 @
2960d57f
...
...
@@ -17,21 +17,10 @@ namespace Microsoft.CodeAnalysis.Editor.UnitTests.TypeInferrer
public
abstract
class
TypeInferrerTestBase
<
TWorkspaceFixture
>
:
TestBase
where
TWorkspaceFixture
:
TestWorkspaceFixture
,
new
()
{
private
readonly
object
_workspaceFixtureGate
=
new
();
private
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
_weakWorkspaceFixture
;
private
readonly
TestFixtureHelper
<
TWorkspaceFixture
>
_fixtureHelper
=
new
();
private
protected
ReferenceCountedDisposable
<
TWorkspaceFixture
>
GetOrCreateWorkspaceFixture
()
{
lock
(
_workspaceFixtureGate
)
{
if
(
_weakWorkspaceFixture
.
TryAddReference
()
is
{
}
workspaceFixture
)
return
workspaceFixture
;
var
result
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>(
new
TWorkspaceFixture
());
_weakWorkspaceFixture
=
new
ReferenceCountedDisposable
<
TWorkspaceFixture
>.
WeakReference
(
result
);
return
result
;
}
}
=>
_fixtureHelper
.
GetOrCreateFixture
();
private
static
async
Task
<
bool
>
CanUseSpeculativeSemanticModelAsync
(
Document
document
,
int
position
)
{
...
...
src/EditorFeatures/TestUtilities/Utilities/TestFixtureHelper`1.cs
0 → 100644
浏览文件 @
2960d57f
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using
System
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.Editor.UnitTests
{
internal
sealed
class
TestFixtureHelper
<
TFixture
>
where
TFixture
:
class
,
IDisposable
,
new
()
{
private
readonly
object
_gate
=
new
();
/// <summary>
/// Holds a weak reference to the current test fixture instance. This reference allows
/// <see cref="GetOrCreateFixture"/> to access and add a reference to the current test fixture if one exists,
/// but does not prevent the fixture from being disposed after the last reference to it is released.
/// </summary>
private
ReferenceCountedDisposable
<
TFixture
>.
WeakReference
_weakFixture
;
/// <summary>
/// Gets a reference to a test fixture, or creates it if one does not already exist.
/// </summary>
/// <remarks>
/// <para>The resulting test fixture will not be disposed until the last referencer disposes of its reference.
/// It is possible for more than one test fixture to be created during the life of any single test, but only one
/// test fixture will be live at any given point.</para>
///
/// <para>The following shows how a block of test code can ensure a single test fixture is created and used
/// within any given block of code:</para>
///
/// <code>
/// using (var fixture = GetOrCreateFixture())
/// {
/// // The test fixture 'fixture' is guaranteed to not be released or replaced within this block
/// }
/// </code>
/// </remarks>
/// <returns>The test fixture instance.</returns>
internal
ReferenceCountedDisposable
<
TFixture
>
GetOrCreateFixture
()
{
lock
(
_gate
)
{
if
(
_weakFixture
.
TryAddReference
()
is
{
}
fixture
)
return
fixture
;
var
result
=
new
ReferenceCountedDisposable
<
TFixture
>(
new
TFixture
());
_weakFixture
=
new
ReferenceCountedDisposable
<
TFixture
>.
WeakReference
(
result
);
return
result
;
}
}
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录