public void InitializePreservesExistingSequencePropertyValue()
 {
     string originalValue = Guid.NewGuid().ToString();
     var telemetry = new StubTelemetry { Sequence = originalValue };
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.Equal(originalValue, telemetry.Sequence);
 }
 public void InitializeSetsTimestampPropertyOfGivenTelemetry()
 {
     var initializer = new TimestampPropertyInitializer();
     var telemetry = new StubTelemetry();
     initializer.Initialize(telemetry);
     Assert.True(DateTimeOffset.Now.Subtract(telemetry.Timestamp) < TimeSpan.FromMinutes(1));
 }
 public void InitializeDoesNotOverrideTimestampSpecifiedExplicitly()
 {
     var initializer = new TimestampPropertyInitializer();
     var expected = new DateTimeOffset(new DateTime(42));
     var telemetry = new StubTelemetry { Timestamp = expected };
     initializer.Initialize(telemetry);
     Assert.Equal(expected, telemetry.Timestamp);
 }
        public void InitializeGeneratesUniqueValuesWhenCalledOnMultipleInstances()
        {
            var telemetry1 = new StubTelemetry();
            new SequencePropertyInitializer().Initialize(telemetry1);

            var telemetry2 = new StubTelemetry();
            new SequencePropertyInitializer().Initialize(telemetry2);

            Assert.NotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
        public void InitializeGeneratesUniqueSequenceValuesWhenCalledMultipleTimes()
        {
            var initializer = new SequencePropertyInitializer();

            var telemetry1 = new StubTelemetry();
            initializer.Initialize(telemetry1);
            var telemetry2 = new StubTelemetry();
            initializer.Initialize(telemetry2);

            Assert.NotEqual(telemetry1.Sequence, telemetry2.Sequence);
        }
        public void WhenSendIsCalledTheEventIsBeingQueuedInTheBuffer()
        {
            var telemetryBuffer = new TelemetryBuffer();
            var channel = new InMemoryChannel(telemetryBuffer, new InMemoryTransmitter(telemetryBuffer));
            var sentTelemetry = new StubTelemetry();

            channel.Send(sentTelemetry);
            IEnumerable<ITelemetry> telemetries = telemetryBuffer.Dequeue();

            Assert.Equal(1, telemetries.Count());
            Assert.Same(sentTelemetry, telemetries.First());
        }
 public void InitializeDoesNotIncludeBase64PaddingInSequenceToReduceDataSize()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.DoesNotContain("=", telemetry.Sequence, StringComparison.Ordinal);
 }
 public void InitializeSeparatesStableIdAndNumberWithColonToConformWithVortexSpecification()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.Contains(":", telemetry.Sequence, StringComparison.Ordinal);
 }
 public void InitializeSetsSequencePropertyValue()
 {
     var telemetry = new StubTelemetry();
     new SequencePropertyInitializer().Initialize(telemetry);
     Assert.NotEmpty(telemetry.Sequence);
 }
            public void PassesTelemetryToMemoryBufferChannel()
            {
                var channel = new PersistenceChannel();

                var telemetry = new StubTelemetry();
                channel.Send(telemetry);

                IEnumerable<ITelemetry> actual = channel.TelemetryBuffer.Dequeue();
                Assert.AreEqual(telemetry, actual.First());
            }
        public void TrackRespectsInstrumentaitonKeySetByTelemetryInitializer()
        {
            var sentTelemetry = new List<ITelemetry>();
            var channel = new StubTelemetryChannel { OnSend = t => sentTelemetry.Add(t) };
            var configuration = new TelemetryConfiguration
            {
                // no instrumentation key set here
                TelemetryChannel = channel
            };

            var initializedTelemetry = new List<ITelemetry>();
            var telemetryInitializer = new StubTelemetryInitializer();
            telemetryInitializer.OnInitialize = item =>
            {
                item.Context.InstrumentationKey = "Foo";
                initializedTelemetry.Add(item);
            };

            configuration.TelemetryInitializers.Add(telemetryInitializer);

            var client = new TelemetryClient(configuration);

            var telemetry = new StubTelemetry();
            client.Track(telemetry);

            Assert.Equal(1, sentTelemetry.Count);
            Assert.Equal(1, initializedTelemetry.Count);
        }
        public void TrackDoesNotOverwriteTelemetryPropertiesWithClientPropertiesBecauseExplicitlySetValuesTakePrecedence()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel() };
            var client = new TelemetryClient(configuration);
            client.Context.Properties["TestProperty"] = "ClientValue";
            client.Context.InstrumentationKey = "Test Key";

            var telemetry = new StubTelemetry { Properties = { { "TestProperty", "TelemetryValue" } } };
            client.Track(telemetry);

            Assert.Equal("TelemetryValue", telemetry.Properties["TestProperty"]);
        }
        public void TrackCopiesPropertiesFromClientToTelemetry()
        {
            var configuration = new TelemetryConfiguration { TelemetryChannel = new StubTelemetryChannel() };
            var client = new TelemetryClient(configuration);
            client.Context.Properties["TestProperty"] = "TestValue";
            client.Context.InstrumentationKey = "Test Key";

            var telemetry = new StubTelemetry();
            client.Track(telemetry);

            Assert.Equal(client.Context.Properties.ToArray(), telemetry.Properties.ToArray());
        }