namespace AcDream.Core.Net.Tests; public sealed class SubscriptionSetTests { [Fact] public void Dispose_ReleasesInReverseOrderAndIsIdempotent() { var order = new List(); 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(); 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( subscriptions.Dispose); Assert.Equal([3, 2, 1], order); Assert.Collection( error.InnerExceptions, exception => Assert.IsType(exception), exception => Assert.IsType(exception)); subscriptions.Dispose(); } }