Skip to content

Commit

Permalink
AppendFile => AppendContentAsFile
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonCropp committed Dec 19, 2022
1 parent 186ef89 commit 4249089
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/append-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public Task BinaryFluent() =>
[Fact]
public Task TextFluent() =>
Verify("Foo")
.AppendFile("extra content");
.AppendContentAsFile("extra content");
```
<sup><a href='/src/Verify.Tests/Converters/InstanceFileAppenderTests.cs#L30-L37' title='Snippet source file'>snippet source</a> | <a href='#snippet-textfluent' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->
10 changes: 5 additions & 5 deletions src/Verify.Tests/Converters/InstanceFileAppenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public class InstanceFileAppenderTests
public InstanceFileAppenderTests()
{
settings = new();
settings.AppendFile("appendedFile");
settings.AppendContentAsFile("appendedFile");
}

[Fact]
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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() =>
Expand Down
36 changes: 27 additions & 9 deletions src/Verify/Splitters/Settings_FileAppender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public partial class VerifySettings
{
internal List<Target> 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))
{
Expand All @@ -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));

Expand All @@ -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;
}

Expand All @@ -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;
}
}

0 comments on commit 4249089

Please sign in to comment.