diff --git a/src/Verify.XunitV3.Tests/AttachmentTests.cs b/src/Verify.XunitV3.Tests/AttachmentTests.cs index 41a658fe1..60e245760 100644 --- a/src/Verify.XunitV3.Tests/AttachmentTests.cs +++ b/src/Verify.XunitV3.Tests/AttachmentTests.cs @@ -1,6 +1,6 @@ public class AttachmentTests { -#if NET10_0 +#if NET11_0 [Fact] public async Task Simple() { @@ -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] @@ -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 } \ No newline at end of file diff --git a/src/Verify.XunitV3/Verifier.cs b/src/Verify.XunitV3/Verifier.cs index 12b493c76..3e87dbaad 100644 --- a/src/Verify.XunitV3/Verifier.cs +++ b/src/Verify.XunitV3/Verifier.cs @@ -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() =>