-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
SnapshotUpdateStrategy.cs
69 lines (56 loc) · 2.62 KB
/
SnapshotUpdateStrategy.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
using Meziantou.Framework.InlineSnapshotTesting.SnapshotUpdateStrategies;
namespace Meziantou.Framework.InlineSnapshotTesting;
public abstract class SnapshotUpdateStrategy
{
/// <summary>
/// Do not update the snapshots and fail the tests if the snapshots are different.
/// </summary>
public static SnapshotUpdateStrategy Disallow { get; } = new DisallowStrategy();
/// <summary>
/// Open a merge tool to update the snapshots. You can specify the merge tools to use using <see cref="InlineSnapshotSettings.MergeTools" />.
/// The test fails if the snapshots are different.
/// </summary>
public static SnapshotUpdateStrategy MergeTool { get; } = new MergeToolStrategy();
/// <summary>
/// Open a merge tool to update the snapshots and wait for it to close before continuing the test execution. You can specify the merge tools to use using <see cref="InlineSnapshotSettings.MergeTools" />.
/// The test fails if the snapshots are different.
/// </summary>
public static SnapshotUpdateStrategy MergeToolSync { get; } = new BlockingDiffToolStrategy();
/// <summary>
/// Overwrite the source file with the new snapshot. The test fails if the snapshots are different.
/// </summary>
public static SnapshotUpdateStrategy Overwrite { get; } = new AlwaysStrategy();
/// <summary>
/// Overwrite the source file with the new snapshot. The test won't fail.
/// </summary>
public static SnapshotUpdateStrategy OverwriteWithoutFailure { get; } = new AlwaysWithoutFailureStrategy();
public static SnapshotUpdateStrategy Default
{
get
{
if (TaskDialogPrompt.IsSupported())
return new PromptStrategy(new TaskDialogPrompt());
return MergeTool;
}
}
/// <summary>
/// Indicates if an an inline snapshot must be updated
/// </summary>
public abstract bool CanUpdateSnapshot(InlineSnapshotSettings settings, string path, string expectedSnapshot, string actualSnapshot);
public abstract void UpdateFile(InlineSnapshotSettings settings, string targetFile, string tempFile);
/// <summary>
/// Indicates if an exception must be thrown when the snapshots differ.
/// </summary>
public abstract bool MustReportError(InlineSnapshotSettings settings, string path);
private protected static void MoveFile(string source, string destination)
{
if (source == destination)
return;
#if NETCOREAPP3_0_OR_GREATER
File.Move(source, destination, overwrite: true);
#else
File.Copy(source, destination, overwrite: true);
File.Delete(source);
#endif
}
}