mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-06 16:16:44 +08:00
test(core-tests): 简化异步断言包装
- 简化 Architecture、Command、Query 与 AsyncArchitecture 测试中的机械型 async/await 异步断言包装 - 更新 AsyncKeyLockManagerTests 中的 Task 断言写法以消除低风险 analyzer 噪音
This commit is contained in:
parent
9b20a07c0a
commit
67c9359fd2
@ -99,10 +99,10 @@ public class ArchitectureLifecycleBehaviorTests
|
||||
{
|
||||
var architecture = new PhaseTrackingArchitecture(() => throw new InvalidOperationException("boom"));
|
||||
|
||||
var exception = Assert.ThrowsAsync<InvalidOperationException>(async () => await architecture.InitializeAsync());
|
||||
var exception = Assert.ThrowsAsync<InvalidOperationException>(() => architecture.InitializeAsync());
|
||||
Assert.That(exception, Is.Not.Null);
|
||||
Assert.That(architecture.CurrentPhase, Is.EqualTo(ArchitecturePhase.FailedInitialization));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await architecture.WaitUntilReadyAsync());
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => architecture.WaitUntilReadyAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -139,7 +139,7 @@ public class ArchitectureLifecycleBehaviorTests
|
||||
var destroyOrder = new List<string>();
|
||||
var architecture = new FailingInitializationArchitecture(destroyOrder);
|
||||
|
||||
var exception = Assert.ThrowsAsync<InvalidOperationException>(async () => await architecture.InitializeAsync());
|
||||
var exception = Assert.ThrowsAsync<InvalidOperationException>(() => architecture.InitializeAsync());
|
||||
Assert.That(exception, Is.Not.Null);
|
||||
Assert.That(architecture.CurrentPhase, Is.EqualTo(ArchitecturePhase.FailedInitialization));
|
||||
|
||||
|
||||
@ -110,7 +110,7 @@ public class AbstractAsyncCommandTests
|
||||
var command = new TestAsyncCommandWithExceptionV3(input);
|
||||
var asyncCommand = (IAsyncCommand)command;
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await asyncCommand.ExecuteAsync());
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => asyncCommand.ExecuteAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -94,7 +94,7 @@ public class CommandExecutorTests
|
||||
[Test]
|
||||
public void SendAsync_WithNullCommand_Should_ThrowArgumentNullException()
|
||||
{
|
||||
Assert.ThrowsAsync<ArgumentNullException>(async () => await _commandExecutor.SendAsync(null!));
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => _commandExecutor.SendAsync(null!));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -118,7 +118,7 @@ public class CommandExecutorTests
|
||||
[Test]
|
||||
public void SendAsync_WithResult_AndNullCommand_Should_ThrowArgumentNullException()
|
||||
{
|
||||
Assert.ThrowsAsync<ArgumentNullException>(async () => await _commandExecutor.SendAsync<int>(null!));
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => _commandExecutor.SendAsync<int>(null!));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -123,7 +123,7 @@ public sealed class AsyncKeyLockManagerTests
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotThrowAsync(async () => await Task.WhenAll(tasks));
|
||||
Assert.DoesNotThrowAsync(() => Task.WhenAll(tasks));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -243,7 +243,7 @@ public sealed class AsyncKeyLockManagerTests
|
||||
manager.Dispose();
|
||||
|
||||
// Act & Assert
|
||||
Assert.ThrowsAsync<ObjectDisposedException>(async () => await manager.AcquireLockAsync("test-key"));
|
||||
Assert.ThrowsAsync<ObjectDisposedException>(() => manager.AcquireLockAsync("test-key").AsTask());
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -302,7 +302,7 @@ public sealed class AsyncKeyLockManagerTests
|
||||
}
|
||||
|
||||
// Assert
|
||||
Assert.DoesNotThrowAsync(async () => await Task.WhenAll(tasks));
|
||||
Assert.DoesNotThrowAsync(() => Task.WhenAll(tasks));
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -334,4 +334,4 @@ public sealed class AsyncKeyLockManagerTests
|
||||
// Assert - 不应该抛出异常
|
||||
Assert.Pass();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class AbstractAsyncQueryTests
|
||||
var query = new TestAsyncQueryWithExceptionV4(input);
|
||||
var asyncQuery = (IAsyncQuery<int>)query;
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await asyncQuery.DoAsync());
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => asyncQuery.DoAsync());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -44,7 +44,7 @@ public class AsyncQueryExecutorTests
|
||||
[Test]
|
||||
public void SendAsync_WithNullQuery_Should_ThrowArgumentNullException()
|
||||
{
|
||||
Assert.ThrowsAsync<ArgumentNullException>(async () => await _asyncQueryExecutor.SendAsync<int>(null!));
|
||||
Assert.ThrowsAsync<ArgumentNullException>(() => _asyncQueryExecutor.SendAsync<int>(null!));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -100,7 +100,7 @@ public class AsyncQueryExecutorTests
|
||||
var input = new TestAsyncQueryInput { Value = 0 };
|
||||
var query = new TestAsyncQueryWithException(input);
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await _asyncQueryExecutor.SendAsync(query));
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => _asyncQueryExecutor.SendAsync(query));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -93,7 +93,7 @@ public class AsyncArchitectureTests : ArchitectureTestsBase<AsyncTestArchitectur
|
||||
{
|
||||
Architecture!.AddPostRegistrationHook(a => { a.RegisterModel(new FailingModel()); });
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await Architecture.InitializeAsync());
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => Architecture.InitializeAsync());
|
||||
|
||||
Assert.That(
|
||||
Architecture.CurrentPhase,
|
||||
@ -140,8 +140,8 @@ public class AsyncArchitectureTests : ArchitectureTestsBase<AsyncTestArchitectur
|
||||
a.RegisterModel(new FailingModel())
|
||||
);
|
||||
|
||||
Assert.ThrowsAsync<InvalidOperationException>(async () => await Architecture.InitializeAsync());
|
||||
Assert.ThrowsAsync<InvalidOperationException>(() => Architecture.InitializeAsync());
|
||||
|
||||
AssertInitializationFailed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user