From 1ed456bc189c2fc657b95f94fda44e17a3906c04 Mon Sep 17 00:00:00 2001 From: semuserable Date: Thu, 3 Jun 2021 11:45:18 +0300 Subject: [PATCH] Hub over-dispose test --- test/Sentry.Tests/HubTests.cs | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/test/Sentry.Tests/HubTests.cs b/test/Sentry.Tests/HubTests.cs index 9062b90c9b..b456f4838e 100644 --- a/test/Sentry.Tests/HubTests.cs +++ b/test/Sentry.Tests/HubTests.cs @@ -640,10 +640,8 @@ public void CaptureTransaction_AfterTransactionFinishes_ResetsTransactionOnScope hub.WithScope(scope => scope.Transaction.Should().BeNull()); } - [Theory] - [InlineData(1)] - [InlineData(2)] - public void Dispose_IsEnabled_SetToFalse(int disposeCount) + [Fact] + public void Dispose_IsEnabled_SetToFalse() { // Arrange var hub = new Hub(new SentryOptions @@ -651,14 +649,30 @@ public void Dispose_IsEnabled_SetToFalse(int disposeCount) Dsn = DsnSamples.ValidDsnWithSecret }); + hub.IsEnabled.Should().BeTrue(); + // Act - for (var i = 0; i < disposeCount; i++) - { - hub.Dispose(); - } + hub.Dispose(); // Assert hub.IsEnabled.Should().BeFalse(); } + + [Fact] + public void Dispose_CalledSecondTime_ClientDisposedOnce() + { + var client = Substitute.For(); + var hub = new Hub(client, new SentryOptions + { + Dsn = DsnSamples.ValidDsnWithSecret + }); + + // Act + hub.Dispose(); + hub.Dispose(); + + // Assert + (client as IDisposable).Received(1).Dispose(); + } } }