-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry data points for .NET Core 2.0
- Loading branch information
William Li
committed
Jul 27, 2017
1 parent
48a3c4b
commit f078aca
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
test/Microsoft.NET.Build.Tests/GivenThatWeWantToBuildANetCoreAppForTelemetry.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using FluentAssertions; | ||
using Microsoft.NET.TestFramework; | ||
using Microsoft.NET.TestFramework.Assertions; | ||
using Microsoft.NET.TestFramework.Commands; | ||
using Microsoft.NET.TestFramework.ProjectConstruction; | ||
using System; | ||
using System.IO; | ||
using Xunit; | ||
using Xunit.Abstractions; | ||
using System.Reflection; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public class GivenThatWeWantToBuildANetCoreAppAndPassingALogger : SdkTest | ||
{ | ||
public GivenThatWeWantToBuildANetCoreAppAndPassingALogger(ITestOutputHelper log) : base(log) | ||
{ | ||
} | ||
|
||
[CoreMSBuildOnlyFact] | ||
public void It_collects_TargetFramework_version() | ||
{ | ||
string targetFramework = "netcoreapp1.0"; | ||
var testProject = new TestProject() | ||
{ | ||
Name = "FrameworkTargetTelemetryTest", | ||
TargetFrameworks = targetFramework, | ||
IsSdkProject = true, | ||
}; | ||
Type loggerType = typeof(LogTelemetryToStdOutForTest); | ||
var TelemetryTestLogger = new[] | ||
{ | ||
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" | ||
}; | ||
var testAsset = _testAssetsManager.CreateTestProject(testProject) | ||
.Restore(Log, testProject.Name, TelemetryTestLogger); | ||
|
||
var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); | ||
|
||
buildCommand | ||
.Execute(TelemetryTestLogger) | ||
.StdOut.Should() | ||
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.0\"}"); | ||
} | ||
|
||
[CoreMSBuildOnlyFact] | ||
public void It_collects_multi_TargetFramework_version() | ||
{ | ||
string targetFramework = "net46;netcoreapp1.1"; | ||
|
||
var testProject = new TestProject() | ||
{ | ||
Name = "MultitargetTelemetry", | ||
TargetFrameworks = targetFramework, | ||
IsSdkProject = true, | ||
}; | ||
Type loggerType = typeof(LogTelemetryToStdOutForTest); | ||
var TelemetryTestLogger = new[] | ||
{ | ||
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" | ||
}; | ||
var testAsset = _testAssetsManager.CreateTestProject(testProject) | ||
.Restore(Log, testProject.Name, TelemetryTestLogger); | ||
|
||
var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); | ||
|
||
buildCommand | ||
.Execute(TelemetryTestLogger) | ||
.StdOut.Should() | ||
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETFramework,Version=v4.6\"}") | ||
.And | ||
.Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.1\"}"); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
test/Microsoft.NET.Build.Tests/LogTelemetryToStdOutForTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System; | ||
using Microsoft.Build.Framework; | ||
using Microsoft.Build.Utilities; | ||
using NuGet.Protocol; | ||
|
||
namespace Microsoft.NET.Build.Tests | ||
{ | ||
public sealed class LogTelemetryToStdOutForTest : Logger | ||
{ | ||
|
||
public LogTelemetryToStdOutForTest() | ||
{ | ||
} | ||
|
||
public override void Initialize(IEventSource eventSource) | ||
{ | ||
if (eventSource is IEventSource2 eventSource2) | ||
{ | ||
eventSource2.TelemetryLogged += OnTelemetryLogged; | ||
} | ||
} | ||
|
||
private void OnTelemetryLogged(object sender, TelemetryEventArgs args) | ||
{ | ||
Console.WriteLine(args.ToJson()); | ||
} | ||
} | ||
} |