refactor(net): own session wiring subscriptions
This commit is contained in:
parent
88fe1db37b
commit
7d452aa6a2
8 changed files with 577 additions and 61 deletions
47
tests/AcDream.Core.Net.Tests/SubscriptionSetTests.cs
Normal file
47
tests/AcDream.Core.Net.Tests/SubscriptionSetTests.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
namespace AcDream.Core.Net.Tests;
|
||||
|
||||
public sealed class SubscriptionSetTests
|
||||
{
|
||||
[Fact]
|
||||
public void Dispose_ReleasesInReverseOrderAndIsIdempotent()
|
||||
{
|
||||
var order = new List<int>();
|
||||
var subscriptions = new SubscriptionSet();
|
||||
subscriptions.Add(() => order.Add(1));
|
||||
subscriptions.Add(() => order.Add(2));
|
||||
subscriptions.Add(() => order.Add(3));
|
||||
|
||||
subscriptions.Dispose();
|
||||
subscriptions.Dispose();
|
||||
|
||||
Assert.Equal([3, 2, 1], order);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Dispose_AttemptsEveryReleaseAndAggregatesFailures()
|
||||
{
|
||||
var order = new List<int>();
|
||||
var subscriptions = new SubscriptionSet();
|
||||
subscriptions.Add(() => order.Add(1));
|
||||
subscriptions.Add(() =>
|
||||
{
|
||||
order.Add(2);
|
||||
throw new InvalidOperationException("second failed");
|
||||
});
|
||||
subscriptions.Add(() =>
|
||||
{
|
||||
order.Add(3);
|
||||
throw new IOException("third failed");
|
||||
});
|
||||
|
||||
AggregateException error = Assert.Throws<AggregateException>(
|
||||
subscriptions.Dispose);
|
||||
|
||||
Assert.Equal([3, 2, 1], order);
|
||||
Assert.Collection(
|
||||
error.InnerExceptions,
|
||||
exception => Assert.IsType<IOException>(exception),
|
||||
exception => Assert.IsType<InvalidOperationException>(exception));
|
||||
subscriptions.Dispose();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue