forked from VerifyTests/Verify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSnippets.cs
165 lines (130 loc) · 3.68 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
// ReSharper disable UnusedParameter.Local
public class Snippets
{
void EnableClipboard()
{
#region EnableClipboard
ClipboardAccept.Enable();
#endregion
}
#region OnHandlers
public Task OnHandlersSample()
{
VerifierSettings.OnVerify(
before: () =>
{
Debug.WriteLine("before");
},
after: () =>
{
Debug.WriteLine("after");
});
VerifierSettings.OnFirstVerify(
(receivedFile, receivedText) =>
{
Debug.WriteLine(receivedFile);
return Task.CompletedTask;
});
VerifierSettings.OnVerifyMismatch(
(filePair, message) =>
{
Debug.WriteLine(filePair.ReceivedPath);
Debug.WriteLine(filePair.VerifiedPath);
Debug.WriteLine(message);
return Task.CompletedTask;
});
return Verify("value");
}
#endregion
void TreatAsString()
{
#region TreatAsString
VerifierSettings.TreatAsString<ClassWithToString>(
(target, settings) => target.Property);
#endregion
}
class ClassWithToString
{
public string Property { get; } = null!;
}
void DerivePathInfo()
{
#region DerivePathInfo
Verifier.DerivePathInfo(
(sourceFile, projectDirectory, type, method) => new(
directory: Path.Combine(projectDirectory, "Snapshots"),
typeName: type.Name,
methodName: method.Name));
#endregion
}
void DerivePathInfoAppVeyor()
{
#region DerivePathInfoAppVeyor
if (BuildServerDetector.Detected)
{
var buildDirectory = Environment.GetEnvironmentVariable("APPVEYOR_BUILD_FOLDER")!;
Verifier.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 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
class Company
{
public string Name { get; } = null!;
}
}