-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into merges/main-to-feat…
…ures/required-members * upstream/main: (85 commits) Skip timing test (#61222) Prepare VB iterators for EnC support (#61488) Improve normalization to match idiomatic patterns for nested usings and fixed statements. (#61533) Update unit tests Don't throw in logging when the document path contains curly braces (#61524) Fix AbstractLanguageService constructor (#61513) Remove Utf8StringLiteral conversion (#61481) Use feature attribute Pull token out Make async Make async NRT Add member add docs Expose VirtualChars to asp.net (through EA) to facilitate route classification Fix setup authoring bug (#61508) Update src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCommitter.cs Update src/EditorFeatures/Core/RenameTracking/RenameTrackingTaggerProvider.RenameTrackingCommitter.cs Update src/EditorFeatures/Core/InlineRename/InlineRenameSession.cs Add support for properties ...
- Loading branch information
Showing
310 changed files
with
3,766 additions
and
10,993 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# The `TestAccessor` Pattern | ||
|
||
The `TestAccessor` pattern allows production code to expose internal functionality for test purposes without making the internal functionality available to other production code. The pattern has two primary components: | ||
|
||
1. A `TestAccessor` type, which contains the functionality available only for testing | ||
2. A `GetTestAccessor()` method, which returns an instance of `TestAccessor` | ||
|
||
The pattern relies on enforcement of a simple rule that no production code is allowed to call a `GetTestAccessor()` method. This is enforceable either through code reviews or through an analyzer. This pattern has many advantages over alternatives: | ||
|
||
* The pattern does not require expanded accessibility (e.g. `internal` instead of `private`) for the purpose of testing | ||
* The pattern is self-documenting: all properties and methods within a `TestAccessor` type are intended only for use in test code | ||
* The pattern is consistent enough to enforce through static analysis (analyzers) | ||
* The pattern is simple enough to enforce manually (code reviews) | ||
|
||
## The `TestAccessor` Type | ||
|
||
The `TestAccessor` type is typically defined as a nested structure. In the following example, the `SomeProductionType.TestAccessor.PrivateStateData` property allows test code to read and write the value of the private field `SomeProductionType._privateStateData` without exposing the `_privateStateData` field to other production code. | ||
|
||
```csharp | ||
internal class SomeProductionType | ||
{ | ||
private int _privateStateData; | ||
|
||
internal readonly struct TestAccessor | ||
{ | ||
private readonly SomeProductionType _instance; | ||
|
||
internal TestAccessor(SomeProductionType instance) | ||
{ | ||
_instance = instance; | ||
} | ||
|
||
internal ref int PrivateStateData => ref _instance._privateStateData; | ||
} | ||
} | ||
``` | ||
|
||
## The `GetTestAccessor()` Method | ||
|
||
The `GetTestAccessor()` method is always defined as follows: | ||
|
||
```csharp | ||
internal TestAccessor GetTestAccessor() | ||
=> new TestAccessor(this); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.