From 6c8b7ab7dd3d12be8c8ddce938b8b179ac645800 Mon Sep 17 00:00:00 2001 From: Arin Ghazarian Date: Thu, 16 Jan 2025 14:05:00 -0800 Subject: [PATCH] Swap FluentAssertions with xUnit assertions --- .../MigrateRepoCommandHandlerTests.cs | 494 +++++++++--------- 1 file changed, 242 insertions(+), 252 deletions(-) diff --git a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs index a8836c915..f6367d535 100644 --- a/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs +++ b/src/OctoshiftCLI.Tests/gei/Commands/MigrateRepo/MigrateRepoCommandHandlerTests.cs @@ -3,7 +3,6 @@ using System.IO; using System.Net.Http; using System.Threading.Tasks; -using FluentAssertions; using Moq; using OctoshiftCLI.Extensions; using OctoshiftCLI.GithubEnterpriseImporter.Commands.MigrateRepo; @@ -94,8 +93,7 @@ public async Task Dont_Generate_Archives_If_Target_Repo_Exists() TargetRepo = TARGET_REPO, GhesApiUrl = GHES_API_URL, }; - await FluentActions - .Invoking(async () => await _handler.Handle(args)).Should().ThrowExactlyAsync(); + await Assert.ThrowsAsync(async () => await _handler.Handle(args)); // Assert _mockSourceGithubApi.Verify(x => x.StartGitArchiveGeneration(It.IsAny(), It.IsAny()), Times.Never); @@ -139,7 +137,7 @@ public async Task Happy_Path_Without_Wait() _mockTargetGithubApi.Verify(m => m.StartMigration(MIGRATION_SOURCE_ID, GITHUB_REPO_URL, GITHUB_ORG_ID, TARGET_REPO, GITHUB_SOURCE_PAT, GITHUB_TARGET_PAT, null, null, false, null, false)); _mockOctoLogger.Verify(m => m.LogInformation(It.IsAny()), Times.Exactly(2)); - actualLogOutput.Should().Equal(expectedLogOutput); + Assert.Equal(expectedLogOutput, actualLogOutput); _mockTargetGithubApi.VerifyNoOtherCalls(); } @@ -177,7 +175,7 @@ public async Task Skip_Migration_If_Target_Repo_Exists() // Assert _mockOctoLogger.Verify(m => m.LogWarning(It.IsAny()), Times.Exactly(1)); - actualLogOutput.Should().Contain(expectedLogOutput); + Assert.Contains(expectedLogOutput, actualLogOutput); } [Fact] @@ -229,19 +227,24 @@ public async Task Throws_Decorated_Error_When_Create_Migration_Source_Fails_With _mockEnvironmentVariableProvider.Setup(m => m.SourceGithubPersonalAccessToken(It.IsAny())).Returns(GITHUB_SOURCE_PAT); _mockEnvironmentVariableProvider.Setup(m => m.TargetGithubPersonalAccessToken(It.IsAny())).Returns(GITHUB_TARGET_PAT); - // Act - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - GithubSourceOrg = SOURCE_ORG, - SourceRepo = SOURCE_REPO, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - TargetApiUrl = TARGET_API_URL, - QueueOnly = true, - })) - .Should() - .ThrowAsync() - .WithMessage($"monalisa does not have the correct permissions to execute `CreateMigrationSource`. Please check that:\n (a) you are a member of the `{TARGET_ORG}` organization,\n (b) you are an organization owner or you have been granted the migrator role and\n (c) your personal access token has the correct scopes.\nFor more information, see https://docs.github.com/en/migrations/using-github-enterprise-importer/preparing-to-migrate-with-github-enterprise-importer/managing-access-for-github-enterprise-importer."); + // Act, Assert + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + GithubSourceOrg = SOURCE_ORG, + SourceRepo = SOURCE_REPO, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + TargetApiUrl = TARGET_API_URL, + QueueOnly = true, + })); + Assert.Equal( + $"monalisa does not have the correct permissions to execute `CreateMigrationSource`. " + + $"Please check that:\n (a) you are a member of the `{TARGET_ORG}` organization,\n " + + $"(b) you are an organization owner or you have been granted the migrator role and\n " + + $"(c) your personal access token has the correct scopes.\n" + + $"For more information, see https://docs.github.com/en/migrations/using-github-enterprise-importer/preparing-to-migrate-with-github-enterprise-importer/managing-access-for-github-enterprise-importer.", + ex.Message); } [Fact] @@ -607,8 +610,8 @@ public async Task With_Duplicate_Archive_Paths() [Fact] public async Task Github_Only_One_Archive_Url_Throws_Error() { - await FluentActions - .Invoking(async () => await _handler.Handle(new MigrateRepoCommandArgs + await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs { GithubSourceOrg = SOURCE_ORG, SourceRepo = SOURCE_REPO, @@ -616,24 +619,21 @@ await FluentActions TargetRepo = TARGET_REPO, TargetApiUrl = TARGET_API_URL, GitArchiveUrl = GIT_ARCHIVE_URL, - })) - .Should().ThrowAsync(); + })); } [Fact] public async Task Ghes_Without_AzureConnectionString_Or_Aws_Bucket_Name_Throws_Error() { - await FluentActions - .Invoking(async () => await _handler.Handle(new MigrateRepoCommandArgs + await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs { GithubSourceOrg = SOURCE_ORG, SourceRepo = SOURCE_REPO, GithubTargetOrg = TARGET_ORG, TargetRepo = TARGET_REPO, GhesApiUrl = GHES_API_URL - } - )) - .Should().ThrowAsync(); + })); } [Fact] @@ -804,8 +804,8 @@ public async Task Ghes_Failed_Archive_Generation_Throws_Error() _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await FluentActions - .Invoking(async () => await _handler.Handle(new MigrateRepoCommandArgs + await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs { GithubSourceOrg = SOURCE_ORG, SourceRepo = SOURCE_REPO, @@ -814,9 +814,7 @@ await FluentActions TargetApiUrl = TARGET_API_URL, GhesApiUrl = GHES_API_URL, AzureStorageConnectionString = AZURE_CONNECTION_STRING - } - )) - .Should().ThrowAsync(); + })); } [Fact] @@ -920,7 +918,7 @@ public async Task It_Uses_Github_Source_And_Target_Pats_When_Provided() await _handler.Handle(args); // Assert - actualLogOutput.Should().NotContain("Since github-target-pat is provided, github-source-pat will also use its value."); + Assert.DoesNotContain("Since github-target-pat is provided, github-source-pat will also use its value.", actualLogOutput); _mockEnvironmentVariableProvider.Verify(m => m.SourceGithubPersonalAccessToken(It.IsAny()), Times.Never); _mockEnvironmentVariableProvider.Verify(m => m.TargetGithubPersonalAccessToken(It.IsAny()), Times.Never); @@ -968,7 +966,7 @@ public async Task It_Uses_Github_Source_Pat_When_Provided() await _handler.Handle(args); // Assert - actualLogOutput.Should().NotContain("Since github-target-pat is provided, github-source-pat will also use its value."); + Assert.DoesNotContain("Since github-target-pat is provided, github-source-pat will also use its value.", actualLogOutput); _mockEnvironmentVariableProvider.Verify(m => m.SourceGithubPersonalAccessToken(It.IsAny()), Times.Never); _mockEnvironmentVariableProvider.Verify(m => m.TargetGithubPersonalAccessToken(It.IsAny())); @@ -1354,18 +1352,17 @@ public async Task Ghes_With_Both_Azure_Storage_Connection_String_And_Aws_Bucket_ { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsBucketName = AWS_BUCKET_NAME - })) - .Should() - .ThrowAsync(); + await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsBucketName = AWS_BUCKET_NAME + })); } [Fact] @@ -1373,19 +1370,18 @@ public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Access_Key_Id { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AwsBucketName = AWS_BUCKET_NAME, - AwsSecretKey = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*--aws-access-key*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AwsBucketName = AWS_BUCKET_NAME, + AwsSecretKey = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("--aws-access-key", ex.Message); } [Fact] @@ -1393,19 +1389,18 @@ public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Secret_Key_Th { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AwsBucketName = AWS_BUCKET_NAME, - AwsAccessKey = AWS_ACCESS_KEY_ID - })) - .Should() - .ThrowAsync() - .WithMessage("*--aws-secret-key*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AwsBucketName = AWS_BUCKET_NAME, + AwsAccessKey = AWS_ACCESS_KEY_ID + })); + Assert.Contains("--aws-secret-key", ex.Message); } [Fact] @@ -1413,21 +1408,20 @@ public async Task Ghes_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Region_Throws { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AwsBucketName = AWS_BUCKET_NAME, - AwsAccessKey = AWS_ACCESS_KEY_ID, - AwsSecretKey = AWS_SECRET_ACCESS_KEY, - AwsSessionToken = AWS_SESSION_TOKEN - })) - .Should() - .ThrowAsync() - .WithMessage("Either --aws-region or AWS_REGION environment variable must be set."); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AwsBucketName = AWS_BUCKET_NAME, + AwsAccessKey = AWS_ACCESS_KEY_ID, + AwsSecretKey = AWS_SECRET_ACCESS_KEY, + AwsSessionToken = AWS_SESSION_TOKEN + })); + Assert.Contains("Either --aws-region or AWS_REGION environment variable must be set.", ex.Message); } [Fact] @@ -1435,19 +1429,19 @@ public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Access_Key_Prov { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsAccessKey = AWS_ACCESS_KEY_ID - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsAccessKey = AWS_ACCESS_KEY_ID + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1455,19 +1449,19 @@ public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secret_Key_Prov { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsSecretKey = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsSecretKey = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1475,19 +1469,19 @@ public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Session_Token_P { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsSessionToken = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsSessionToken = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1495,19 +1489,19 @@ public async Task Ghes_When_Aws_Bucket_Name_Not_Provided_But_Aws_Region_Provided { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GhesApiUrl = GHES_API_URL, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsRegion = AWS_REGION - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GhesApiUrl = GHES_API_URL, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsRegion = AWS_REGION + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1515,19 +1509,18 @@ public async Task GitArchivePath_With_Both_Azure_Storage_Connection_String_And_A { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsBucketName = AWS_BUCKET_NAME - })) - .Should() - .ThrowAsync(); + await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsBucketName = AWS_BUCKET_NAME + })); } [Fact] @@ -1535,20 +1528,19 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Acc { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AwsBucketName = AWS_BUCKET_NAME, - AwsSecretKey = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*--aws-access-key*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AwsBucketName = AWS_BUCKET_NAME, + AwsSecretKey = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("--aws-access-key", ex.Message); } [Fact] @@ -1556,20 +1548,19 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Sec { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AwsBucketName = AWS_BUCKET_NAME, - AwsAccessKey = AWS_ACCESS_KEY_ID - })) - .Should() - .ThrowAsync() - .WithMessage("*--aws-secret-key*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AwsBucketName = AWS_BUCKET_NAME, + AwsAccessKey = AWS_ACCESS_KEY_ID + })); + Assert.Contains("--aws-secret-key", ex.Message); } [Fact] @@ -1577,22 +1568,21 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Is_Provided_But_No_Aws_Reg { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AwsBucketName = AWS_BUCKET_NAME, - AwsAccessKey = AWS_ACCESS_KEY_ID, - AwsSecretKey = AWS_SECRET_ACCESS_KEY, - AwsSessionToken = AWS_SESSION_TOKEN - })) - .Should() - .ThrowAsync() - .WithMessage("Either --aws-region or AWS_REGION environment variable must be set."); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AwsBucketName = AWS_BUCKET_NAME, + AwsAccessKey = AWS_ACCESS_KEY_ID, + AwsSecretKey = AWS_SECRET_ACCESS_KEY, + AwsSessionToken = AWS_SESSION_TOKEN + })); + Assert.Contains("Either --aws-region or AWS_REGION environment variable must be set.", ex.Message); } [Fact] @@ -1600,20 +1590,20 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Acces { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsAccessKey = AWS_ACCESS_KEY_ID - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsAccessKey = AWS_ACCESS_KEY_ID + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1621,20 +1611,20 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Secre { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsSecretKey = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsSecretKey = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1642,20 +1632,20 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Sessi { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsSessionToken = AWS_SECRET_ACCESS_KEY - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsSessionToken = AWS_SECRET_ACCESS_KEY + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact] @@ -1663,20 +1653,20 @@ public async Task GitArchivePath_When_Aws_Bucket_Name_Not_Provided_But_Aws_Regio { _mockGhesVersionChecker.Setup(m => m.AreBlobCredentialsRequired(GHES_API_URL)).ReturnsAsync(true); - await _handler.Invoking(async x => await x.Handle(new MigrateRepoCommandArgs - { - SourceRepo = SOURCE_REPO, - GithubSourceOrg = SOURCE_ORG, - GithubTargetOrg = TARGET_ORG, - TargetRepo = TARGET_REPO, - GitArchivePath = GIT_ARCHIVE_FILE_PATH, - MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, - AzureStorageConnectionString = AZURE_CONNECTION_STRING, - AwsRegion = AWS_REGION - })) - .Should() - .ThrowAsync() - .WithMessage("*AWS S3*--aws-bucket-name*"); + var ex = await Assert.ThrowsAsync( + async () => await _handler.Handle(new MigrateRepoCommandArgs + { + SourceRepo = SOURCE_REPO, + GithubSourceOrg = SOURCE_ORG, + GithubTargetOrg = TARGET_ORG, + TargetRepo = TARGET_REPO, + GitArchivePath = GIT_ARCHIVE_FILE_PATH, + MetadataArchivePath = METADATA_ARCHIVE_FILE_PATH, + AzureStorageConnectionString = AZURE_CONNECTION_STRING, + AwsRegion = AWS_REGION + })); + Assert.Contains("AWS S3", ex.Message); + Assert.Contains("--aws-bucket-name", ex.Message); } [Fact]