Skip to content

Commit

Permalink
add tests for interval args
Browse files Browse the repository at this point in the history
  • Loading branch information
byCrookie committed Oct 28, 2023
1 parent 204c181 commit bf373a8
Show file tree
Hide file tree
Showing 20 changed files with 96 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using GithubBackup.Cli.Commands.Github.Backup;
using GithubBackup.Cli.Commands.Github.Credentials;
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Core.Github.Migrations;
using GithubBackup.Core.Github.Users;
using Microsoft.Extensions.Logging;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.CommandLine.Parsing;
using FluentAssertions;
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Tests.Utils;
using GithubBackup.Cli.Utils;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.IO.Abstractions.TestingHelpers;
using GithubBackup.Cli.Commands.Github.Credentials;
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Core.Github.Migrations;
using GithubBackup.Core.Github.Users;
using GithubBackup.TestUtils.Logging;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.CommandLine;
using System.CommandLine.Parsing;
using FluentAssertions;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Tests.Utils;
using GithubBackup.Cli.Utils;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GithubBackup.Cli.Commands.Github.Credentials;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Login;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Core.Github.Migrations;
using GithubBackup.Core.Github.Users;
using GithubBackup.TestUtils.Logging;
Expand Down
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");
}
}


Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Commands.Services;

namespace GithubBackup.Cli.Commands.Github.Backup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.CommandLine.Binding;
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Interval;

namespace GithubBackup.Cli.Commands.Github.Backup;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System.CommandLine;
using GithubBackup.Cli.Commands.Github.Download;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Github.Migrate;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Utils;

namespace GithubBackup.Cli.Commands.Github.Backup;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.CommandLine.Binding;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Utils;

namespace GithubBackup.Cli.Commands.Github.Download;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Commands.Services;

namespace GithubBackup.Cli.Commands.Github.Download;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.CommandLine;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Utils;

namespace GithubBackup.Cli.Commands.Github.Download;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using FluentValidation;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Commands.Services;

namespace GithubBackup.Cli.Commands.Github.Migrate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using System.CommandLine.Binding;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Utils;

namespace GithubBackup.Cli.Commands.Github.Migrate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.CommandLine;
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Global;
using GithubBackup.Cli.Commands.Interval;
using GithubBackup.Cli.Utils;

namespace GithubBackup.Cli.Commands.Github.Migrate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GithubBackup.Cli.Commands.Github.Interval;
namespace GithubBackup.Cli.Commands.Interval;

internal static class IntervalArgDescriptions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace GithubBackup.Cli.Commands.Github.Interval;
namespace GithubBackup.Cli.Commands.Interval;

internal sealed class IntervalArgs
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.CommandLine.Binding;

namespace GithubBackup.Cli.Commands.Github.Interval;
namespace GithubBackup.Cli.Commands.Interval;

internal sealed class IntervalArgsBinder : BinderBase<IntervalArgs>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.CommandLine;

namespace GithubBackup.Cli.Commands.Github.Interval;
namespace GithubBackup.Cli.Commands.Interval;

public class IntervalArguments
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using GithubBackup.Cli.Commands.Github.Interval;
using GithubBackup.Cli.Commands.Interval;

namespace GithubBackup.Cli.Commands.Services;

Expand Down

0 comments on commit bf373a8

Please sign in to comment.