public void DoesNotContinueAsyncOperationsOnCapturedSynchronizationContextToImprovePerformance() { var transmitter = new StubTransmitter() { OnEnqueue = transmission => Task.Run(() => { }) }; var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("https://127.0.0.1") }; bool postedBack = false; using (var context = new StubSynchronizationContext()) { context.OnPost = (callback, state) => { postedBack = true; callback(state); }; serializer.Serialize(new[] { new StubTelemetry() }); } Assert.IsFalse(postedBack); }
public void EnqueuesTransmissionWithExpectedPropertiesForUnknownTelemetry() { Transmission transmission = null; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { transmission = t; }; var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") }; serializer.Serialize(new[] { new StubTelemetry() }); Assert.AreEqual(serializer.EndpointAddress, transmission.EndpointAddress); Assert.AreEqual("application/x-json-stream", transmission.ContentType); Assert.AreEqual("gzip", transmission.ContentEncoding); Assert.AreEqual("{" + "\"name\":\"Microsoft.ApplicationInsights.Event\"," + "\"time\":\"0001-01-01T00:00:00.0000000Z\"," + "\"data\":{\"baseType\":\"EventData\"," + "\"baseData\":{\"ver\":2," + "\"name\":\"ConvertedTelemetry\"}" + "}" + "}", Unzip(transmission.Content)); }
public void EnqueuesTransmissionWithSetTransmissionStatusEvent() { Transmission transmission = null; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { transmission = t; }; var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") }; // Set TransmissionStatusEvent does not change the behavior, only wires up event to transmission. serializer.TransmissionStatusEvent += delegate(object sender, TransmissionStatusEventArgs args) { }; serializer.Serialize(new[] { new StubSerializableTelemetry() }); Assert.AreEqual(serializer.EndpointAddress, transmission.EndpointAddress); Assert.AreEqual("application/x-json-stream", transmission.ContentType); Assert.AreEqual("gzip", transmission.ContentEncoding); var expectedContent = "{" + "\"name\":\"StubTelemetryName\"," + "\"time\":\"0001-01-01T00:00:00.0000000Z\"," + "\"data\":{\"baseType\":\"StubTelemetryBaseType\"," + "\"baseData\":{}" + "}" + "}"; Assert.AreEqual(expectedContent, Unzip(transmission.Content)); }
public void EnqueuesTransmissionWithExpectedPropertiesForKnownTelemetry() { Transmission transmission = null; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { transmission = t; }; var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") }; serializer.Serialize(new[] { new StubSerializableTelemetry() }); Assert.AreEqual(serializer.EndpointAddress, transmission.EndpointAddress); Assert.AreEqual("application/x-json-stream", transmission.ContentType); Assert.AreEqual("gzip", transmission.ContentEncoding); var expectedContent = "{" + "\"name\":\"StubTelemetryName\"," + "\"time\":\"0001-01-01T00:00:00.0000000Z\"," + "\"data\":{\"baseType\":\"StubTelemetryBaseType\"," + "\"baseData\":{}" + "}" + "}"; Assert.AreEqual(expectedContent, Unzip(transmission.Content)); }
public void SerializesTelemetryOnSameThreadBecauseItAssumesItIsAlreadyOnThreadPool() { int serializationThreadId = -1; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { serializationThreadId = Thread.CurrentThread.ManagedThreadId; }; var serializer = new TelemetrySerializer(transmitter); serializer.Serialize(new[] { new StubTelemetry() }); Assert.Equal(serializationThreadId, Thread.CurrentThread.ManagedThreadId); }
public void SerializesTelemetryOnSameThreadBecauseItAssumesItIsAlreadyOnThreadPool() { int serializationThreadId = -1; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { serializationThreadId = Thread.CurrentThread.ManagedThreadId; }; var serializer = new TelemetrySerializer(transmitter); serializer.Serialize(new[] { new StubTelemetry() }); Assert.AreEqual(serializationThreadId, Thread.CurrentThread.ManagedThreadId); }
public void EnqueuesTransmissionWithExpectedProperties() { Transmission transmission = null; var transmitter = new StubTransmitter(); transmitter.OnEnqueue = t => { transmission = t; }; var serializer = new TelemetrySerializer(transmitter) { EndpointAddress = new Uri("http://expected.uri") }; serializer.Serialize(new[] { new StubTelemetry() }); Assert.Equal(serializer.EndpointAddress, transmission.EndpointAddress); Assert.Equal("application/x-json-stream", transmission.ContentType); Assert.Equal("gzip", transmission.ContentEncoding); Assert.Equal(string.Empty, Unzip(transmission.Content)); }
public void ThrowsArgumentExceptionWhenTelemetryIsEmptyToPreventUsageErrors() { var serializer = new TelemetrySerializer(new StubTransmitter()); AssertEx.Throws <ArgumentException>(() => serializer.Serialize(new List <ITelemetry>())); }
public void ThrowsArgumentNullExceptionWhenTelemetryIsNullToPreventUsageErrors() { var serializer = new TelemetrySerializer(new StubTransmitter()); AssertEx.Throws <ArgumentNullException>(() => serializer.Serialize(null)); }
public void ThrowsArgumentExceptionWhenTelemetryIsEmptyToPreventUsageErrors() { var serializer = new TelemetrySerializer(new StubTransmitter()); Assert.Throws<ArgumentException>(() => serializer.Serialize(Enumerable.Empty<ITelemetry>())); }
public void ThrowsArgumentNullExceptionWhenTelemetryIsNullToPreventUsageErrors() { var serializer = new TelemetrySerializer(new StubTransmitter()); Assert.Throws<ArgumentNullException>(() => serializer.Serialize(null)); }
public void DoesNotContinueAsyncOperationsOnCapturedSynchronizationContextToImprovePerformance() { var transmitter = new StubTransmitter() { OnEnqueue = transmission => TaskEx.Run(() => { }) }; var serializer = new TelemetrySerializer(transmitter); bool postedBack = false; using (var context = new StubSynchronizationContext()) { context.OnPost = (callback, state) => { postedBack = true; callback(state); }; serializer.Serialize(new[] { new StubTelemetry() }); } Assert.False(postedBack); }