-
Notifications
You must be signed in to change notification settings - Fork 0
fix: ArchiveAsync returns true for already-archived issues (MatchedCount vs ModifiedCount) #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,86 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| using Shared.Domain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace IssueManager.Tests.Integration.Handlers; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Integration tests for IssueRepository.ArchiveAsync (soft-delete). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Verifies correct behavior when archiving existing, already-archived, and non-existent issues. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public class DeleteIssueHandlerTests : IAsyncLifetime | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private const string MONGODB_IMAGE = "mongo:8.0"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private const string TEST_DATABASE = "IssueManagerTestDb"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private readonly MongoDbContainer _mongoContainer; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private IIssueRepository _repository = null!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public DeleteIssueHandlerTests() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _mongoContainer = new MongoDbBuilder() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .WithImage(MONGODB_IMAGE) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .Build(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Initializes the test container and repository. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task InitializeAsync() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _mongoContainer.StartAsync(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var connectionString = _mongoContainer.GetConnectionString(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| _repository = new IssueRepository(connectionString, TEST_DATABASE); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Disposes the test container. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// </summary> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task DisposeAsync() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _mongoContainer.StopAsync(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _mongoContainer.DisposeAsync(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task ArchiveAsync_ExistingUnarchivedIssue_ReturnsTrue() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var issue = Issue.Create("Test Issue", "Test Description"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _repository.CreateAsync(issue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var result = await _repository.ArchiveAsync(issue.Id, "testuser"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.Should().BeTrue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var retrieved = await _repository.GetByIdAsync(issue.Id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retrieved!.IsArchived.Should().BeTrue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retrieved.ArchivedBy.Should().Be("testuser"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| retrieved.ArchivedAt.Should().NotBeNull(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [Fact] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task ArchiveAsync_AlreadyArchivedIssue_ReturnsTrueIdempotent() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Arrange | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var issue = Issue.Create("Already Archived Issue", "Description"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _repository.CreateAsync(issue); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| await _repository.ArchiveAsync(issue.Id, "firstuser"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Act - archive again (already archived, ModifiedCount will be 0) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var result = await _repository.ArchiveAsync(issue.Id, "seconduser"); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Assert - should return true (issue was found), not false (issue not found) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result.Should().BeTrue(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+63
to
+74
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public async Task ArchiveAsync_AlreadyArchivedIssue_ReturnsTrueIdempotent() | |
| { | |
| // Arrange | |
| var issue = Issue.Create("Already Archived Issue", "Description"); | |
| await _repository.CreateAsync(issue); | |
| await _repository.ArchiveAsync(issue.Id, "firstuser"); | |
| // Act - archive again (already archived, ModifiedCount will be 0) | |
| var result = await _repository.ArchiveAsync(issue.Id, "seconduser"); | |
| // Assert - should return true (issue was found), not false (issue not found) | |
| result.Should().BeTrue(); | |
| public async Task ArchiveAsync_AlreadyArchivedIssue_RearchivesAndReturnsTrue() | |
| { | |
| // Arrange | |
| var issue = Issue.Create("Already Archived Issue", "Description"); | |
| await _repository.CreateAsync(issue); | |
| await _repository.ArchiveAsync(issue.Id, "firstuser"); | |
| // Act - archive again (already archived; repository updates metadata) | |
| var result = await _repository.ArchiveAsync(issue.Id, "seconduser"); | |
| // Assert - should return true (issue was found) and reflect latest archive metadata | |
| result.Should().BeTrue(); | |
| var retrieved = await _repository.GetByIdAsync(issue.Id); | |
| retrieved!.IsArchived.Should().BeTrue(); | |
| retrieved.ArchivedBy.Should().Be("seconduser"); | |
| retrieved.ArchivedAt.Should().NotBeNull(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The class/file name suggests these are tests for a delete handler, but the tests (and XML summary) exercise
IssueRepository.ArchiveAsyncdirectly and never instantiate/callDeleteIssueHandler. Renaming/moving this test to match what it covers will make test intent and failures easier to understand (e.g., anIssueRepositoryArchiveAsyncTests-style name and/or placement under a repository/data test folder).