diff --git a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/Abstractions/ITestFileCreator.cs b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/Abstractions/ITestFileCreator.cs index f0a2e2e..2c32580 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/Abstractions/ITestFileCreator.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/Abstractions/ITestFileCreator.cs @@ -1,6 +1,8 @@ -namespace Mohaymen.GiteaClient.IntegrationTests.Common.Initializers.TestData.Abstractions; +using Mohaymen.GiteaClient.Gitea.File.CreateFile.Dtos; + +namespace Mohaymen.GiteaClient.IntegrationTests.Common.Initializers.TestData.Abstractions; public interface ITestFileCreator { - Task CreateFileAsync(string repositoryName, string filePath, string content, CancellationToken cancellationToken); + Task CreateFileAsync(CreateFileCommandDto createFileCommandDto, CancellationToken cancellationToken); } \ No newline at end of file diff --git a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestFileCreator.cs b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestFileCreator.cs index 06d69ff..51e279c 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestFileCreator.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestFileCreator.cs @@ -13,15 +13,8 @@ public TestFileCreator(IFileFacade fileFacade) _fileFacade = fileFacade ?? throw new ArgumentNullException(nameof(fileFacade)); } - public async Task CreateFileAsync(string repositoryName, string filePath, string content, CancellationToken cancellationToken) + public async Task CreateFileAsync(CreateFileCommandDto createFileCommandDto, CancellationToken cancellationToken) { - var createFileCommandDto = new CreateFileCommandDto - { - RepositoryName = repositoryName, - FilePath = filePath, - Content = content - }; - await _fileFacade.CreateFileAsync(createFileCommandDto, cancellationToken); } } \ No newline at end of file diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFile/GetFileTests.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFile/GetFileTests.cs index a0a908c..8851f84 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFile/GetFileTests.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Gitea/File/GetFile/GetFileTests.cs @@ -35,7 +35,13 @@ public async Task GetFile_ShouldGetFileWithOkStatusCode_WhenInputsAreProvidedPro const string content = "Hello, World!"; var cancellationToken = _giteaCollectionFixture.CancellationToken; await _repositoryCreator.CreateRepositoryAsync(repositoryName, cancellationToken); - await _fileCreator.CreateFileAsync(repositoryName, filePath, content, cancellationToken); + var createFileCommandDto = new CreateFileCommandDto + { + RepositoryName = repositoryName, + FilePath = filePath, + Content = content + }; + await _fileCreator.CreateFileAsync(createFileCommandDto, cancellationToken); var getFileCommandDto = new GetFileCommandDto { diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/MergePullRequest/MergePullRequestTests.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/MergePullRequest/MergePullRequestTests.cs new file mode 100644 index 0000000..55d6d26 --- /dev/null +++ b/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/MergePullRequest/MergePullRequestTests.cs @@ -0,0 +1,92 @@ +using System.Net; +using FluentAssertions; +using Microsoft.Extensions.DependencyInjection; +using Mohaymen.GiteaClient.Gitea.Client.Abstractions; +using Mohaymen.GiteaClient.Gitea.File.CreateFile.Dtos; +using Mohaymen.GiteaClient.Gitea.PullRequest.Common.Enums; +using Mohaymen.GiteaClient.Gitea.PullRequest.CreatePullRequest.Dtos; +using Mohaymen.GiteaClient.Gitea.PullRequest.GetPullRequestList.Dtos; +using Mohaymen.GiteaClient.Gitea.PullRequest.MergePullRequest.Dtos; +using Mohaymen.GiteaClient.IntegrationTests.Common.Collections.Gitea; +using Mohaymen.GiteaClient.IntegrationTests.Common.Initializers.TestData.Abstractions; +using Mohaymen.GiteaClient.IntegrationTests.Common.Models; + +namespace Mohaymen.GiteaClient.IntegrationTests.Gitea.PullRequest.MergePullRequest; + +[Collection("GiteaIntegrationTests")] +public class MergePullRequestTests +{ + private readonly IGiteaClient _sut; + private readonly ITestRepositoryCreator _repositoryCreator; + private readonly ITestBranchCreator _branchCreator; + private readonly ITestPullRequestCreator _pullRequestCreator; + private readonly ITestFileCreator _fileCreator; + private readonly GiteaCollectionFixture _giteaCollectionFixture; + + public MergePullRequestTests(GiteaCollectionFixture giteaCollectionFixture) + { + _giteaCollectionFixture = giteaCollectionFixture ?? throw new ArgumentNullException(nameof(giteaCollectionFixture)); + _repositoryCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService(); + _branchCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService(); + _pullRequestCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService(); + _fileCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService(); + _sut = giteaCollectionFixture.ServiceProvider.GetRequiredService(); + } + + [Fact] + public async Task MergePullRequest_ShouldMergePullRequest_WhenInputsAreProvidedProperly() + { + // Arrange + const string repositoryName = "merge_pull_request_repo"; + const string headBranch = "merge_pull_request_branch"; + const string baseBranch = GiteaTestConstants.DefaultBranch; + const string title = "merge_pull_request_title"; + const string assignee = GiteaTestConstants.Username; + var createPullRequestCommandDto = new CreatePullRequestCommandDto + { + RepositoryName = repositoryName, + HeadBranch = headBranch, + BaseBranch = baseBranch, + Title = title, + Assignee = assignee + }; + var cancellationToken = _giteaCollectionFixture.CancellationToken; + const string filePath = "merge_pull_request_file.txt"; + const string content = "merge_pull_request_content.txt"; + var createFileCommandDto = new CreateFileCommandDto + { + RepositoryName = repositoryName, + FilePath = filePath, + Content = content, + BranchName = headBranch + }; + + await _repositoryCreator.CreateRepositoryAsync(repositoryName, cancellationToken); + await _branchCreator.CreateBranchAsync(repositoryName, headBranch, cancellationToken); + await _fileCreator.CreateFileAsync(createFileCommandDto, cancellationToken); + await _pullRequestCreator.CreatePullRequestAsync(createPullRequestCommandDto, cancellationToken); + + var mergePullRequestCommandDto = new MergePullRequestCommandDto + { + RepositoryName = repositoryName, + Index = 1, + MergeType = MergeType.Merge + }; + var expectedGetPullRequestListCommandDto = new GetPullRequestListCommandDto + { + RepositoryName = repositoryName + }; + + // Act + var actual = await _sut.PullRequestClient.MergePullRequestAsync(mergePullRequestCommandDto, cancellationToken); + + // Assert + actual.StatusCode.Should().Be(HttpStatusCode.OK); + var getPullRequestListResponse = await _sut.PullRequestClient.GetPullRequestListAsync( + expectedGetPullRequestListCommandDto, + _giteaCollectionFixture.CancellationToken); + getPullRequestListResponse.StatusCode.Should().Be(HttpStatusCode.OK); + getPullRequestListResponse.Content.Should().NotBeNull(); + getPullRequestListResponse.Content!.First().Merged.Should().BeTrue(); + } +} \ No newline at end of file