Skip to content

Commit deee040

Browse files
committed
Add descriptive DisplayName attributes to unit tests for improved test clarity.
1 parent 9ba73b7 commit deee040

4 files changed

Lines changed: 26 additions & 26 deletions

File tree

test/unit/Elsa.Resilience.Core.UnitTests/DefaultTransientExceptionStrategyTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,31 +42,31 @@ public class DefaultTransientExceptionStrategyTests
4242
"Null reference"
4343
];
4444

45-
[Theory]
45+
[Theory(DisplayName = "Known transient exception types should be detected as transient")]
4646
[MemberData(nameof(TransientExceptionTypes))]
4747
public void IsTransient_KnownTransientExceptionType_ReturnsTrue(Type exceptionType)
4848
{
4949
var exception = (Exception)Activator.CreateInstance(exceptionType)!;
5050
Assert.True(_strategy.IsTransient(exception));
5151
}
5252

53-
[Theory]
53+
[Theory(DisplayName = "Exceptions with transient message patterns should be detected as transient")]
5454
[MemberData(nameof(TransientMessagePatterns))]
5555
public void IsTransient_ExceptionWithTransientMessagePattern_ReturnsTrue(string message)
5656
{
5757
var exception = new Exception(message);
5858
Assert.True(_strategy.IsTransient(exception));
5959
}
6060

61-
[Theory]
61+
[Theory(DisplayName = "Exceptions with non-transient messages should not be detected as transient")]
6262
[MemberData(nameof(NonTransientMessagePatterns))]
6363
public void IsTransient_ExceptionWithNonTransientMessage_ReturnsFalse(string message)
6464
{
6565
var exception = new Exception(message);
6666
Assert.False(_strategy.IsTransient(exception));
6767
}
6868

69-
[Theory]
69+
[Theory(DisplayName = "Non-transient exception types should not be detected as transient regardless of message")]
7070
[InlineData(typeof(InvalidOperationException), "Some error")]
7171
[InlineData(typeof(ArgumentException), "Invalid argument")]
7272
[InlineData(typeof(NullReferenceException), "Object reference not set")]
@@ -76,7 +76,7 @@ public void IsTransient_NonTransientExceptionType_ReturnsFalse(Type exceptionTyp
7676
Assert.False(_strategy.IsTransient(exception));
7777
}
7878

79-
[Theory]
79+
[Theory(DisplayName = "Exceptions with empty messages should be detected based on type only")]
8080
[InlineData(typeof(TimeoutException), true)]
8181
[InlineData(typeof(InvalidOperationException), false)]
8282
public void IsTransient_ExceptionWithEmptyMessage_ChecksTypeOnly(Type exceptionType, bool expectedResult)

test/unit/Elsa.Resilience.Core.UnitTests/ResilienceStrategyCatalogTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class ResilienceStrategyCatalogTests
88
{
99
private static ResilienceStrategyCatalog CreateCatalog(params IResilienceStrategySource[] sources) => new(sources);
1010

11-
[Fact]
11+
[Fact(DisplayName = "Catalog with no sources should return empty list")]
1212
public async Task ListAsync_NoProviders_ReturnsEmptyList()
1313
{
1414
var catalog = CreateCatalog();
@@ -17,7 +17,7 @@ public async Task ListAsync_NoProviders_ReturnsEmptyList()
1717
Assert.Empty(result);
1818
}
1919

20-
[Fact]
20+
[Fact(DisplayName = "Catalog should return all strategies from a single source")]
2121
public async Task ListAsync_SingleProviderWithStrategies_ReturnsStrategies()
2222
{
2323
var strategies = new[]
@@ -35,7 +35,7 @@ public async Task ListAsync_SingleProviderWithStrategies_ReturnsStrategies()
3535
s => Assert.Equal("strategy2", s.Id));
3636
}
3737

38-
[Fact]
38+
[Fact(DisplayName = "Catalog should combine strategies from multiple sources")]
3939
public async Task ListAsync_MultipleProviders_CombinesAllStrategies()
4040
{
4141
var provider1 = TestDataFactory.CreateStrategySource(
@@ -53,7 +53,7 @@ public async Task ListAsync_MultipleProviders_CombinesAllStrategies()
5353
Assert.Contains(result, s => s.Id == "strategy3");
5454
}
5555

56-
[Theory]
56+
[Theory(DisplayName = "Catalog should retrieve strategy by ID or return null if not found")]
5757
[InlineData("test-id", "Test Strategy", true)]
5858
[InlineData("non-existent", null, false)]
5959
public async Task GetAsync_WithStrategyId_ReturnsExpectedResult(string searchId, string? expectedDisplayName, bool shouldExist)
@@ -76,7 +76,7 @@ public async Task GetAsync_WithStrategyId_ReturnsExpectedResult(string searchId,
7676
}
7777
}
7878

79-
[Fact]
79+
[Fact(DisplayName = "Catalog should search all sources to find a strategy")]
8080
public async Task GetAsync_MultipleProvidersStrategyInSecond_ReturnsStrategy()
8181
{
8282
var provider1 = TestDataFactory.CreateStrategySource(
@@ -91,7 +91,7 @@ public async Task GetAsync_MultipleProvidersStrategyInSecond_ReturnsStrategy()
9191
Assert.Equal("strategy2", result.Id);
9292
}
9393

94-
[Fact]
94+
[Fact(DisplayName = "Catalog should cache strategy list after first retrieval")]
9595
public async Task ListAsync_CalledMultipleTimes_CachesResult()
9696
{
9797
var strategy = TestDataFactory.CreateStrategy("test", "Test");
@@ -105,7 +105,7 @@ public async Task ListAsync_CalledMultipleTimes_CachesResult()
105105
await provider.Received(1).GetStrategiesAsync(Arg.Any<CancellationToken>());
106106
}
107107

108-
[Fact]
108+
[Fact(DisplayName = "GetAsync should use cached list when available")]
109109
public async Task GetAsync_CalledAfterList_UsesCachedResult()
110110
{
111111
var strategy = TestDataFactory.CreateStrategy("test", "Test");

test/unit/Elsa.Resilience.Core.UnitTests/ResilienceStrategyConfigEvaluatorTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ public ResilienceStrategyConfigEvaluatorTests()
2222
_evaluator = new(_catalog, _expressionEvaluator, serializer);
2323
}
2424

25-
[Fact]
25+
[Fact(DisplayName = "Evaluator should return null when config is null")]
2626
public async Task EvaluateAsync_NullConfig_ReturnsNull()
2727
{
2828
var result = await _evaluator.EvaluateAsync(null, _context);
2929
Assert.Null(result);
3030
}
3131

32-
[Fact]
32+
[Fact(DisplayName = "Evaluator in identifier mode should resolve strategy from catalog")]
3333
public async Task EvaluateAsync_IdentifierMode_WithValidId_ReturnsStrategyFromCatalog()
3434
{
3535
var strategy = TestDataFactory.CreateStrategy("test-strategy", "Test Strategy");
@@ -43,7 +43,7 @@ public async Task EvaluateAsync_IdentifierMode_WithValidId_ReturnsStrategyFromCa
4343
await _catalog.Received(1).GetAsync("test-strategy", Arg.Any<CancellationToken>());
4444
}
4545

46-
[Theory]
46+
[Theory(DisplayName = "Evaluator in identifier mode should return null for invalid strategy IDs")]
4747
[InlineData("")]
4848
[InlineData(" ")]
4949
[InlineData(null)]
@@ -57,7 +57,7 @@ public async Task EvaluateAsync_IdentifierMode_WithInvalidId_ReturnsNull(string?
5757
await _catalog.DidNotReceive().GetAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
5858
}
5959

60-
[Fact]
60+
[Fact(DisplayName = "Evaluator in expression mode should return null when expression is null")]
6161
public async Task EvaluateAsync_ExpressionMode_WithNullExpression_ReturnsNull()
6262
{
6363
var config = CreateConfig(ResilienceStrategyConfigMode.Expression);
@@ -68,7 +68,7 @@ public async Task EvaluateAsync_ExpressionMode_WithNullExpression_ReturnsNull()
6868
await _expressionEvaluator.DidNotReceive().EvaluateAsync<object>(Arg.Any<Expression>(), Arg.Any<ExpressionExecutionContext>(), Arg.Any<ExpressionEvaluatorOptions>());
6969
}
7070

71-
[Fact]
71+
[Fact(DisplayName = "Evaluator in expression mode should resolve string IDs from catalog")]
7272
public async Task EvaluateAsync_ExpressionMode_ReturnsStringId_ResolvesFromCatalog()
7373
{
7474
var expression = new Expression("C#", "\"test-strategy\"");
@@ -84,7 +84,7 @@ public async Task EvaluateAsync_ExpressionMode_ReturnsStringId_ResolvesFromCatal
8484
await _catalog.Received(1).GetAsync("test-strategy", Arg.Any<CancellationToken>());
8585
}
8686

87-
[Fact]
87+
[Fact(DisplayName = "Evaluator in expression mode should return strategy objects directly")]
8888
public async Task EvaluateAsync_ExpressionMode_ReturnsStrategyObject_ReturnsStrategyDirectly()
8989
{
9090
var expression = new Expression("C#", "strategy");
@@ -99,7 +99,7 @@ public async Task EvaluateAsync_ExpressionMode_ReturnsStrategyObject_ReturnsStra
9999
await _catalog.DidNotReceive().GetAsync(Arg.Any<string>(), Arg.Any<CancellationToken>());
100100
}
101101

102-
[Theory]
102+
[Theory(DisplayName = "Evaluator in expression mode should return null for unexpected result types")]
103103
[InlineData("null", null)]
104104
[InlineData("42", 42)]
105105
public async Task EvaluateAsync_ExpressionMode_ReturnsUnexpectedType_ReturnsNull(string expressionCode, object? expressionResult)

test/unit/Elsa.Resilience.Core.UnitTests/TransientExceptionDetectorTests.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ private static ITransientExceptionStrategy CreateDetector(params (Exception exce
1515
private static TransientExceptionDetector CreateService(params ITransientExceptionStrategy[] detectors) =>
1616
new(detectors);
1717

18-
[Fact]
18+
[Fact(DisplayName = "Service with no registered strategies should return false for any exception")]
1919
public void IsTransient_NoDetectors_ReturnsFalse()
2020
{
2121
var service = CreateService();
@@ -24,7 +24,7 @@ public void IsTransient_NoDetectors_ReturnsFalse()
2424
Assert.False(service.IsTransient(exception));
2525
}
2626

27-
[Fact]
27+
[Fact(DisplayName = "Service should return true when any strategy detects the exception as transient")]
2828
public void IsTransient_DetectorReturnsTrue_ReturnsTrue()
2929
{
3030
var exception = new Exception("test");
@@ -34,7 +34,7 @@ public void IsTransient_DetectorReturnsTrue_ReturnsTrue()
3434
Assert.True(service.IsTransient(exception));
3535
}
3636

37-
[Fact]
37+
[Fact(DisplayName = "Service with multiple strategies should return true if any one detects as transient")]
3838
public void IsTransient_MultipleDetectorsOneReturnsTrue_ReturnsTrue()
3939
{
4040
var exception = new Exception("test");
@@ -45,7 +45,7 @@ public void IsTransient_MultipleDetectorsOneReturnsTrue_ReturnsTrue()
4545
Assert.True(service.IsTransient(exception));
4646
}
4747

48-
[Fact]
48+
[Fact(DisplayName = "Service should return false when all strategies detect the exception as non-transient")]
4949
public void IsTransient_AllDetectorsReturnFalse_ReturnsFalse()
5050
{
5151
var exception = new Exception("test");
@@ -58,7 +58,7 @@ public void IsTransient_AllDetectorsReturnFalse_ReturnsFalse()
5858
Assert.False(service.IsTransient(exception));
5959
}
6060

61-
[Theory]
61+
[Theory(DisplayName = "Service should walk the inner exception chain to find transient exceptions")]
6262
[InlineData(1)] // Inner exception is transient
6363
[InlineData(2)] // Deep inner exception is transient
6464
public void IsTransient_InnerExceptionChainHasTransient_ReturnsTrue(int depth)
@@ -79,7 +79,7 @@ public void IsTransient_InnerExceptionChainHasTransient_ReturnsTrue(int depth)
7979
Assert.True(service.IsTransient(exception));
8080
}
8181

82-
[Theory]
82+
[Theory(DisplayName = "Service should inspect AggregateException inner exceptions")]
8383
[InlineData(1, true)] // One transient inner exception
8484
[InlineData(2, false)] // No transient inner exceptions
8585
public void IsTransient_AggregateException_ChecksInnerExceptions(int scenario, bool expectedResult)
@@ -107,7 +107,7 @@ public void IsTransient_AggregateException_ChecksInnerExceptions(int scenario, b
107107
Assert.Equal(expectedResult, service.IsTransient(aggregateException));
108108
}
109109

110-
[Fact]
110+
[Fact(DisplayName = "AggregateException with mixed inner exceptions should be transient if any inner is transient")]
111111
public void IsTransient_AggregateExceptionWithMultipleInnerOneTransient_ReturnsTrue()
112112
{
113113
var transientException = new TimeoutException("timeout");

0 commit comments

Comments
 (0)