|
| 1 | +using System; |
1 | 2 | using FluentAssertions;
|
| 3 | +using Moq; |
| 4 | +using OctoshiftCLI.BbsToGithub; |
2 | 5 | using OctoshiftCLI.BbsToGithub.Commands;
|
| 6 | +using OctoshiftCLI.Contracts; |
3 | 7 | using Xunit;
|
4 | 8 |
|
5 | 9 | namespace OctoshiftCLI.Tests.BbsToGithub.Commands;
|
6 | 10 |
|
7 | 11 | public class GenerateScriptCommandTests
|
8 | 12 | {
|
| 13 | + private const string BBS_SERVER_URL = "http://bbs.contoso.com:7990"; |
| 14 | + |
| 15 | + private readonly Mock<IServiceProvider> _mockServiceProvider = new(); |
| 16 | + private readonly Mock<BbsApiFactory> _mockBbsApiFactory = TestHelpers.CreateMock<BbsApiFactory>(); |
| 17 | + private readonly Mock<OctoLogger> _mockOctoLogger = TestHelpers.CreateMock<OctoLogger>(); |
| 18 | + private readonly Mock<EnvironmentVariableProvider> _mockEnvironmentVariableProvider = TestHelpers.CreateMock<EnvironmentVariableProvider>(); |
| 19 | + private readonly Mock<FileSystemProvider> _mockFileSystemProvider = TestHelpers.CreateMock<FileSystemProvider>(); |
| 20 | + private readonly Mock<IVersionProvider> _mockVersionProvider = new(); |
| 21 | + |
| 22 | + private readonly GenerateScriptCommand _command = new(); |
| 23 | + |
| 24 | + public GenerateScriptCommandTests() |
| 25 | + { |
| 26 | + _mockServiceProvider.Setup(m => m.GetService(typeof(OctoLogger))).Returns(_mockOctoLogger.Object); |
| 27 | + _mockServiceProvider.Setup(m => m.GetService(typeof(EnvironmentVariableProvider))).Returns(_mockEnvironmentVariableProvider.Object); |
| 28 | + _mockServiceProvider.Setup(m => m.GetService(typeof(FileSystemProvider))).Returns(_mockFileSystemProvider.Object); |
| 29 | + _mockServiceProvider.Setup(m => m.GetService(typeof(IVersionProvider))).Returns(_mockVersionProvider.Object); |
| 30 | + _mockServiceProvider.Setup(m => m.GetService(typeof(BbsApiFactory))).Returns(_mockBbsApiFactory.Object); |
| 31 | + } |
| 32 | + |
9 | 33 | [Fact]
|
10 | 34 | public void Should_Have_Options()
|
11 | 35 | {
|
12 |
| - var command = new GenerateScriptCommand(); |
13 |
| - command.Should().NotBeNull(); |
14 |
| - command.Name.Should().Be("generate-script"); |
15 |
| - command.Options.Count.Should().Be(10); |
16 |
| - |
17 |
| - TestHelpers.VerifyCommandOption(command.Options, "bbs-server-url", true); |
18 |
| - TestHelpers.VerifyCommandOption(command.Options, "github-org", true); |
19 |
| - TestHelpers.VerifyCommandOption(command.Options, "bbs-username", false); |
20 |
| - TestHelpers.VerifyCommandOption(command.Options, "bbs-password", false); |
21 |
| - TestHelpers.VerifyCommandOption(command.Options, "bbs-shared-home", false); |
22 |
| - TestHelpers.VerifyCommandOption(command.Options, "ssh-user", false); |
23 |
| - TestHelpers.VerifyCommandOption(command.Options, "ssh-private-key", false); |
24 |
| - TestHelpers.VerifyCommandOption(command.Options, "ssh-port", false); |
25 |
| - TestHelpers.VerifyCommandOption(command.Options, "output", false); |
26 |
| - TestHelpers.VerifyCommandOption(command.Options, "verbose", false); |
| 36 | + _command.Should().NotBeNull(); |
| 37 | + _command.Name.Should().Be("generate-script"); |
| 38 | + _command.Options.Count.Should().Be(11); |
| 39 | + |
| 40 | + TestHelpers.VerifyCommandOption(_command.Options, "bbs-server-url", true); |
| 41 | + TestHelpers.VerifyCommandOption(_command.Options, "github-org", true); |
| 42 | + TestHelpers.VerifyCommandOption(_command.Options, "bbs-username", false); |
| 43 | + TestHelpers.VerifyCommandOption(_command.Options, "bbs-password", false); |
| 44 | + TestHelpers.VerifyCommandOption(_command.Options, "bbs-shared-home", false); |
| 45 | + TestHelpers.VerifyCommandOption(_command.Options, "ssh-user", false); |
| 46 | + TestHelpers.VerifyCommandOption(_command.Options, "ssh-private-key", false); |
| 47 | + TestHelpers.VerifyCommandOption(_command.Options, "ssh-port", false); |
| 48 | + TestHelpers.VerifyCommandOption(_command.Options, "output", false); |
| 49 | + TestHelpers.VerifyCommandOption(_command.Options, "kerberos", false, true); |
| 50 | + TestHelpers.VerifyCommandOption(_command.Options, "verbose", false); |
| 51 | + } |
| 52 | + |
| 53 | + [Fact] |
| 54 | + public void It_Gets_A_Kerberos_HttpClient_When_Kerberos_Is_True() |
| 55 | + { |
| 56 | + var args = new GenerateScriptCommandArgs |
| 57 | + { |
| 58 | + BbsServerUrl = BBS_SERVER_URL, |
| 59 | + Kerberos = true |
| 60 | + }; |
| 61 | + |
| 62 | + _command.BuildHandler(args, _mockServiceProvider.Object); |
| 63 | + |
| 64 | + _mockBbsApiFactory.Verify(m => m.CreateKerberos(BBS_SERVER_URL)); |
| 65 | + } |
| 66 | + |
| 67 | + [Fact] |
| 68 | + public void It_Gets_A_Default_HttpClient_When_Kerberos_Is_Not_Set() |
| 69 | + { |
| 70 | + var bbsTestUser = "user"; |
| 71 | + var bbsTestPassword = "password"; |
| 72 | + |
| 73 | + var args = new GenerateScriptCommandArgs |
| 74 | + { |
| 75 | + BbsServerUrl = BBS_SERVER_URL, |
| 76 | + BbsUsername = bbsTestUser, |
| 77 | + BbsPassword = bbsTestPassword, |
| 78 | + }; |
| 79 | + |
| 80 | + _command.BuildHandler(args, _mockServiceProvider.Object); |
| 81 | + |
| 82 | + _mockBbsApiFactory.Verify(m => m.Create(BBS_SERVER_URL, bbsTestUser, bbsTestPassword)); |
27 | 83 | }
|
28 | 84 | }
|
0 commit comments