-
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Snippets.cs
177 lines (131 loc) · 4.16 KB
/
Snippets.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
// ReSharper disable UnusedParameter.Local
// ReSharper disable UnusedMember.Local
public class Snippets
{
async Task ChangeDefaultsPerVerification(object target)
{
#region ChangeDefaultsPerVerification
var settings = new VerifySettings();
settings.DontIgnoreEmptyCollections();
settings.DontScrubGuids();
settings.DontScrubDateTimes();
await Verify(target, settings);
#endregion
#region ChangeDefaultsPerVerification
await Verify(target)
.DontIgnoreEmptyCollections()
.DontScrubGuids()
.DontScrubDateTimes();
#endregion
}
void EnableClipboard() =>
#region EnableClipboard
ClipboardAccept.Enable();
#endregion
void TreatAsString() =>
#region TreatAsString
VerifierSettings.TreatAsString<ClassWithToString>(
(target, settings) => target.Property);
#endregion
record ClassWithToString(string Property);
void DerivePathInfoAppVeyor()
{
// ReSharper disable once ArrangeStaticMemberQualifier
#region DerivePathInfoAppVeyor
if (BuildServerDetector.Detected)
{
var buildDirectory = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_FOLDER")!;
DerivePathInfo(
(sourceFile, projectDirectory, typeName, methodName) =>
{
var testDirectory = Path.GetDirectoryName(sourceFile)!;
var testDirectorySuffix = testDirectory.Replace(projectDirectory, string.Empty);
return new(directory: Path.Combine(buildDirectory, testDirectorySuffix));
});
}
#endregion
}
void AutoVerify()
{
#region AutoVerify
var settings = new VerifySettings();
settings.AutoVerify();
#endregion
}
void AutoVerifyDelegate()
{
#region AutoVerifyDelegate
var settings = new VerifySettings();
settings.AutoVerify(
verifiedFile =>
Path.GetExtension(verifiedFile) == "png");
#endregion
}
#region AutoVerifyFluent
[Fact]
public Task AutoVerifyFluent() =>
Verify("Value")
.AutoVerify();
#endregion
#region AutoVerifyFluentDelegate
[Fact]
public Task AutoVerifyFluentDelegate() =>
Verify("Value")
.AutoVerify(
verifiedFile =>
Path.GetExtension(verifiedFile) == "png");
#endregion
void DisableDiff()
{
#region DisableDiff
var settings = new VerifySettings();
settings.DisableDiff();
#endregion
}
void ApplyExtraSettingsSample()
{
#region ExtraSettingsGlobal
VerifierSettings.AddExtraSettings(
_ => _.TypeNameHandling = TypeNameHandling.All);
#endregion
#region ExtraSettingsInstance
var settings = new VerifySettings();
settings.AddExtraSettings(
_ => _.TypeNameHandling = TypeNameHandling.All);
#endregion
}
void Converter() =>
#region JsonConverter
VerifierSettings.AddExtraSettings(
_ => _.Converters.Add(new CompanyConverter()));
#endregion
#region CompanyConverter
class CompanyConverter :
WriteOnlyJsonConverter<Company>
{
public override void Write(VerifyJsonWriter writer, Company company) =>
writer.WriteMember(company, company.Name, "Name");
}
#endregion
record Company(string Name);
async Task VerifyFuncOfTaskOfT()
{
var repo = new Repo();
var id = 1;
#region VerifyFuncOfTaskOfT
await Verify(
async () => new
{
Foo = await repo.GetFoo(id),
Bars = await repo.GetBars(id)
});
#endregion
}
class Repo
{
// ReSharper disable once MemberCanBeMadeStatic.Local
public Task<object> GetFoo(int id) => throw new NotImplementedException();
// ReSharper disable once MemberCanBeMadeStatic.Local
public Task<object> GetBars(int id) => throw new NotImplementedException();
}
}