Skip to content

Commit

Permalink
Deserialize custom dimensions from application insights API response (#…
Browse files Browse the repository at this point in the history
…14917)

* Deserialize custom dimensions from application insights API response.
Fixes #13042

* Test non-empty CustomDimensions from application insights API response

Co-authored-by: Oleg Deribas <olegd@superoffice.com>
  • Loading branch information
geneh and olegd-superoffice committed Sep 17, 2020
1 parent 3540eb4 commit 58a48f0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace Microsoft.Azure.ApplicationInsights.Query.Models
{
public partial class EventsResultDataCustomDimensions
{
#pragma warning disable CS0649 // Field is never assigned to, and will always have its default value
[JsonExtensionData]
private IDictionary<string, JToken> _customDimensionsValues;
#pragma warning restore CS0649 // Field is never assigned to, and will always have its default value

public IEnumerable<string> Keys => _customDimensionsValues?.Keys;

public bool TryGetValue(string key, out string value)
{
if (_customDimensionsValues != null && _customDimensionsValues.TryGetValue(key, out var jToken))
{
value = jToken?.ToString();
return true;
}
value = null;
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ protected void AssertEvent(EventsResultData evnt, string expectedType)

Assert.NotNull(evnt.Timestamp);
// CustomDimensions & CustomMeasurements can be null
if (evnt.CustomDimensions != null && evnt.CustomDimensions.TryGetValue("ProcessId", out var value)) {
Assert.NotNull(value);
}

// Operation
if (expectedType != EventType.CustomEvents && expectedType != EventType.PageViews &&
Expand Down

0 comments on commit 58a48f0

Please sign in to comment.