forked from VerifyTests/Verify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSnippets.cs
More file actions
154 lines (122 loc) · 3.53 KB
/
Copy pathSnippets.cs
File metadata and controls
154 lines (122 loc) · 3.53 KB
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
using DiffEngine;
// ReSharper disable UnusedParameter.Local
public class Snippets
{
#region OnHandlers
public Task OnHandlersSample()
{
VerifierSettings.OnVerify(
before: () => { Debug.WriteLine("before"); },
after: () => { Debug.WriteLine("after"); });
VerifierSettings.OnFirstVerify(
receivedFile =>
{
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; set; } = null!;
}
void DerivePathInfo()
{
#region DerivePathInfo
VerifierSettings.DerivePathInfo(
(sourceFile, projectDirectory, type, method) =>
{
return 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")!;
VerifierSettings.DerivePathInfo(
(sourceFile, projectDirectory, type, method) =>
{
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.WriteProperty(company, company.Name, "Name");
}
}
#endregion
class Company
{
public string Name { get; set; } = null!;
}
}