public void TraceTelemetryPropertiesFromContextAndItemSerializesToPropertiesInJson() { var expected = new TraceTelemetry(); expected.Context.GlobalProperties.Add("contextpropkey", "contextpropvalue"); expected.Properties.Add("TestProperty", "TestPropertyValue"); ((ITelemetry)expected).Sanitize(); Assert.AreEqual(1, expected.Properties.Count); Assert.AreEqual(1, expected.Context.GlobalProperties.Count); Assert.IsTrue(expected.Properties.ContainsKey("TestProperty")); Assert.IsTrue(expected.Context.GlobalProperties.ContainsKey("contextpropkey")); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <AI.MessageData>(expected); // Items added to both MessageData.Properties, and MessageData.Context.GlobalProperties are serialized to properties. Assert.AreEqual(2, item.data.baseData.properties.Count); Assert.IsTrue(item.data.baseData.properties.ContainsKey("contextpropkey")); Assert.IsTrue(item.data.baseData.properties.ContainsKey("TestProperty")); }
public void RemoteDependencyTelemetrySerializesToJson() { DependencyTelemetry expected = this.CreateRemoteDependencyTelemetry(); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <DependencyTelemetry, AI.RemoteDependencyData>(expected); Assert.Equal <DateTimeOffset>(expected.Timestamp, DateTimeOffset.Parse(item.time, null, System.Globalization.DateTimeStyles.AssumeUniversal)); Assert.Equal(expected.Sequence, item.seq); Assert.Equal(expected.Context.InstrumentationKey, item.iKey); Assert.Equal(expected.Context.Tags.ToArray(), item.tags.ToArray()); Assert.Equal(typeof(AI.RemoteDependencyData).Name, item.data.baseType); Assert.Equal(expected.Id, item.data.baseData.id); Assert.Equal(expected.ResultCode, item.data.baseData.resultCode); Assert.Equal(expected.Name, item.data.baseData.name); Assert.Equal(expected.Duration.TotalMilliseconds, item.data.baseData.value); Assert.Equal(expected.DependencyKind.ToString(), item.data.baseData.dependencyKind.ToString()); Assert.Equal(expected.DependencyTypeName, item.data.baseData.dependencyTypeName); Assert.Equal(expected.Success, item.data.baseData.success); Assert.Equal(expected.Properties.ToArray(), item.data.baseData.properties.ToArray()); }
public void RemoteDependencyTelemetrySerializesToJson() { DependencyTelemetry expected = this.CreateRemoteDependencyTelemetry(); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <DependencyTelemetry, DataPlatformModel.RemoteDependencyData>(expected); Assert.Equal(expected.Timestamp, item.Time); Assert.Equal(expected.Sequence, item.Seq); Assert.Equal(expected.Context.InstrumentationKey, item.IKey); Assert.Equal(expected.Context.Tags.ToArray(), item.Tags.ToArray()); Assert.Equal(typeof(DataPlatformModel.RemoteDependencyData).Name, item.Data.BaseType); Assert.Equal(expected.Id, item.Data.BaseData.Id); Assert.Equal(expected.ResultCode, item.Data.BaseData.ResultCode); Assert.Equal(expected.Name, item.Data.BaseData.Name); Assert.Equal(expected.Duration.TotalMilliseconds, item.Data.BaseData.Value); Assert.Equal(expected.DependencyKind.ToString(), item.Data.BaseData.DependencyKind.ToString()); Assert.Equal(expected.DependencyTypeName, item.Data.BaseData.DependencyTypeName); Assert.Equal(expected.Success, item.Data.BaseData.Success); Assert.Equal(expected.Properties.ToArray(), item.Data.BaseData.Properties.ToArray()); }
public void PageViewTelemetrySerializesToJsonCorrectly() { var expected = new PageViewTelemetry("My Page"); expected.Url = new Uri("http://temp.org/page1"); expected.Duration = TimeSpan.FromSeconds(123); expected.Metrics.Add("Metric1", 30); expected.Properties.Add("Property1", "Value1"); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <AI.PageViewData>(expected); // NOTE: It's correct that we use the v1 name here, and therefore we test against it. Assert.AreEqual(item.name, AI.ItemType.PageView); Assert.AreEqual(nameof(AI.PageViewData), item.data.baseType); Assert.AreEqual(2, item.data.baseData.ver); Assert.AreEqual(expected.Name, item.data.baseData.name); Assert.AreEqual(expected.Duration, TimeSpan.Parse(item.data.baseData.duration)); Assert.AreEqual(expected.Url.ToString(), item.data.baseData.url); AssertEx.AreEqual(expected.Properties.ToArray(), item.data.baseData.properties.ToArray()); }
public void PageViewTelemetrySerializesToJsonCorrectly() { var expected = new PageViewTelemetry("My Page"); expected.Url = new Uri("http://temp.org/page1"); expected.Duration = TimeSpan.FromSeconds(123); expected.Metrics.Add("Metric1", 30); expected.Properties.Add("Property1", "Value1"); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <PageViewTelemetry, DataPlatformModel.PageViewData>(expected); // NOTE: It's correct that we use the v1 name here, and therefore we test against it. Assert.Equal(item.Name, Microsoft.Developer.Analytics.DataCollection.Model.v1.ItemType.PageView); Assert.Equal(typeof(DataPlatformModel.PageViewData).Name, item.Data.BaseType); Assert.Equal(2, item.Data.BaseData.Ver); Assert.Equal(expected.Name, item.Data.BaseData.Name); Assert.Equal(expected.Duration, item.Data.BaseData.Duration); Assert.Equal(expected.Url.ToString(), item.Data.BaseData.Url); Assert.Equal(expected.Properties.ToArray(), item.Data.BaseData.Properties.ToArray()); }
public void RequestTelemetrySerializesToJson() { var expected = new RequestTelemetry(); expected.Timestamp = DateTimeOffset.Now; expected.Id = "a1b2c3d4e5f6h7h8i9j10"; expected.Name = "GET /WebForm.aspx"; expected.Duration = TimeSpan.FromSeconds(4); expected.ResponseCode = "200"; expected.Success = true; expected.Url = new Uri("http://localhost/myapp/MyPage.aspx"); expected.HttpMethod = "GET"; expected.Metrics.Add("Metric1", 30); expected.Properties.Add("userHostAddress", "::1"); ((ITelemetry)expected).Sanitize(); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <RequestTelemetry, DataPlatformModel.RequestData>(expected); // NOTE: It's correct that we use the v1 name here, and therefore we test against it. Assert.Equal(item.Name, Microsoft.Developer.Analytics.DataCollection.Model.v1.ItemType.Request); Assert.Equal(typeof(DataPlatformModel.RequestData).Name, item.Data.BaseType); Assert.Equal(2, item.Data.BaseData.Ver); Assert.Equal(expected.Id, item.Data.BaseData.Id); Assert.Equal(expected.Name, item.Data.BaseData.Name); Assert.Equal(expected.Timestamp, item.Data.BaseData.StartTime); Assert.Equal(expected.Duration, item.Data.BaseData.Duration); Assert.Equal(expected.Success, item.Data.BaseData.Success); Assert.Equal(expected.ResponseCode, item.Data.BaseData.ResponseCode); Assert.Equal(expected.Url.ToString(), item.Data.BaseData.Url.ToString(), StringComparer.OrdinalIgnoreCase); Assert.Equal(expected.HttpMethod, item.Data.BaseData.HttpMethod); Assert.Equal(1, item.Data.BaseData.Measurements.Count); Assert.Equal(expected.Metrics, item.Data.BaseData.Measurements); Assert.Equal(expected.Properties.ToArray(), item.Data.BaseData.Properties.ToArray()); }
public void AvailabilityTelemetrySerializesToJson() { AvailabilityTelemetry expected = this.CreateAvailabilityTelemetry(); var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <AI.AvailabilityData>(expected); Assert.AreEqual <DateTimeOffset>(expected.Timestamp, DateTimeOffset.Parse(item.time, null, System.Globalization.DateTimeStyles.AssumeUniversal)); Assert.AreEqual(expected.Sequence, item.seq); Assert.AreEqual(expected.Context.InstrumentationKey, item.iKey); AssertEx.AreEqual(expected.Context.SanitizedTags.ToArray(), item.tags.ToArray()); Assert.AreEqual(nameof(AI.AvailabilityData), item.data.baseType); Assert.AreEqual(expected.Duration, TimeSpan.Parse(item.data.baseData.duration)); Assert.AreEqual(expected.Message, item.data.baseData.message); Assert.AreEqual(expected.Success, item.data.baseData.success); Assert.AreEqual(expected.RunLocation, item.data.baseData.runLocation); Assert.AreEqual(expected.Name, item.data.baseData.name); Assert.AreEqual(expected.Id.ToString(), item.data.baseData.id); // IExtension is currently flattened into the properties by serialization Utils.CopyDictionary(((MyTestExtension)expected.Extension).SerializeIntoDictionary(), expected.Properties); AssertEx.AreEqual(expected.Properties.ToArray(), item.data.baseData.properties.ToArray()); }
/// Test validates that if Serialize is called multiple times, and telemetry is modified /// in between, serialize always gives the latest state. /// public void RequestTelemetrySerializationPicksUpCorrectState() { var expected = CreateTestTelemetry(); ((ITelemetry)expected).Sanitize(); byte[] buf = new byte[1000000]; expected.SerializeData(new JsonSerializationWriter(new StreamWriter(new MemoryStream(buf)))); // Change the telemetry after serialization. expected.Url = new Uri(expected.Url.ToString() + "new"); // Validate that the newly updated URL is picked up. var item = TelemetryItemTestHelper.SerializeDeserializeTelemetryItem <AI.RequestData>(expected); // NOTE: It's correct that we use the v1 name here, and therefore we test against it. Assert.AreEqual(item.name, AI.ItemType.Request); Assert.AreEqual(nameof(AI.RequestData), item.data.baseType); Assert.AreEqual(2, item.data.baseData.ver); Assert.AreEqual(expected.Id, item.data.baseData.id); Assert.AreEqual(expected.Name, item.data.baseData.name); Assert.AreEqual(expected.Timestamp, DateTimeOffset.Parse(item.time)); Assert.AreEqual(expected.Duration, TimeSpan.Parse(item.data.baseData.duration)); Assert.AreEqual(expected.Success, item.data.baseData.success); Assert.AreEqual(expected.ResponseCode, item.data.baseData.responseCode); Assert.AreEqual(expected.Url.ToString(), item.data.baseData.url.ToString()); Assert.AreEqual(1, item.data.baseData.measurements.Count); // IExtension is currently flattened into the properties by serialization Utils.CopyDictionary(((MyTestExtension)expected.Extension).SerializeIntoDictionary(), expected.Properties); AssertEx.AreEqual(expected.Properties.ToArray(), item.data.baseData.properties.ToArray()); }