Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Threading.Channels;
#endif

using Microsoft.Testing.Platform;
using Microsoft.Testing.Platform.Configurations;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
Expand Down Expand Up @@ -37,7 +36,6 @@
private readonly bool _isCi;
private readonly IEnvironment _environment;
private readonly ITestApplicationCancellationTokenSource _testApplicationCancellationTokenSource;
private readonly ITask _task;
private readonly IClock _clock;
private readonly ITelemetryInformation _telemetryInformation;
private readonly ITelemetryClientFactory _telemetryClientFactory;
Expand Down Expand Up @@ -86,7 +84,7 @@
_environment = environment;
_currentSessionId = sessionId;
_testApplicationCancellationTokenSource = testApplicationCancellationTokenSource;
_task = task;

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Release)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context

Check failure on line 87 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L87

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(87,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name '_task' does not exist in the current context
_clock = clock;
_telemetryInformation = telemetryInformation;
_telemetryClientFactory = telemetryClientFactory;
Expand Down Expand Up @@ -189,7 +187,6 @@
break;
#endif
case bool value:
RoslynDebug.Assert(false, $"Telemetry entry '{pair.Key}' contains a boolean value, boolean values should always be converted to string using: .{nameof(TelemetryExtensions.AsTelemetryBool)}()");
properties.Add(pair.Key, value.AsTelemetryBool());
break;
default:
Expand Down Expand Up @@ -264,7 +261,7 @@
return;
}

RoslynDebug.Assert(false, $"Telemetry entry '{key}' contains an unhashed string value '{value}'. Strings need to be hashed using {nameof(Sha256Hasher)}.{nameof(Sha256Hasher.HashWithNormalizedCasing)}(), or white-listed.");

Check failure on line 264 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L264

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(264,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name 'RoslynDebug' does not exist in the current context

Check failure on line 264 in src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build Linux Debug)

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs#L264

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(264,9): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name 'RoslynDebug' does not exist in the current context
}

#if NET7_0_OR_GREATER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,55 @@ public void Timeout_During_Dispose_Should_Exit_Gracefully()
appInsightsProvider.Dispose();
#endif
}

[TestMethod]
public async Task LogEvent_WithBooleanProperty_ConvertsValueToTelemetryString()
{
Mock<IEnvironment> environment = new();
Mock<IClock> clock = new();
Mock<IConfiguration> config = new();
Mock<ITelemetryInformation> telemetryInformation = new();

Mock<ILoggerFactory> loggerFactory = new();
loggerFactory.Setup(x => x.CreateLogger(It.IsAny<string>())).Returns(new Mock<ILogger>().Object);

var capturedProperties = new Dictionary<string, string>();
Mock<ITelemetryClient> testTelemetryClient = new();
testTelemetryClient.Setup(x => x.TrackEvent(It.IsAny<string>(), It.IsAny<Dictionary<string, string>>(), It.IsAny<Dictionary<string, double>>()))
.Callback((string _, Dictionary<string, string> properties, Dictionary<string, double> _) =>
{
foreach (KeyValuePair<string, string> pair in properties)
{
capturedProperties[pair.Key] = pair.Value;
}
});

Mock<ITelemetryClientFactory> telemetryClientFactory = new();
telemetryClientFactory.Setup(x => x.Create(It.IsAny<string?>(), It.IsAny<string>())).Returns(testTelemetryClient.Object);

CancellationTokenSource cancellationTokenSource = new();
Mock<ITestApplicationCancellationTokenSource> testApplicationCancellationTokenSource = new();
testApplicationCancellationTokenSource.Setup(x => x.CancellationToken).Returns(cancellationTokenSource.Token);

AppInsightsProvider appInsightsProvider = new(
environment.Object,
testApplicationCancellationTokenSource.Object,
new SystemTask(),
loggerFactory.Object,
clock.Object,
config.Object,
telemetryInformation.Object,
telemetryClientFactory.Object,
"sessionId");

await appInsightsProvider.LogEventAsync(
"Sample",
new Dictionary<string, object> { ["my.bool"] = true },
CancellationToken.None);

await appInsightsProvider.DisposeAsync();
Comment on lines +203 to +210
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit a450882: the new test now calls DisposeAsync() only under #if NETCOREAPP and falls back to Dispose() on .NET Framework targets, matching the existing tests in this file. Verified by running the test on net462/net472/net8.0/net9.0 — all pass.


Assert.IsTrue(capturedProperties.ContainsKey("my.bool"));
Assert.AreEqual(TelemetryProperties.True, capturedProperties["my.bool"]);
}
}
Loading