-
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
10 changed files
with
211 additions
and
0 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
...oginServiceTests.PersistentOnlyAsync_NotQuietAndNoUser_ReturnNullAndNotPrint.verified.txt
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 @@ | ||
emptyString |
1 change: 1 addition & 0 deletions
1
...uth/LoginServiceTests.PersistentOnlyAsync_NotQuietAndUser_ReturnUserAndPrint.verified.txt
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 @@ | ||
Logged in as test |
1 change: 1 addition & 0 deletions
1
...h/LoginServiceTests.PersistentOnlyAsync_QuietAndUser_ReturnUserAndDoNotPrint.verified.txt
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 @@ | ||
emptyString |
1 change: 1 addition & 0 deletions
1
...oginServiceTests.WithPersistentAsync_NotQuietAndNoUser_ReturnNullAndNotPrint.verified.txt
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 @@ | ||
emptyString |
1 change: 1 addition & 0 deletions
1
...uth/LoginServiceTests.WithPersistentAsync_NotQuietAndUser_ReturnUserAndPrint.verified.txt
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 @@ | ||
Logged in as test |
1 change: 1 addition & 0 deletions
1
...h/LoginServiceTests.WithPersistentAsync_QuietAndUser_ReturnUserAndDoNotPrint.verified.txt
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 @@ | ||
emptyString |
1 change: 1 addition & 0 deletions
1
...nServiceTests.WithoutPersistentAsync_NotQuietAndNoUser_ReturnNullAndNotPrint.verified.txt
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 @@ | ||
emptyString |
1 change: 1 addition & 0 deletions
1
.../LoginServiceTests.WithoutPersistentAsync_NotQuietAndUser_ReturnUserAndPrint.verified.txt
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 @@ | ||
Logged in as test |
1 change: 1 addition & 0 deletions
1
...oginServiceTests.WithoutPersistentAsync_QuietAndUser_ReturnUserAndDoNotPrint.verified.txt
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 @@ | ||
emptyString |
202 changes: 202 additions & 0 deletions
202
GithubBackup/GithubBackup.Cli.Tests/Commands/Github/Auth/LoginServiceTests.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,202 @@ | ||
using FluentAssertions; | ||
using GithubBackup.Cli.Commands.Github.Auth; | ||
using GithubBackup.Cli.Commands.Github.Auth.Pipeline; | ||
using GithubBackup.Cli.Commands.Github.Login; | ||
using GithubBackup.Cli.Commands.Global; | ||
using GithubBackup.Core.Github.Users; | ||
using GithubBackup.TestUtils.Logging; | ||
using Microsoft.Extensions.Logging; | ||
using NSubstitute; | ||
using Spectre.Console.Testing; | ||
|
||
namespace GithubBackup.Cli.Tests.Commands.Github.Auth; | ||
|
||
[UsesVerify] | ||
public class LoginServiceTests | ||
{ | ||
private readonly LoginService _sut; | ||
private readonly ILogger<LoginService> _logger; | ||
private readonly TestConsole _ansiConsole; | ||
private readonly ILoginPipelineBuilder _loginPipelineBuilder; | ||
|
||
public LoginServiceTests() | ||
{ | ||
_logger = Substitute.For<ILogger<LoginService>>(); | ||
_ansiConsole = new TestConsole(); | ||
_loginPipelineBuilder = Substitute.For<ILoginPipelineBuilder>(); | ||
|
||
_sut = new LoginService( | ||
_logger, | ||
_ansiConsole, | ||
_loginPipelineBuilder | ||
); | ||
} | ||
|
||
[Fact] | ||
public async Task PersistentOnlyAsync_NotQuietAndNoUser_ReturnNullAndNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.PersistedOnly().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns((User?)null); | ||
|
||
var result = await _sut.PersistentOnlyAsync(globalArgs, args, CancellationToken.None); | ||
|
||
result.Should().BeNull(); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task PersistentOnlyAsync_NotQuietAndUser_ReturnUserAndPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.PersistedOnly().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.PersistentOnlyAsync(globalArgs, args, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(new LogEntry(LogLevel.Information, "Logged in as test")); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task PersistentOnlyAsync_QuietAndUser_ReturnUserAndDoNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, true, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.PersistedOnly().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.PersistentOnlyAsync(globalArgs, args, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithoutPersistentAsync_NotQuietAndNoUser_ReturnNullAndNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithoutPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns((User?)null); | ||
|
||
var action = () => _sut.WithoutPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
await action.Should().ThrowAsync<Exception>(); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithoutPersistentAsync_NotQuietAndUser_ReturnUserAndPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithoutPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.WithoutPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(new LogEntry(LogLevel.Information, "Logged in as test")); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithoutPersistentAsync_QuietAndUser_ReturnUserAndDoNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, true, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithoutPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.WithoutPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithPersistentAsync_NotQuietAndNoUser_ReturnNullAndNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns((User?)null); | ||
|
||
var action = () => _sut.WithPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
await action.Should().ThrowAsync<Exception>(); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithPersistentAsync_NotQuietAndUser_ReturnUserAndPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, false, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.WithPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(new LogEntry(LogLevel.Information, "Logged in as test")); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
|
||
[Fact] | ||
public async Task WithPersistentAsync_QuietAndUser_ReturnUserAndDoNotPrint() | ||
{ | ||
var globalArgs = new GlobalArgs(LogLevel.Debug, true, new FileInfo("Test")); | ||
var args = new LoginArgs(null, false); | ||
var user = new User("test", "test"); | ||
|
||
var pipeline = Substitute.For<ILoginPipeline>(); | ||
_loginPipelineBuilder.WithPersistent().Returns(pipeline); | ||
pipeline.LoginAsync(globalArgs, args, false, CancellationToken.None).Returns(user); | ||
|
||
var result = await _sut.WithPersistentAsync(globalArgs, args, false, CancellationToken.None); | ||
|
||
result.Should().Be(user); | ||
|
||
_logger.VerifyLogs(); | ||
await Verify(_ansiConsole.Output); | ||
} | ||
} |