diff --git a/docs/append-file.md b/docs/append-file.md index e971474960..aff78f496d 100644 --- a/docs/append-file.md +++ b/docs/append-file.md @@ -32,7 +32,7 @@ public Task BinaryFluent() => [Fact] public Task TextFluent() => Verify("Foo") - .AppendFile("extra content"); + .AppendContentAsFile("extra content"); ``` snippet source | anchor diff --git a/src/Verify.Tests/Converters/InstanceFileAppenderTests.cs b/src/Verify.Tests/Converters/InstanceFileAppenderTests.cs index 83451f144f..17ad3eb136 100644 --- a/src/Verify.Tests/Converters/InstanceFileAppenderTests.cs +++ b/src/Verify.Tests/Converters/InstanceFileAppenderTests.cs @@ -6,7 +6,7 @@ public class InstanceFileAppenderTests public InstanceFileAppenderTests() { settings = new(); - settings.AppendFile("appendedFile"); + settings.AppendContentAsFile("appendedFile"); } [Fact] @@ -16,7 +16,7 @@ public Task Text() => [Fact] public Task WithName() => Verify("Foo", settings) - .AppendFile("extra content", name: "theName"); + .AppendContentAsFile("extra content", name: "theName"); #region BinaryFluent @@ -32,14 +32,14 @@ public Task BinaryFluent() => [Fact] public Task TextFluent() => Verify("Foo") - .AppendFile("extra content"); + .AppendContentAsFile("extra content"); #endregion [Fact] public Task WithScrubbing() => Verify("Foo") - .AppendFile(""" + .AppendContentAsFile(""" line1 line2 line3 @@ -49,7 +49,7 @@ public Task WithScrubbing() => [Fact] public Task TextBytesFluent() => Verify("Foo") - .AppendFile(Encoding.UTF8.GetBytes("appendedFile")); + .AppendContentAsFile(Encoding.UTF8.GetBytes("appendedFile")); [Fact] public Task TextStreamFluent() => diff --git a/src/Verify/Splitters/Settings_FileAppender.cs b/src/Verify/Splitters/Settings_FileAppender.cs index 08a8600d07..024f779de6 100644 --- a/src/Verify/Splitters/Settings_FileAppender.cs +++ b/src/Verify/Splitters/Settings_FileAppender.cs @@ -32,13 +32,13 @@ public partial class VerifySettings { internal List appendedFiles = new(); - public void AppendFile(string content, string extension = "txt", string? name = null) => + public void AppendContentAsFile(string content, string extension = "txt", string? name = null) => appendedFiles.Add(new(extension, content, name)); - public void AppendFile(StringBuilder content, string extension = "txt", string? name = null) => + public void AppendContentAsFile(StringBuilder content, string extension = "txt", string? name = null) => appendedFiles.Add(new(extension, content, name)); - public void AppendFile(byte[] content, string extension = "txt", string? name = null) + public void AppendContentAsFile(byte[] content, string extension = "txt", string? name = null) { if (FileExtensions.IsText(extension)) { @@ -50,6 +50,12 @@ public void AppendFile(byte[] content, string extension = "txt", string? name = } } + public void AppendFile(string file, string? name = null) => + AppendFile(IoHelpers.OpenRead(file), name); + + public void AppendFile(FileInfo file, string? name = null) => + AppendFile(file.FullName, name); + public void AppendFile(FileStream stream, string? name = null) => AppendFile(stream, stream.Extension(), name??Path.GetFileNameWithoutExtension(stream.Name)); @@ -70,21 +76,21 @@ public void AppendFile(Stream stream, string extension = "txt", string? name = n public partial class SettingsTask { - public SettingsTask AppendFile(StringBuilder content, string extension = "txt", string? name = null) + public SettingsTask AppendContentAsFile(StringBuilder content, string extension = "txt", string? name = null) { - CurrentSettings.AppendFile(content, extension, name); + CurrentSettings.AppendContentAsFile(content, extension, name); return this; } - public SettingsTask AppendFile(string content, string extension = "txt", string? name = null) + public SettingsTask AppendContentAsFile(string content, string extension = "txt", string? name = null) { - CurrentSettings.AppendFile(content, extension, name); + CurrentSettings.AppendContentAsFile(content, extension, name); return this; } - public SettingsTask AppendFile(byte[] content, string extension = "txt", string? name = null) + public SettingsTask AppendContentAsFile(byte[] content, string extension = "txt", string? name = null) { - CurrentSettings.AppendFile(content, extension, name); + CurrentSettings.AppendContentAsFile(content, extension, name); return this; } @@ -99,4 +105,16 @@ public SettingsTask AppendFile(Stream stream, string extension = "txt", string? CurrentSettings.AppendFile(stream, extension, name); return this; } + + public SettingsTask AppendFile(string file, string? name = null) + { + CurrentSettings.AppendFile(file, name); + return this; + } + + public SettingsTask AppendFile(FileInfo file, string? name = null) + { + CurrentSettings.AppendFile(file, name); + return this; + } } \ No newline at end of file