Skip to content

Commit

Permalink
Upgrade JetBrains tooling and resolve new warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tjementum committed Jan 25, 2025
1 parent 21810c8 commit 4628b11
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
2 changes: 1 addition & 1 deletion application/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"commands": ["dotnet-dotcover"]
},
"jetbrains.resharper.globaltools": {
"version": "2024.3.0",
"version": "2024.3.4",
"commands": ["jb"]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public async Task Handle_WhenCalled_ShouldPublishDomainEvents()
publisher
);
var request = new TestCommand();
var cancellationToken = new CancellationToken();
var next = Substitute.For<RequestHandlerDelegate<Result<TestAggregate>>>();
next.Invoke().Returns(TestAggregate.Create("Test"));

Expand All @@ -32,10 +31,10 @@ public async Task Handle_WhenCalled_ShouldPublishDomainEvents()
);

// Act
await behavior.Handle(request, next, cancellationToken);
await behavior.Handle(request, next, CancellationToken.None);

// Assert
await publisher.Received(1).Publish(domainEvent, cancellationToken);
await publisher.Received(1).Publish(domainEvent, CancellationToken.None);
testAggregate.DomainEvents.Should().BeEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,19 @@ public async Task Handle_WhenSuccessfulCommand_ShouldCallNextAndCommitChanges()
{
// Arrange
var command = new TestCommand();
var cancellationToken = new CancellationToken();
var next = Substitute.For<RequestHandlerDelegate<Result<TestAggregate>>>();
var successfulCommandResult = Result<TestAggregate>.Success(TestAggregate.Create("Foo"));
next.Invoke().Returns(Task.FromResult(successfulCommandResult));

// Act
_ = await _behavior.Handle(command, next, cancellationToken);
_ = await _behavior.Handle(command, next, CancellationToken.None);

// Assert
await _unitOfWork.Received().CommitAsync(cancellationToken);
await _unitOfWork.Received().CommitAsync(CancellationToken.None);
Received.InOrder(() =>
{
next.Invoke();
_unitOfWork.CommitAsync(cancellationToken);
_unitOfWork.CommitAsync(CancellationToken.None);
}
);
}
Expand All @@ -52,16 +51,15 @@ public async Task Handle_WhenNonSuccessfulCommand_ShouldCallNextButNotCommitChan
{
// Arrange
var command = new TestCommand();
var cancellationToken = new CancellationToken();
var next = Substitute.For<RequestHandlerDelegate<Result<TestAggregate>>>();
var successfulCommandResult = Result<TestAggregate>.BadRequest("Fail");
next.Invoke().Returns(Task.FromResult(successfulCommandResult));

// Act
_ = await _behavior.Handle(command, next, cancellationToken);
_ = await _behavior.Handle(command, next, CancellationToken.None);

// Assert
await _unitOfWork.DidNotReceive().CommitAsync(cancellationToken);
await _unitOfWork.DidNotReceive().CommitAsync(CancellationToken.None);
await next.Received().Invoke();
}
}
18 changes: 8 additions & 10 deletions application/shared-kernel/Tests/Persistence/RepositoryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,13 @@ public async Task Add_WhenNewAggregate_ShouldAddToDatabase()
{
// Arrange
var testAggregate = TestAggregate.Create("TestAggregate");
var cancellationToken = new CancellationToken();

// Act
await _testAggregateRepository.AddAsync(testAggregate, cancellationToken);
await _testDbContext.SaveChangesAsync(cancellationToken);
await _testAggregateRepository.AddAsync(testAggregate, CancellationToken.None);
await _testDbContext.SaveChangesAsync(CancellationToken.None);

// Assert
var retrievedAggregate = await _testAggregateRepository.GetByIdAsync(testAggregate.Id, cancellationToken);
var retrievedAggregate = await _testAggregateRepository.GetByIdAsync(testAggregate.Id, CancellationToken.None);
retrievedAggregate.Should().NotBeNull();
retrievedAggregate!.Id.Should().Be(testAggregate.Id);
}
Expand Down Expand Up @@ -136,26 +135,25 @@ public async Task Update_WhenEntityIsModifiedByAnotherUser_ShouldThrowConcurrenc
// Arrange
var primaryRepository = new TestAggregateRepository(_testDbContext);
var originalTestAggregate = TestAggregate.Create("TestAggregate");
var cancellationToken = new CancellationToken();
await primaryRepository.AddAsync(originalTestAggregate, cancellationToken);
await _testDbContext.SaveChangesAsync(cancellationToken);
await primaryRepository.AddAsync(originalTestAggregate, CancellationToken.None);
await _testDbContext.SaveChangesAsync(CancellationToken.None);

// Simulate another user by creating a new DbContext and repository instance
var secondaryDbContext = _sqliteInMemoryDbContextFactory.CreateContext();
var secondaryRepository = new TestAggregateRepository(secondaryDbContext);

// Act
var concurrentTestAggregate =
(await secondaryRepository.GetByIdAsync(originalTestAggregate.Id, cancellationToken))!;
(await secondaryRepository.GetByIdAsync(originalTestAggregate.Id, CancellationToken.None))!;
concurrentTestAggregate.Name = "UpdatedTestAggregateByAnotherUser";
secondaryRepository.Update(concurrentTestAggregate);
await secondaryDbContext.SaveChangesAsync(cancellationToken);
await secondaryDbContext.SaveChangesAsync(CancellationToken.None);

originalTestAggregate.Name = "UpdatedTestAggregate";
primaryRepository.Update(originalTestAggregate);

// Assert
await Assert.ThrowsAsync<DbUpdateConcurrencyException>(() => _testDbContext.SaveChangesAsync(cancellationToken));
await Assert.ThrowsAsync<DbUpdateConcurrencyException>(() => _testDbContext.SaveChangesAsync(CancellationToken.None));
}

[Fact]
Expand Down

0 comments on commit 4628b11

Please sign in to comment.