Пример #1
0
        public void ItMasksEventNameWithTargetframeworkevalOnTargetFrameworkVersionUseWindowsFormsOrWPF()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = MSBuildLogger.TargetFrameworkTelemetryEventName,
                Properties = new Dictionary <string, string>
                {
                    { MSBuildLogger.TargetFrameworkVersionTelemetryPropertyKey, ".NETStandard,Version=v2.0" },
                    { MSBuildLogger.UseWindowsFormsTelemetryPropertyKey, "true" },
                    { MSBuildLogger.UseWPFTelemetryPropertyKey, "AnyNonTrueValue" },
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.EventName.Should().Be($"msbuild/{MSBuildLogger.TargetFrameworkTelemetryEventName}");
            fakeTelemetry.LogEntry.Properties.Keys.Count.Should().Be(3);
            fakeTelemetry.LogEntry.Properties[MSBuildLogger.TargetFrameworkVersionTelemetryPropertyKey].Should().Be(Sha256Hasher.Hash(".NETSTANDARD,VERSION=V2.0"));
            fakeTelemetry.LogEntry.Properties[MSBuildLogger.UseWindowsFormsTelemetryPropertyKey].Should().Be("True");
            fakeTelemetry.LogEntry.Properties[MSBuildLogger.UseWPFTelemetryPropertyKey]
            .Should().Be(
                "False",
                "sanitize to avoid user input, and since in SDK prop and target non 'true' is effectively false");
        }
Пример #2
0
        public void ItCanSendProperties()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = "targetframeworkeval",
                Properties = new Dictionary <string, string>
                {
                    { "TargetFrameworkVersion", ".NETFramework,Version=v4.6" },
                    { "RuntimeIdentifier", "null" },
                    { "SelfContained", "null" },
                    { "UseApphost", "null" },
                    { "OutputType", "Library" },
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.Properties.ShouldBeEquivalentTo(new Dictionary <string, string>
            {
                { "TargetFrameworkVersion", "9a871d7066260764d4cb5047e4b10570271d04bd1da275681a4b12bce0b27496" },
                { "RuntimeIdentifier", "fb329000228cc5a24c264c57139de8bf854fc86fc18bf1c04ab61a2b5cb4b921" },
                { "SelfContained", "fb329000228cc5a24c264c57139de8bf854fc86fc18bf1c04ab61a2b5cb4b921" },
                { "UseApphost", "fb329000228cc5a24c264c57139de8bf854fc86fc18bf1c04ab61a2b5cb4b921" },
                { "OutputType", "d77982267d9699c2a57bcab5bb975a1935f6427002f52fd4569762fd72db3a94" },
            });
        }
Пример #3
0
        public void ItBlocksTelemetryThatIsNotInTheList()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = "User Defined Event Name",
                Properties = new Dictionary <string, string>
                {
                    { "User Defined Key", "User Defined Value" },
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.Should().BeNull();
        }
Пример #4
0
        public void ItMasksEventNameWithTargetframeworkevalOnTargetFrameworkVersionUseWindowsFormsOrWPFWhenFieldIsEmpty()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = MSBuildLogger.TargetFrameworkTelemetryEventName,
                Properties = new Dictionary <string, string>
                {
                    { MSBuildLogger.UseWindowsFormsTelemetryPropertyKey, "null" },
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.Properties[MSBuildLogger.UseWindowsFormsTelemetryPropertyKey]
            .Should().Be(
                "null",
                "MSBuild will throw when the task param contain empty and if the field is empty json will emit the entry, so it still need to be set to something.");
        }
Пример #5
0
        public void ItDoesNotMasksExceptionTelemetry()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = MSBuildLogger.SdkTaskBaseCatchExceptionTelemetryEventName,
                Properties = new Dictionary <string, string>
                {
                    { "exceptionType", "System.Exception" },
                    { "detail", "Exception detail" }
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.EventName.Should().Be(MSBuildLogger.SdkTaskBaseCatchExceptionTelemetryEventName);
            fakeTelemetry.LogEntry.Properties.Keys.Count.Should().Be(2);
            fakeTelemetry.LogEntry.Properties["exceptionType"].Should().Be("System.Exception");
            fakeTelemetry.LogEntry.Properties["detail"].Should().Be("Exception detail");
        }
Пример #6
0
        public void ItDoesNotMaskReadyToRunTelemetry()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = MSBuildLogger.ReadyToRunTelemetryEventName,
                Properties = new Dictionary <string, string>
                {
                    { "PublishReadyToRunUseCrossgen2", "null" },
                    { "otherProperty", "otherProperty value" }
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.EventName.Should().Be(MSBuildLogger.ReadyToRunTelemetryEventName);
            fakeTelemetry.LogEntry.Properties.Keys.Count.Should().Be(2);
            fakeTelemetry.LogEntry.Properties["PublishReadyToRunUseCrossgen2"].Should().Be("null");
            fakeTelemetry.LogEntry.Properties["otherProperty"].Should().Be("otherProperty value");
        }
Пример #7
0
        public void ItMasksTargetFrameworkEventname()
        {
            var fakeTelemetry      = new FakeTelemetry();
            var telemetryEventArgs = new TelemetryEventArgs
            {
                EventName  = "targetframeworkeval",
                Properties = new Dictionary <string, string>
                {
                    { "TargetFrameworkVersion", ".NETStandard,Version=v2.0" },
                }
            };

            MSBuildLogger.FormatAndSend(fakeTelemetry, telemetryEventArgs);

            fakeTelemetry.LogEntry.EventName.Should().Be("msbuild/targetframeworkeval");
            fakeTelemetry.LogEntry.Properties.Keys.Count.Should().Be(1);
            var expectedKey = "TargetFrameworkVersion";

            fakeTelemetry.LogEntry.Properties.Should().ContainKey(expectedKey);
            fakeTelemetry.LogEntry.Properties[expectedKey].Should().Be(Sha256Hasher.Hash(".NETSTANDARD,VERSION=V2.0"));
        }