-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
96 additions
and
19 deletions.
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
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
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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli.Tests/Commands/Github/Migrate/MigrateArgsTests.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli.Tests/Commands/Github/Migrate/MigrateRunnerTests.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
77 changes: 77 additions & 0 deletions
77
GithubBackup/GithubBackup.Cli.Tests/Commands/Interval/IntervalArgsTests.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,77 @@ | ||
using System.CommandLine; | ||
using System.CommandLine.Parsing; | ||
using FluentAssertions; | ||
using GithubBackup.Cli.Commands.Global; | ||
using GithubBackup.Cli.Commands.Interval; | ||
using GithubBackup.Cli.Tests.Utils; | ||
using GithubBackup.Cli.Utils; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace GithubBackup.Cli.Tests.Commands.Interval; | ||
|
||
public class IntervalArgsTests | ||
{ | ||
private readonly IntervalArguments _intervalArguments = new(); | ||
|
||
[Fact] | ||
public async Task InvokeAsync_FlagsArePassed_FlagsGetParsed() | ||
{ | ||
var rootCommand = new RootCommand(); | ||
rootCommand.AddGlobalOptions(_intervalArguments.Options()); | ||
var subCommand = new Command("sub"); | ||
|
||
subCommand.SetHandler( | ||
intervalArgs => | ||
{ | ||
intervalArgs.Should().NotBeNull(); | ||
intervalArgs.Interval.Should().Be(TimeSpan.FromSeconds(10)); | ||
}, | ||
new IntervalArgsBinder(_intervalArguments) | ||
); | ||
|
||
rootCommand.AddCommand(subCommand); | ||
await TestCommandline.Build(rootCommand).InvokeAsync("sub --interval 10"); | ||
} | ||
|
||
[Fact] | ||
public async Task InvokeAsync_ShortFlagsArePassed_FlagsGetParsed() | ||
{ | ||
var rootCommand = new RootCommand(); | ||
rootCommand.AddGlobalOptions(_intervalArguments.Options()); | ||
var subCommand = new Command("sub"); | ||
|
||
subCommand.SetHandler( | ||
intervalArgs => | ||
{ | ||
intervalArgs.Should().NotBeNull(); | ||
intervalArgs.Interval.Should().Be(TimeSpan.FromSeconds(10)); | ||
}, | ||
new IntervalArgsBinder(_intervalArguments) | ||
); | ||
|
||
rootCommand.AddCommand(subCommand); | ||
await TestCommandline.Build(rootCommand).InvokeAsync("sub -i 10"); | ||
} | ||
|
||
[Fact] | ||
public async Task InvokeAsync_NoFlagsArePassed_DefaultsAreUsed() | ||
{ | ||
var rootCommand = new RootCommand(); | ||
rootCommand.AddGlobalOptions(_intervalArguments.Options()); | ||
var subCommand = new Command("sub"); | ||
|
||
subCommand.SetHandler( | ||
intervalArgs => | ||
{ | ||
intervalArgs.Should().NotBeNull(); | ||
intervalArgs.Interval.Should().BeNull(); | ||
}, | ||
new IntervalArgsBinder(_intervalArguments) | ||
); | ||
|
||
rootCommand.AddCommand(subCommand); | ||
await TestCommandline.Build(rootCommand).InvokeAsync("sub"); | ||
} | ||
} | ||
|
||
|
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Backup/BackupArgs.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Backup/BackupArgsBinder.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Backup/BackupCommand.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Download/DowndloadArgsBinder.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Download/DownloadArgs.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Download/DownloadCommand.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Migrate/MigrateArgs.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Migrate/MigrateArgsBinder.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Github/Migrate/MigrateCommand.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
2 changes: 1 addition & 1 deletion
2
...ithub/Interval/IntervalArgDescriptions.cs → ...mands/Interval/IntervalArgDescriptions.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
2 changes: 1 addition & 1 deletion
2
.../Commands/Github/Interval/IntervalArgs.cs → ...kup.Cli/Commands/Interval/IntervalArgs.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
2 changes: 1 addition & 1 deletion
2
...nds/Github/Interval/IntervalArgsBinder.cs → ...i/Commands/Interval/IntervalArgsBinder.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
2 changes: 1 addition & 1 deletion
2
...ands/Github/Interval/IntervalArguments.cs → ...li/Commands/Interval/IntervalArguments.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
2 changes: 1 addition & 1 deletion
2
GithubBackup/GithubBackup.Cli/Commands/Services/ICommandIntervalArgs.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