Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Verify.XunitV3.Tests/AttachmentTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
public class AttachmentTests
{
#if NET10_0
#if NET11_0
[Fact]
public async Task Simple()
{
Expand All @@ -10,10 +10,10 @@ public async Task Simple()
File.Delete(fullPath);
await Verify("Foo").AutoVerify();
File.Delete(fullPath);
var attachments = TestContext.Current.Attachments!;
Assert.Contains(attachments.Keys,
_ => _.Contains("Verify snapshot mismatch") &&
_.Contains("AttachmentTests.Simple."));
var key = Assert.Single(TestContext.Current.Attachments!).Key;
Assert.StartsWith("Verify.XunitV3.Tests/AttachmentTests.Simple.", key);
Assert.EndsWith(".received.txt", key);
Assert.DoesNotContain(':', key);
}

[Fact]
Expand All @@ -37,10 +37,10 @@ void Delete()
}
}

var attachments = TestContext.Current.Attachments!;
Assert.Contains(attachments.Keys,
_ => _.Contains("Verify snapshot mismatch") &&
_.Contains("AttachmentTests.Simple."));
var key = Assert.Single(TestContext.Current.Attachments!).Key;
Assert.StartsWith("Verify.XunitV3.Tests/AttachmentTests/AttachmentTests.Simple.", key);
Assert.EndsWith(".received.txt", key);
Assert.DoesNotContain(':', key);
}
#endif
}
18 changes: 17 additions & 1 deletion src/Verify.XunitV3/Verifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@ public static partial class Verifier
{
static async Task AddFile(string path) =>
TestContext.Current.AddAttachment(
$"Verify snapshot mismatch: {path}",
GetAttachmentName(path),
await File.ReadAllBytesAsync(path));

internal static string GetAttachmentName(string path)
{
var fullPath = Path.GetFullPath(path).Replace('\\', '/');
var solutionDir = VerifierSettings.SolutionDir;
if (solutionDir is not null)
{
var fullSolutionDir = Path.GetFullPath(solutionDir).Replace('\\', '/').TrimEnd('/') + '/';
if (fullPath.StartsWith(fullSolutionDir, StringComparison.OrdinalIgnoreCase))
{
return fullPath[fullSolutionDir.Length..];
}
}

return fullPath;
}

[ModuleInitializer]
[EditorBrowsable(EditorBrowsableState.Never)]
public static void AddAttachmentEvents() =>
Expand Down
Loading