|
| 1 | +namespace Sentry.Tests.Internals; |
| 2 | + |
| 3 | +public class UnsampledTransactionTests |
| 4 | +{ |
| 5 | + [Fact] |
| 6 | + public void StartChild_CreatesSpan_IsTrackedByParent() |
| 7 | + { |
| 8 | + // Arrange |
| 9 | + var hub = Substitute.For<IHub>(); |
| 10 | + ITransactionContext context = new TransactionContext("TestTransaction", "TestOperation", |
| 11 | + new SentryTraceHeader(SentryId.Create(), SpanId.Create(), false) |
| 12 | + ); |
| 13 | + using var transaction = new UnsampledTransaction(hub, context); |
| 14 | + |
| 15 | + // Act |
| 16 | + using var unsampledSpan = transaction.StartChild("Foo"); |
| 17 | + |
| 18 | + // Assert |
| 19 | + var span = Assert.Single(transaction.Spans); |
| 20 | + Assert.Same(unsampledSpan, span); |
| 21 | + } |
| 22 | + |
| 23 | + [Fact] |
| 24 | + public void Finish_WithTrackedSpans_ClearsTrackedSpans() |
| 25 | + { |
| 26 | + // Arrange |
| 27 | + var hub = Substitute.For<IHub>(); |
| 28 | + ITransactionContext context = new TransactionContext("TestTransaction", "TestOperation", |
| 29 | + new SentryTraceHeader(SentryId.Create(), SpanId.Create(), false) |
| 30 | + ); |
| 31 | + var transaction = new UnsampledTransaction(hub, context); |
| 32 | + _ = transaction.StartChild("Foo"); |
| 33 | + |
| 34 | + // Act |
| 35 | + transaction.Finish(); |
| 36 | + |
| 37 | + // Assert |
| 38 | + Assert.Empty(transaction.Spans); |
| 39 | + } |
| 40 | + |
| 41 | + [Fact] |
| 42 | + public void Dispose_WithTrackedSpans_ClearsTrackedSpans() |
| 43 | + { |
| 44 | + // Arrange |
| 45 | + var hub = Substitute.For<IHub>(); |
| 46 | + ITransactionContext context = new TransactionContext("TestTransaction", "TestOperation", |
| 47 | + new SentryTraceHeader(SentryId.Create(), SpanId.Create(), false) |
| 48 | + ); |
| 49 | + var transaction = new UnsampledTransaction(hub, context); |
| 50 | + _ = transaction.StartChild("Foo"); |
| 51 | + |
| 52 | + // Act |
| 53 | + transaction.Dispose(); |
| 54 | + |
| 55 | + // Assert |
| 56 | + Assert.Empty(transaction.Spans); |
| 57 | + } |
| 58 | +} |
0 commit comments