-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1794 from microsoft/feat/none_output_option
Add none output option
- Loading branch information
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
cli/commons/src/Microsoft.Kiota.Cli.Commons.Tests/IO/NoneOutputFormatterTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Microsoft.Kiota.Cli.Commons.IO; | ||
using Xunit; | ||
|
||
namespace Microsoft.Kiota.Cli.Commons.Tests.IO; | ||
|
||
public class NoneOutputFormatterTest | ||
{ | ||
public class WriteOutputAsyncFunction_Should | ||
{ | ||
[Fact] | ||
public async Task Write_No_Content_With_Short_Stream_Content() | ||
{ | ||
var formatter = new NoneOutputFormatter(); | ||
var content = "Test content"; | ||
using var stream = new MemoryStream(Encoding.ASCII.GetBytes(content)); | ||
var sb = new StringBuilder(); | ||
using var outWriter = new StringWriter(sb); | ||
using var errorWriter = new StringWriter(sb); | ||
Console.SetOut(outWriter); | ||
Console.SetError(errorWriter); | ||
|
||
await formatter.WriteOutputAsync(stream, new OutputFormatterOptions()); | ||
|
||
Assert.Equal(0, sb.Length); | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
cli/commons/src/Microsoft.Kiota.Cli.Commons/IO/NoneOutputFormatter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using System.CommandLine; | ||
using System.Text.Json; | ||
using Spectre.Console; | ||
|
||
namespace Microsoft.Kiota.Cli.Commons.IO; | ||
|
||
/// <summary> | ||
/// A no-op output formatter | ||
/// </summary> | ||
public class NoneOutputFormatter : IOutputFormatter | ||
{ | ||
/// <inheritdoc /> | ||
public Task WriteOutputAsync(Stream content, IOutputFormatterOptions? options = null, CancellationToken cancellationToken = default) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters