Esempio n. 1
0
        public void FlushCanBeAborted()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer))
            {
                SendingInterval = TimeSpan.FromDays(1),
                EndpointAddress = "http://localhost/bad"
            };

            channel.Send(new StubTelemetry()); // Send telemetry so that it sets next send intreval and does not interfere with Flush
            channel.Flush();

            var transmission = new StubTelemetry();

            channel.Send(transmission);

            using (TestEventListener listener = new TestEventListener())
            {
                listener.EnableEvents(CoreEventSource.Log, EventLevel.Warning);
                channel.Flush(TimeSpan.FromTicks(1));

                var expectedMessage = listener.Messages.First();
                Assert.Equal(24, expectedMessage.EventId);
            }
        }
Esempio n. 2
0
        public void FlushCanBeAborted()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel         = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer))
            {
                SendingInterval = TimeSpan.FromDays(1),
                EndpointAddress = "http://localhost/bad"
            };

            var telemetry = new TraceTelemetry("test");

            telemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();
            channel.Send(telemetry); // Send telemetry so that it sets next send interval and does not interfere with Flush
            channel.Flush();

            telemetry = new TraceTelemetry("test");
            telemetry.Context.InstrumentationKey = Guid.NewGuid().ToString();
            channel.Send(telemetry);

            using (TestEventListener listener = new TestEventListener())
            {
                listener.EnableEvents(CoreEventSource.Log, EventLevel.Warning);
                channel.Flush(TimeSpan.FromSeconds(1));

                var expectedMessage = listener.Messages.First();
                Assert.AreEqual(24, expectedMessage.EventId);
            }
        }