public void Test_Event_IsPopulated() { using (ShimsContext.Create()) { var tEvent = new TestTelemetryEvent(); var now = DateTime.Now; ShimDateTime.NowGet = () => now; var correlationSet = false; ShimTelemetryExtensions.SetCorrelationITelemetryBbTelemetryEvent = (t, e) => { if (e == tEvent) { correlationSet = true; } }; var result = tEvent.ToTelemetry(); result.Should().NotBeNull(); correlationSet.Should().BeTrue(); (result?.Name).Should().Be(tEvent.GetType().Name); (result?.Timestamp).Should().Be(now); (result?.Properties[nameof(TestExceptionEvent.Id)]).Should().Be(tEvent.Id.ToString()); (result?.Properties[nameof(TestExceptionEvent.Description)]).Should().Be(tEvent.Description); } }
public void Test_Event_IsPopulated() { var tEvent = new TestTelemetryEvent(); var now = DateTime.Now; var result = new ConvertEvent <TelemetryEvent, EventTelemetry>(tEvent) { Now = () => now }.ToTelemetry(); result.Should().NotBeNull(); (result?.Name).Should().Be(tEvent.GetType().Name); (result?.Timestamp).Should().Be(now); (result?.Properties[nameof(TestExceptionEvent.Id)]).Should().Be(tEvent.Id.ToString()); (result?.Properties[nameof(TestExceptionEvent.Description)]).Should().Be(tEvent.Description); }
public async Task Test_PublishWithoutCorrelation() { var bbMock = new Mock <BigBrother> { CallBase = true }; var tEvent = new TestTelemetryEvent(); TestTelemetryEvent rEvent = null; using (bbMock.Object.TelemetryStream.OfType <TestTelemetryEvent>().Subscribe(e => rEvent = e)) { bbMock.Object.Publish(tEvent); await Task.Delay(TimeSpan.FromSeconds(1)); // wait a bit to ensure the subscription gets love rEvent.Should().NotBeNull(); rEvent.Should().Be(tEvent); } }
public async Task Test_Internal_IsSubscribed() { var e = new TestTelemetryEvent(); var bbMock = new Mock <BigBrother> { CallBase = true }; bbMock.Setup(x => x.HandleInternalEvent(It.IsAny <TelemetryEvent>())).Verifiable(); bbMock.Object.SetupSubscriptions(); BigBrother.InternalStream.OnNext(e); await Task.Delay(TimeSpan.FromSeconds(1)); // give the subscription some love bbMock.Verify(x => x.HandleInternalEvent(e), Times.Once); // wipe all internal subscriptions BigBrotherExtensions.WipeInternalSubscriptions(); }
public void Test_Event_PublishesOnException() { using (ShimsContext.Create()) { var exception = new Exception("Exploding the test here"); var tEvent = new TestTelemetryEvent(); ShimTelemetryExtensions.SetCorrelationITelemetryBbTelemetryEvent = (t, e) => throw exception; using (BigBrother.InternalStream.OfType <BbExceptionEvent>() .Subscribe(e => { e.Exception.Should().Be(exception); })) { var result = tEvent.ToTelemetry(); result.Should().BeNull(); } } }
public async Task Ensure_LoseOverridesStrictCorrelation() { var bbMock = new Mock <BigBrother> { CallBase = true }; var handle = new object(); var tEvent = new TestTelemetryEvent(); TestTelemetryEvent rEvent = null; using (bbMock.Object.CreateCorrelation()) using (bbMock.Object.TelemetryStream.OfType <TestTelemetryEvent>().Subscribe(e => rEvent = e)) { bbMock.Object.Publish(tEvent, handle); await Task.Delay(TimeSpan.FromSeconds(1)); // wait a bit to ensure the subscription gets love rEvent.Should().NotBeNull(); rEvent.Should().Be(tEvent); rEvent.CorrelationVector.Should().Be(bbMock.Object.CorrelationHandles[handle].Vector); bbMock.Object.Handle.Should().NotBeNull(); } }