diff --git a/test/NuGet.Core.Tests/NuGet.Common.Test/TelemetryActivityTests.cs b/test/NuGet.Core.Tests/NuGet.Common.Test/TelemetryActivityTests.cs index b53ca416e65..c5a871000cb 100644 --- a/test/NuGet.Core.Tests/NuGet.Common.Test/TelemetryActivityTests.cs +++ b/test/NuGet.Core.Tests/NuGet.Common.Test/TelemetryActivityTests.cs @@ -13,14 +13,25 @@ namespace NuGet.Common.Test { public class TelemetryActivityTests { - private readonly Mock _telemetryService = new Mock(); + private readonly Mock _telemetryService = new Mock(MockBehavior.Strict); private TelemetryEvent _telemetryEvent; + private readonly Mock _activity = new Mock(MockBehavior.Strict); + private bool _activityDisposed; + private string _activityName; + public TelemetryActivityTests() { _telemetryService.Setup(x => x.EmitTelemetryEvent(It.IsAny())) .Callback(x => _telemetryEvent = x); + _telemetryService.Setup(x => x.StartActivity(It.IsAny())) + .Callback(x => _activityName = x) + .Returns(_activity.Object); + + _activity.Setup(x => x.Dispose()) + .Callback(() => _activityDisposed = true); + TelemetryActivity.NuGetTelemetryService = _telemetryService.Object; } @@ -125,6 +136,26 @@ public void Dispose_Always_EmitsDuration() Assert.InRange(duration, 0d, 10d); } + [Fact] + public void Create_will_start_activity() + { + using (var telemetry = TelemetryActivity.Create(CreateNewTelemetryEvent())) + { + } + + Assert.Equal("testEvent", _activityName); + } + + [Fact] + public void Dispose_will_dispose_activity() + { + using (var telemetry = TelemetryActivity.Create(CreateNewTelemetryEvent())) + { + } + + Assert.True(_activityDisposed); + } + private static TelemetryEvent CreateNewTelemetryEvent() { return new TelemetryEvent("testEvent", new Dictionary());