Skip to content

Commit

Permalink
correct integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Alireza Eiji committed Jul 25, 2024
1 parent a824c7e commit f9a7c21
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -52,23 +53,25 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndAddFileWithItsContent_W
}
]
};

await _testRepositoryCreator.CreateRepositoryAsync(repoName, _giteaCollectionFixture.CancellationToken);

// Act
var actual = await _sut.CommitClient.CreateCommitAsync(createCommitCommandDto, _giteaCollectionFixture.CancellationToken);

// 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);
Expand All @@ -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 =
Expand All @@ -97,23 +101,25 @@ public async Task CreateCommitAsync_ShouldCreateCommitAndEditFileWithItsContent_
}
]
};

await _testRepositoryCreator.CreateRepositoryAsync($"EditFile_{RepositoryName}", _giteaCollectionFixture.CancellationToken);

// Act
var actual = await _sut.CommitClient.CreateCommitAsync(createCommitCommandDto, _giteaCollectionFixture.CancellationToken);

// 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);
Expand All @@ -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);

Expand All @@ -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();
}
Expand Down

0 comments on commit f9a7c21

Please sign in to comment.