Skip to content

Commit

Permalink
Hub over-dispose test
Browse files Browse the repository at this point in the history
  • Loading branch information
semuserable committed Jun 3, 2021
1 parent e8e4be1 commit 1ed456b
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions test/Sentry.Tests/HubTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -640,25 +640,39 @@ 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
{
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<ISentryClient, IDisposable>();
var hub = new Hub(client, new SentryOptions
{
Dsn = DsnSamples.ValidDsnWithSecret
});

// Act
hub.Dispose();
hub.Dispose();

// Assert
(client as IDisposable).Received(1).Dispose();
}
}
}

0 comments on commit 1ed456b

Please sign in to comment.