Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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,7 @@
using System.Threading.Channels;
#endif

using Microsoft.Testing.Platform;

Check failure on line 8 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#L8

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

Check failure on line 8 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#L8

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(8,1): error IDE0005: (NETCORE_ENGINEERING_TELEMETRY=Build) Using directive is unnecessary. (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0005)
Comment thread
Evangelink marked this conversation as resolved.
Outdated
using Microsoft.Testing.Platform.Configurations;
using Microsoft.Testing.Platform.Helpers;
using Microsoft.Testing.Platform.Logging;
Expand Down Expand Up @@ -37,7 +37,7 @@
private readonly bool _isCi;
private readonly IEnvironment _environment;
private readonly ITestApplicationCancellationTokenSource _testApplicationCancellationTokenSource;
private readonly ITask _task;

Check failure on line 40 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#L40

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)

Check failure on line 40 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#L40

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx (Build MacOS Release)

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)

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

View check run for this annotation

Azure Pipelines / microsoft.testfx

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

src/Platform/Microsoft.Testing.Extensions.Telemetry/AppInsightsProvider.cs(40,28): error IDE0052: (NETCORE_ENGINEERING_TELEMETRY=Build) Private member 'AppInsightsProvider._task' can be removed as the value assigned to it is never read (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/style-rules/ide0052)
Comment thread
Evangelink marked this conversation as resolved.
Outdated
private readonly IClock _clock;
private readonly ITelemetryInformation _telemetryInformation;
private readonly ITelemetryClientFactory _telemetryClientFactory;
Expand Down Expand Up @@ -189,7 +189,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
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 +200 to +202

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