-
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.
Merge branch 'master' into feature/add_commit_api
- Loading branch information
Showing
44 changed files
with
1,237 additions
and
11 deletions.
There are no files selected for viewing
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
55 changes: 55 additions & 0 deletions
55
...iteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTests.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,55 @@ | ||
using System.Net; | ||
using FluentAssertions; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Mohaymen.GiteaClient.Gitea.Client.Abstractions; | ||
using Mohaymen.GiteaClient.Gitea.PullRequest.CreatePullRequest.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.CreatePullRequest; | ||
|
||
[Collection("GiteaIntegrationTests")] | ||
public class CreatePullRequestTests | ||
{ | ||
private readonly IGiteaClient _sut; | ||
private readonly ITestRepositoryCreator _repositoryCreator; | ||
private readonly ITestBranchCreator _branchCreator; | ||
private readonly GiteaCollectionFixture _giteaCollectionFixture; | ||
|
||
public CreatePullRequestTests(GiteaCollectionFixture giteaCollectionFixture) | ||
{ | ||
_giteaCollectionFixture = giteaCollectionFixture ?? throw new ArgumentNullException(nameof(giteaCollectionFixture)); | ||
_repositoryCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestRepositoryCreator>(); | ||
_branchCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestBranchCreator>(); | ||
_sut = giteaCollectionFixture.ServiceProvider.GetRequiredService<IGiteaClient>(); | ||
} | ||
|
||
[Fact] | ||
public async Task CreatePullRequest_ShouldGetBranchListOfRepo_WhenInputsAreProvidedProperly() | ||
{ | ||
// Arrange | ||
const string repositoryName = "create_pull_request_repo"; | ||
const string branchName = "create_pull_request_branch"; | ||
var cancellationToken = _giteaCollectionFixture.CancellationToken; | ||
|
||
await _repositoryCreator.CreateRepositoryAsync(repositoryName, cancellationToken); | ||
await _branchCreator.CreateBranchAsync(repositoryName, branchName, cancellationToken); | ||
|
||
const string title = "title"; | ||
var createPullRequestCommandDto = new CreatePullRequestCommandDto | ||
{ | ||
RepositoryName = repositoryName, | ||
Title = title, | ||
HeadBranch = branchName, | ||
BaseBranch = GiteaTestConstants.DefaultBranch | ||
}; | ||
|
||
// Act | ||
var actual = await _sut.PullRequestClient.CreatePullRequestAsync(createPullRequestCommandDto, cancellationToken); | ||
|
||
// Assert | ||
actual.StatusCode.Should().Be(HttpStatusCode.Created); | ||
actual.Content!.Title.Should().Be(title); | ||
} | ||
} |
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
62 changes: 62 additions & 0 deletions
62
...n.GiteaClient.IntegrationTests/Gitea/Repository/DeleteRepository/DeleteRepositoryTests.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,62 @@ | ||
using System.Net; | ||
using FluentAssertions; | ||
using FluentValidation; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Mohaymen.GiteaClient.Gitea.Client.Abstractions; | ||
using Mohaymen.GiteaClient.Gitea.Repository.DeleteRepository.Dto; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Assertions.Abstractions; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Collections.Gitea; | ||
|
||
namespace Mohaymen.GiteaClient.IntegrationTests.Gitea.Repository.DeleteRepository; | ||
|
||
[Collection("GiteaIntegrationTests")] | ||
public class DeleteRepositoryTests : IClassFixture<RepositoryClassFixture> | ||
{ | ||
private readonly IGiteaClient _sut; | ||
private readonly ITestRepositoryChecker _testRepositoryChecker; | ||
private readonly GiteaCollectionFixture _giteaCollectionFixture; | ||
|
||
public DeleteRepositoryTests(GiteaCollectionFixture giteaCollectionFixture) | ||
{ | ||
_giteaCollectionFixture = giteaCollectionFixture ?? throw new ArgumentNullException(nameof(giteaCollectionFixture)); | ||
_testRepositoryChecker = _giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestRepositoryChecker>(); | ||
_sut = _giteaCollectionFixture.ServiceProvider.GetRequiredService<IGiteaClient>(); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteRepositoryAsync_ShouldReturnNotContentSuccessResponse_WhenRepositoryExistsAndDeleted() | ||
{ | ||
// Arrange | ||
var deletedRepositoryCommandDto = new DeleteRepositoryCommandDto | ||
{ | ||
RepositoryName = RepositoryClassFixture.DeleteRepositoryName | ||
}; | ||
|
||
// Act | ||
var actual = await _sut.RepositoryClient.DeleteRepositoryAsync(deletedRepositoryCommandDto, _giteaCollectionFixture.CancellationToken); | ||
|
||
// Assert | ||
actual.StatusCode.Should().Be(HttpStatusCode.NoContent); | ||
var isRepositoryExists = await _testRepositoryChecker.ContainsRepositoryAsync(RepositoryClassFixture.DeleteRepositoryName, _giteaCollectionFixture.CancellationToken); | ||
isRepositoryExists.Should().BeFalse(); | ||
} | ||
|
||
[Fact] | ||
public async Task DeleteRepositoryAsync_ShouldReturnNotFound_WhenRepositoryDoesNotExist() | ||
{ | ||
// Arrange | ||
const string repositoryName = "sampleFakeRepo"; | ||
var deletedRepositoryCommandDto = new DeleteRepositoryCommandDto | ||
{ | ||
RepositoryName = repositoryName | ||
}; | ||
|
||
// Act | ||
var actual = await _sut.RepositoryClient.DeleteRepositoryAsync(deletedRepositoryCommandDto, _giteaCollectionFixture.CancellationToken); | ||
|
||
// Assert | ||
actual.StatusCode.Should().Be(HttpStatusCode.NotFound); | ||
var isRepositoryExists = await _testRepositoryChecker.ContainsRepositoryAsync(repositoryName, _giteaCollectionFixture.CancellationToken); | ||
isRepositoryExists.Should().BeFalse(); | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
Mohaymen.GiteaClient.IntegrationTests/Gitea/Repository/RepositoryClassFixture.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,31 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Collections.Gitea; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Initializers.TestData.Abstractions; | ||
|
||
namespace Mohaymen.GiteaClient.IntegrationTests.Gitea.Repository; | ||
|
||
internal sealed class RepositoryClassFixture : IAsyncLifetime | ||
{ | ||
public const string SearchRepositoryName = "SearchUseCaseRepository"; | ||
public const string DeleteRepositoryName = "DeleteUseCaseRepository"; | ||
|
||
private readonly ITestRepositoryCreator _testRepositoryCreator; | ||
private readonly GiteaCollectionFixture _giteaCollectionFixture; | ||
|
||
public RepositoryClassFixture(GiteaCollectionFixture giteaCollectionFixture) | ||
{ | ||
_giteaCollectionFixture = giteaCollectionFixture ?? throw new ArgumentNullException(nameof(giteaCollectionFixture)); | ||
_testRepositoryCreator = giteaCollectionFixture.ServiceProvider.GetRequiredService<ITestRepositoryCreator>(); | ||
} | ||
|
||
public async Task InitializeAsync() | ||
{ | ||
await _testRepositoryCreator.CreateRepositoryAsync(SearchRepositoryName, _giteaCollectionFixture.CancellationToken); | ||
await _testRepositoryCreator.CreateRepositoryAsync(DeleteRepositoryName, _giteaCollectionFixture.CancellationToken); | ||
} | ||
|
||
public Task DisposeAsync() | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...n.GiteaClient.IntegrationTests/Gitea/Repository/SearchRepository/SearchRepositoryTests.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,64 @@ | ||
using System.Net; | ||
using FluentAssertions; | ||
using FluentValidation; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Mohaymen.GiteaClient.Gitea.Client.Abstractions; | ||
using Mohaymen.GiteaClient.Gitea.Repository.SearchRepository.Dtos; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Assertions.Abstractions; | ||
using Mohaymen.GiteaClient.IntegrationTests.Common.Collections.Gitea; | ||
|
||
namespace Mohaymen.GiteaClient.IntegrationTests.Gitea.Repository.SearchRepository; | ||
|
||
[Collection("GiteaIntegrationTests")] | ||
public class SearchRepositoryTests : IClassFixture<RepositoryClassFixture> | ||
{ | ||
private readonly IGiteaClient _sut; | ||
private readonly GiteaCollectionFixture _giteaCollectionFixture; | ||
|
||
public SearchRepositoryTests(GiteaCollectionFixture giteaCollectionFixture) | ||
{ | ||
_giteaCollectionFixture = giteaCollectionFixture ?? throw new ArgumentNullException(nameof(giteaCollectionFixture)); | ||
_sut = giteaCollectionFixture.ServiceProvider.GetRequiredService<IGiteaClient>(); | ||
|
||
} | ||
|
||
[Fact] | ||
public async Task SearchRepositoryAsync_ShouldReturnListOfMatchedRepositories_WhenSearchQueryIsProvidedAndHasMathc() | ||
{ | ||
// Arrange | ||
var searchRepositoryQuery = new SearchRepositoryQueryDto | ||
{ | ||
Query = "Repo", | ||
Limit = 10, | ||
Page = 1 | ||
}; | ||
|
||
// Act | ||
var actual = await _sut.RepositoryClient.SearchRepositoryAsync(searchRepositoryQuery, _giteaCollectionFixture.CancellationToken); | ||
|
||
// Assert | ||
actual.StatusCode.Should().Be(HttpStatusCode.OK); | ||
actual.Content!.SearchResult.Select(x => x.RepositoryName).Should() | ||
.Contain(RepositoryClassFixture.SearchRepositoryName); | ||
} | ||
|
||
[Fact] | ||
public async Task SearchRepositoryAsync_ShouldReturnEmptyList_WhenSearchQueryIsProvidedAndNotMatch() | ||
{ | ||
// Arrange | ||
var searchRepositoryQuery = new SearchRepositoryQueryDto | ||
{ | ||
Query = "ahmad", | ||
Page = 1, | ||
Limit = 5 | ||
}; | ||
|
||
// Act | ||
var actual = await _sut.RepositoryClient.SearchRepositoryAsync(searchRepositoryQuery, _giteaCollectionFixture.CancellationToken); | ||
|
||
// Assert | ||
actual.StatusCode.Should().Be(HttpStatusCode.OK); | ||
actual.Content!.SearchResult.Should().NotBeNull(); | ||
actual.Content!.SearchResult.Should().BeEmpty(); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
Mohaymen.GiteaClient.Tests/Gitea/PullRequest/Common/Facade/PullRequestFacadeTests.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,77 @@ | ||
using MediatR; | ||
using Mohaymen.GiteaClient.Gitea.PullRequest.Common.Facade; | ||
using Mohaymen.GiteaClient.Gitea.PullRequest.Common.Facade.Abstractions; | ||
using Mohaymen.GiteaClient.Gitea.PullRequest.CreatePullRequest.Commands; | ||
using Mohaymen.GiteaClient.Gitea.PullRequest.CreatePullRequest.Dtos; | ||
using NSubstitute; | ||
using Xunit; | ||
|
||
namespace Mohaymen.GiteaClient.Tests.Gitea.PullRequest.Common.Facade; | ||
|
||
public class PullRequestFacadeTests | ||
{ | ||
private readonly IMediator _mediator; | ||
private readonly IPullRequestFacade _sut; | ||
|
||
public PullRequestFacadeTests() | ||
{ | ||
_mediator = Substitute.For<IMediator>(); | ||
_sut = new PullRequestFacade(_mediator); | ||
} | ||
|
||
[Fact] | ||
public async Task CreatePullRequestAsync_ShouldCallSend_WhenAllFieldsAreProvided() | ||
{ | ||
// Arrange | ||
const string repositoryName = "repo"; | ||
const string headBranch = "head"; | ||
const string baseBranch = "base"; | ||
const string body = "body"; | ||
const string title = "title"; | ||
const string assignee = "assignee"; | ||
var assignees = new List<string> | ||
{ | ||
"assignee1", | ||
"assignee2" | ||
}; | ||
var commandDto = new CreatePullRequestCommandDto | ||
{ | ||
RepositoryName = repositoryName, | ||
HeadBranch = headBranch, | ||
BaseBranch = baseBranch, | ||
Body = body, | ||
Title = title, | ||
Assignee = assignee, | ||
Assignees = assignees | ||
}; | ||
|
||
// Act | ||
await _sut.CreatePullRequestAsync(commandDto, default); | ||
|
||
// Assert | ||
await _mediator.Received(1).Send(Arg.Is<CreatePullRequestCommand>(x => x.RepositoryName == repositoryName | ||
&& x.HeadBranch == headBranch | ||
&& x.BaseBranch == baseBranch | ||
&& x.Body == body | ||
&& x.Title == title | ||
&& x.Assignee == assignee | ||
&& x.Assignees!.SequenceEqual(assignees))); | ||
} | ||
|
||
[Fact] | ||
public async Task CreatePullRequestAsync_ShouldCallSend_WhenOptionalFieldsAreNotProvided() | ||
{ | ||
// Arrange | ||
const string repositoryName = "repo"; | ||
var commandDto = new CreatePullRequestCommandDto | ||
{ | ||
RepositoryName = repositoryName | ||
}; | ||
|
||
// Act | ||
await _sut.CreatePullRequestAsync(commandDto, default); | ||
|
||
// Assert | ||
await _mediator.Received(1).Send(Arg.Is<CreatePullRequestCommand>(x => x.RepositoryName == repositoryName)); | ||
} | ||
} |
Oops, something went wrong.