Skip to content

Commit

Permalink
Tyrrrz#13 - Fix tests - disable suggest mode by default.
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricel committed Mar 31, 2021
1 parent 3dad8dd commit 5f6c0ad
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CliFx.Tests/SpecsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public abstract class SpecsBase : IDisposable

public FakeInMemoryConsole FakeConsole { get; } = new();

public NullFileSystem NullFileSystem { get; } = new();

protected SpecsBase(ITestOutputHelper testOutput) =>
TestOutput = testOutput;

Expand Down
9 changes: 6 additions & 3 deletions CliFx.Tests/SuggestDirectiveSpecs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public CliApplicationBuilder TestApplicationFactory(params string[] commandClass
builder = builder.AddCommand(commandType);
});

return builder.UseConsole(FakeConsole);
return builder.UseConsole(FakeConsole)
.UseFileSystem(NullFileSystem);
}

[Theory]
Expand All @@ -67,7 +68,7 @@ public async Task Suggest_directive_can_be_configured(bool enabled, int expected
}

[Fact]
public async Task Suggest_directive_is_enabled_by_default()
public async Task Suggest_directive_is_disabled_by_default()
{
// Arrange
var application = TestApplicationFactory(_cmdCommandCs)
Expand All @@ -79,7 +80,7 @@ public async Task Suggest_directive_is_enabled_by_default()
);

// Assert
exitCode.Should().Be(0);
exitCode.Should().Be(1);
}

private string FormatExpectedOutput(string [] s)
Expand All @@ -106,6 +107,7 @@ public async Task Suggest_directive_suggests_commands_by_environment_variables(s
{
// Arrange
var application = TestApplicationFactory(_cmdCommandCs, _cmd2CommandCs)
.AllowSuggestMode()
.Build();

// Act
Expand Down Expand Up @@ -133,6 +135,7 @@ public async Task Suggest_directive_suggests_commands_by_command_line_only(strin
{
// Arrange
var application = TestApplicationFactory(_cmdCommandCs, _cmd2CommandCs)
.AllowSuggestMode()
.Build();

// Act
Expand Down
4 changes: 2 additions & 2 deletions CliFx/CliApplicationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public partial class CliApplicationBuilder

private bool _isDebugModeAllowed = true;
private bool _isPreviewModeAllowed = true;
private bool _isSuggestModeAllowed = true;
private bool _isSuggestModeAllowed = false;
private string? _title;
private string? _executableName;
private string? _versionText;
Expand Down Expand Up @@ -182,7 +182,7 @@ public CliApplicationBuilder UseConsole(IConsole console)
/// <summary>
/// Configures the application to use the specified implementation of <see cref="IFileSystem"/>.
/// </summary>
CliApplicationBuilder UseFileSystem(IFileSystem fileSystem)
public CliApplicationBuilder UseFileSystem(IFileSystem fileSystem)
{
_fileSystem = fileSystem;
return this;
Expand Down
33 changes: 33 additions & 0 deletions CliFx/Infrastructure/FakeFileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CliFx.Infrastructure
{
public class FakeSystem : IFileSystem
{
public Dictionary<string, string> Files => new Dictionary<string, string>();

public void Copy(string sourceFileName, string destFileName)
{
Files[destFileName] = Files[sourceFileName];
}

public bool Exists(string path)
{
return Files.ContainsKey(path);
}

public string ReadAllText(string path)
{
return Files[path];
}

public void WriteAllText(string path, string content)
{
Files[path] = content;
}
}


}
27 changes: 27 additions & 0 deletions CliFx/Infrastructure/NullFileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CliFx.Infrastructure
{
public class NullFileSystem : IFileSystem
{
public void Copy(string sourceFileName, string destFileName)
{
}

public bool Exists(string path)
{
return false;
}

public string ReadAllText(string path)
{
return "";
}

public void WriteAllText(string path, string content)
{
}
}
}

0 comments on commit 5f6c0ad

Please sign in to comment.