From f9a7c214fc0cdba8ef5fcd5ff63da933c46fdd86 Mon Sep 17 00:00:00 2001 From: Alireza Eiji Date: Thu, 25 Jul 2024 17:55:26 +0330 Subject: [PATCH] correct integration tests --- .../Initializers/TestData/TestCommiter.cs | 4 +- .../Commit/CreateCommit/CreateCommitTests.cs | 43 +++++++++++-------- 2 files changed, 27 insertions(+), 20 deletions(-) diff --git a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestCommiter.cs b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestCommiter.cs index 8f8acc5..48742a1 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestCommiter.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Common/Initializers/TestData/TestCommiter.cs @@ -37,13 +37,13 @@ public async Task CreateFileAsync(string repositoryName, [ new FileCommitDto { - Path = "1.txt", + Path = filePath, Content = Convert.ToBase64String("sample test content"u8.ToArray()), CommitActionDto = CommitActionDto.Create } ] }; - await _commitFacade.CreateCommitAsync(createCommitDto, cancellationToken); + var rr = await _commitFacade.CreateCommitAsync(createCommitDto, cancellationToken); } } \ No newline at end of file diff --git a/Mohaymen.GiteaClient.IntegrationTests/Gitea/Commit/CreateCommit/CreateCommitTests.cs b/Mohaymen.GiteaClient.IntegrationTests/Gitea/Commit/CreateCommit/CreateCommitTests.cs index 7eca850..9333241 100644 --- a/Mohaymen.GiteaClient.IntegrationTests/Gitea/Commit/CreateCommit/CreateCommitTests.cs +++ b/Mohaymen.GiteaClient.IntegrationTests/Gitea/Commit/CreateCommit/CreateCommitTests.cs @@ -37,9 +37,10 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndAddFileWithItsContent_W const string filePath = "sample.txt"; const string content = "alireza eiji is the man of focus!"; const string expectedContent = "YWxpcmV6YSBlaWppIGlzIHRoZSBtYW4gb2YgZm9jdXMh"; + const string repoName = $"CreateFile_{RepositoryName}"; var createCommitCommandDto = new CreateCommitCommandDto { - RepositoryName = RepositoryName, + RepositoryName = repoName, BranchName = "main", CommitMessage = "some trivial commit", FileDtos = @@ -52,6 +53,8 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndAddFileWithItsContent_W } ] }; + + await _testRepositoryCreator.CreateRepositoryAsync(repoName, _giteaCollectionFixture.CancellationToken); // Act var actual = await _sut.CommitClient.CreateCommitAsync(createCommitCommandDto, _giteaCollectionFixture.CancellationToken); @@ -59,16 +62,16 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndAddFileWithItsContent_W // Assert actual.StatusCode.Should().Be(HttpStatusCode.Created); var commitSha = actual.Content!.CommitResponseDto.Sha; - var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(RepositoryName, + var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(repoName, "main", commitSha, _giteaCollectionFixture.CancellationToken); isCommitCreated.Should().BeTrue(); - var isFileExists = await _testFileChecker.ContainsFileAsync(RepositoryName, + var isFileExists = await _testFileChecker.ContainsFileAsync(repoName, filePath, _giteaCollectionFixture.CancellationToken); isFileExists.Should().BeTrue(); - var doesFileHaveContent = await _testFileChecker.HasFileContent(RepositoryName, + var doesFileHaveContent = await _testFileChecker.HasFileContent(repoName, filePath, expectedContent, _giteaCollectionFixture.CancellationToken); @@ -82,9 +85,10 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndEditFileWithItsContent_ const string filePath = "README.md"; const string content = "alireza eiji is the man of focus!"; const string expectedContent = "YWxpcmV6YSBlaWppIGlzIHRoZSBtYW4gb2YgZm9jdXMh"; + const string repoName = $"EditFile_{RepositoryName}"; var createCommitCommandDto = new CreateCommitCommandDto { - RepositoryName = RepositoryName, + RepositoryName = repoName, BranchName = "main", CommitMessage = "some trivial commit", FileDtos = @@ -97,6 +101,8 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndEditFileWithItsContent_ } ] }; + + await _testRepositoryCreator.CreateRepositoryAsync($"EditFile_{RepositoryName}", _giteaCollectionFixture.CancellationToken); // Act var actual = await _sut.CommitClient.CreateCommitAsync(createCommitCommandDto, _giteaCollectionFixture.CancellationToken); @@ -104,16 +110,16 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndEditFileWithItsContent_ // Assert actual.StatusCode.Should().Be(HttpStatusCode.Created); var commitSha = actual.Content!.CommitResponseDto.Sha; - var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(RepositoryName, + var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(repoName, "main", commitSha, _giteaCollectionFixture.CancellationToken); isCommitCreated.Should().BeTrue(); - var isFileExists = await _testFileChecker.ContainsFileAsync(RepositoryName, + var isFileExists = await _testFileChecker.ContainsFileAsync(repoName, filePath, _giteaCollectionFixture.CancellationToken); isFileExists.Should().BeTrue(); - var doesFileHaveContent = await _testFileChecker.HasFileContent(RepositoryName, + var doesFileHaveContent = await _testFileChecker.HasFileContent(repoName, filePath, expectedContent, _giteaCollectionFixture.CancellationToken); @@ -124,27 +130,28 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndEditFileWithItsContent_ public async Task CreateCommitAsync_ShouldCreateCommitAndDeleteFileWithItsContent_WhenCommitIsForFileDeleting() { // Arrange - const string FileDelete = "SampleDeleteFile.txt"; + const string fileDelete = "SampleDeleteFile.txt"; + const string repoName = $"DeleteFile_{RepositoryName}"; var createCommitCommandDto = new CreateCommitCommandDto { - RepositoryName = RepositoryName, + RepositoryName = repoName, BranchName = "main", CommitMessage = "some trivial commit", FileDtos = [ new FileCommitDto { - Path = FileDelete, + Path = fileDelete, Content = "", CommitActionDto = CommitActionDto.Delete } ] }; - - await _testRepositoryCreator.CreateRepositoryAsync(RepositoryName, _giteaCollectionFixture.CancellationToken); - await _testCommiter.CreateFileAsync(RepositoryName, + + await _testRepositoryCreator.CreateRepositoryAsync(repoName, _giteaCollectionFixture.CancellationToken); + await _testCommiter.CreateFileAsync(repoName, "main", - FileDelete, + fileDelete, "ccc", _giteaCollectionFixture.CancellationToken); @@ -154,13 +161,13 @@ await _testCommiter.CreateFileAsync(RepositoryName, // Assert actual.StatusCode.Should().Be(HttpStatusCode.Created); var commitSha = actual.Content!.CommitResponseDto.Sha; - var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(RepositoryName, + var isCommitCreated= await _testCommitChecker.ContainsCommitWithShaAsync(repoName, "main", commitSha, _giteaCollectionFixture.CancellationToken); isCommitCreated.Should().BeTrue(); - var isFileExists = await _testFileChecker.ContainsFileAsync(RepositoryName, - FileDelete, + var isFileExists = await _testFileChecker.ContainsFileAsync(repoName, + fileDelete, _giteaCollectionFixture.CancellationToken); isFileExists.Should().BeFalse(); }