|
| 1 | +using FluentAssertions; |
| 2 | +using Microsoft.NET.TestFramework; |
| 3 | +using Microsoft.NET.TestFramework.Assertions; |
| 4 | +using Microsoft.NET.TestFramework.Commands; |
| 5 | +using Microsoft.NET.TestFramework.ProjectConstruction; |
| 6 | +using System; |
| 7 | +using System.IO; |
| 8 | +using Xunit; |
| 9 | +using Xunit.Abstractions; |
| 10 | +using System.Reflection; |
| 11 | + |
| 12 | +namespace Microsoft.NET.Build.Tests |
| 13 | +{ |
| 14 | + public class GivenThatWeWantToBuildANetCoreAppAndPassingALogger : SdkTest |
| 15 | + { |
| 16 | + public GivenThatWeWantToBuildANetCoreAppAndPassingALogger(ITestOutputHelper log) : base(log) |
| 17 | + { |
| 18 | + } |
| 19 | + |
| 20 | + [Fact] |
| 21 | + public void It_collects_TargetFramework_version() |
| 22 | + { |
| 23 | + string targetFramework = "netcoreapp1.0"; |
| 24 | + var testProject = new TestProject() |
| 25 | + { |
| 26 | + Name = "FrameworkTargetTelemetryTest", |
| 27 | + TargetFrameworks = targetFramework, |
| 28 | + IsSdkProject = true, |
| 29 | + }; |
| 30 | + Type loggerType = typeof(LogTelemetryToStdOutForTest); |
| 31 | + var TelemetryTestLogger = new[] |
| 32 | + { |
| 33 | + $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" |
| 34 | + }; |
| 35 | + var testAsset = _testAssetsManager.CreateTestProject(testProject) |
| 36 | + .Restore(Log, testProject.Name, TelemetryTestLogger); |
| 37 | + |
| 38 | + var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); |
| 39 | + |
| 40 | + buildCommand |
| 41 | + .Execute(TelemetryTestLogger) |
| 42 | + .StdOut.Should() |
| 43 | + .Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.0\"}"); |
| 44 | + } |
| 45 | + |
| 46 | + [Fact] |
| 47 | + public void It_collects_multi_TargetFramework_version() |
| 48 | + { |
| 49 | + string targetFramework = "net46;netcoreapp1.1"; |
| 50 | + |
| 51 | + var testProject = new TestProject() |
| 52 | + { |
| 53 | + Name = "MultitargetTelemetry", |
| 54 | + TargetFrameworks = targetFramework, |
| 55 | + IsSdkProject = true, |
| 56 | + }; |
| 57 | + Type loggerType = typeof(LogTelemetryToStdOutForTest); |
| 58 | + var TelemetryTestLogger = new[] |
| 59 | + { |
| 60 | + $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" |
| 61 | + }; |
| 62 | + var testAsset = _testAssetsManager.CreateTestProject(testProject) |
| 63 | + .Restore(Log, testProject.Name, TelemetryTestLogger); |
| 64 | + |
| 65 | + var buildCommand = new BuildCommand(Log, Path.Combine(testAsset.TestRoot, testProject.Name)); |
| 66 | + |
| 67 | + buildCommand |
| 68 | + .Execute(TelemetryTestLogger) |
| 69 | + .StdOut.Should() |
| 70 | + .Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETFramework,Version=v4.6\"}") |
| 71 | + .And |
| 72 | + .Contain("{\"EventName\":\"TargetFramework\",\"Properties\":{\"version\":\".NETCoreApp,Version=v1.1\"}"); |
| 73 | + } |
| 74 | + } |
| 75 | +} |
0 commit comments