-
Notifications
You must be signed in to change notification settings - Fork 2
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
4 changed files
with
104 additions
and
11 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
...iteaClient.IntegrationTests/Common/Initializers/TestData/Abstractions/ITestFileCreator.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 |
---|---|---|
@@ -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); | ||
} |
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
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
92 changes: 92 additions & 0 deletions
92
....GiteaClient.IntegrationTests/Gitea/PullRequest/MergePullRequest/MergePullRequestTests.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,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<ITestRepositoryCreator>(); | ||
_branchCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestBranchCreator>(); | ||
_pullRequestCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestPullRequestCreator>(); | ||
_fileCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestFileCreator>(); | ||
_sut = giteaCollectionFixture.ServiceProvider.GetRequiredService<IGiteaClient>(); | ||
} | ||
|
||
[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(); | ||
} | ||
} |