From 2b17bb3565254fb4aca7fb9527385d12b32e9c86 Mon Sep 17 00:00:00 2001 From: HamedSY Date: Thu, 25 Jul 2024 13:38:30 +0330 Subject: [PATCH] fix: integration tests --- .../CreatePullRequestTests.cs | 20 +++++++++--- .../CreatePullRequestTestsClassFixture.cs | 32 ------------------- 2 files changed, 16 insertions(+), 36 deletions(-) delete mode 100644 Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTestsClassFixture.cs diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTests.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTests.cs index 144e8cb..6b2631a 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTests.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTests.cs @@ -4,19 +4,24 @@ 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 : IClassFixture +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(); + _branchCreator = _giteaCollectionFixture.ServiceProvider.GetRequiredService(); _sut = giteaCollectionFixture.ServiceProvider.GetRequiredService(); } @@ -24,17 +29,24 @@ public CreatePullRequestTests(GiteaCollectionFixture giteaCollectionFixture) public async Task CreatePullRequest_ShouldGetBranchListOfRepo_WhenInputsAreProvidedProperly() { // Arrange + const string repositoryName = GiteaTestConstants.RepositoryName; + const string branchName = "test_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 = GiteaTestConstants.RepositoryName, + RepositoryName = repositoryName, Title = title, - HeadBranch = CreatePullRequestTestsClassFixture.BranchName, + HeadBranch = branchName, BaseBranch = GiteaTestConstants.DefaultBranch }; // Act - var actual = await _sut.PullRequestClient.CreatePullRequestAsync(createPullRequestCommandDto, _giteaCollectionFixture.CancellationToken); + var actual = await _sut.PullRequestClient.CreatePullRequestAsync(createPullRequestCommandDto, cancellationToken); // Assert actual.StatusCode.Should().Be(HttpStatusCode.Created); diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTestsClassFixture.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTestsClassFixture.cs deleted file mode 100644 index e40559f..0000000 --- a/Mohaymen.GiteaClient.IntegrationTests/Gitea/PullRequest/CreatePullRequest/CreatePullRequestTestsClassFixture.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -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; - -public class CreatePullRequestTestsClassFixture : IAsyncLifetime -{ - public const string BranchName = "branch"; - - private readonly ITestRepositoryCreator _testRepositoryCreator; - private readonly ITestBranchCreator _testBranchCreator; - - public CreatePullRequestTestsClassFixture(GiteaCollectionFixture giteaCollectionFixture) - { - _testRepositoryCreator = giteaCollectionFixture.ServiceProvider.GetRequiredService(); - _testBranchCreator = giteaCollectionFixture.ServiceProvider.GetRequiredService(); - } - - public async Task InitializeAsync() - { - var repo = GiteaTestConstants.RepositoryName; - await _testRepositoryCreator.CreateRepository(repo); - await _testBranchCreator.CreateBranch(repo, BranchName); - } - - public Task DisposeAsync() - { - return Task.CompletedTask; - } -} \ No newline at end of file