Skip to content

Commit

Permalink
Improve unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanGreve committed Aug 30, 2024
1 parent 5666c7f commit de1a34c
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions AdvancedSystems.Core.Tests/Services/CachingServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public CachingServiceTests(CachingServiceFixture fixture)
public async Task TestCachingRoundtrip_HappyPath()
{
// Arrange
this._fixture.DistributedCache.Invocations.Clear();
string key = "test";
var expected = new Person("Stefan", "Greve");
var options = new CacheOptions
Expand All @@ -49,13 +50,14 @@ public async Task TestCachingRoundtrip_HappyPath()
Assert.NotNull(actual);
Assert.Equal(expected.FirstName, actual?.FirstName);
Assert.Equal(expected.LastName, actual?.LastName);
this._fixture.DistributedCache.Verify(service => service.SetAsync(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<DistributedCacheEntryOptions>(), It.IsAny<CancellationToken>()), Times.AtLeastOnce());
this._fixture.DistributedCache.Verify(service => service.SetAsync(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<DistributedCacheEntryOptions>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
public async Task TestCachingRoundtrip_UnhappyPath()
{
// Arrange
this._fixture.DistributedCache.Invocations.Clear();
var expected = new Person("Stefan", "Greve");

// Act
Expand All @@ -64,7 +66,7 @@ public async Task TestCachingRoundtrip_UnhappyPath()

// Assert
Assert.Null(actual);
this._fixture.DistributedCache.Verify(service => service.SetAsync(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<DistributedCacheEntryOptions>(), It.IsAny<CancellationToken>()), Times.AtLeastOnce());
this._fixture.DistributedCache.Verify(service => service.SetAsync(It.IsAny<string>(), It.IsAny<byte[]>(), It.IsAny<DistributedCacheEntryOptions>(), It.IsAny<CancellationToken>()), Times.Once);
}

[Fact]
Expand Down

0 comments on commit de1a34c

Please sign in to comment.