Esempio n. 1
0
        public void SearchSelectionTelemetryEvent_VulnerableAndDeprecationInfo_Succeeds(bool isPackageVulnerable, bool isPackageDeprecated, bool hasDeprecationAlternative)
        {
            // Assert params
            Assert.False(isPackageDeprecated == false && hasDeprecationAlternative == true);

            // Arrange
            var            telemetrySession   = new Mock <ITelemetrySession>();
            TelemetryEvent lastTelemetryEvent = null;

            _ = telemetrySession
                .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>()))
                .Callback <TelemetryEvent>(x => lastTelemetryEvent = x);

            var service = new NuGetVSTelemetryService(telemetrySession.Object);

            var evt = new SearchSelectionTelemetryEvent(
                parentId: It.IsAny <Guid>(),
                recommendedCount: It.IsAny <int>(),
                itemIndex: It.IsAny <int>(),
                packageId: "testpackage",
                packageVersion: new NuGetVersion(1, 0, 0),
                isPackageVulnerable: isPackageVulnerable,
                isPackageDeprecated: isPackageDeprecated,
                hasDeprecationAlternativePackage: hasDeprecationAlternative);

            // Act
            service.EmitTelemetryEvent(evt);

            // Assert
            Assert.NotNull(lastTelemetryEvent);
            Assert.Equal(isPackageDeprecated, lastTelemetryEvent["IsPackageDeprecated"]);
            Assert.Equal(isPackageVulnerable, lastTelemetryEvent["IsPackageVulnerable"]);
            Assert.Equal(hasDeprecationAlternative, lastTelemetryEvent["HasDeprecationAlternativePackage"]);
        }
        public void HyperlinkClicked_CorrelatesSearchSelectionAndAction_Succeeds()
        {
            // Arrange
            var            telemetrySession   = new Mock <ITelemetrySession>();
            TelemetryEvent lastTelemetryEvent = null;

            _ = telemetrySession
                .Setup(x => x.PostEvent(It.IsAny <TelemetryEvent>()))
                .Callback <TelemetryEvent>(x => lastTelemetryEvent = x);

            var service = new NuGetVSTelemetryService(telemetrySession.Object);

            var testPackageId      = "testPackage.id";
            var testPackageVersion = new NuGetVersion(1, 0, 0);

            var evtHyperlink = new HyperlinkClickedTelemetryEvent(
                HyperlinkType.DeprecationAlternativeDetails,
                ContractsItemFilter.All,
                isSolutionView: false,
                testPackageId);

            var evtSearch = new SearchSelectionTelemetryEvent(
                parentId: It.IsAny <Guid>(),
                recommendedCount: It.IsAny <int>(),
                itemIndex: It.IsAny <int>(),
                packageId: testPackageId,
                packageVersion: testPackageVersion,
                isPackageVulnerable: It.IsAny <bool>(),
                isPackageDeprecated: true,
                hasDeprecationAlternativePackage: true);

            var evtActions = new VSActionsTelemetryEvent(
                operationId: It.IsAny <string>(),
                projectIds: new[] { Guid.NewGuid().ToString() },
                operationType: NuGetOperationType.Install,
                source: OperationSource.PMC,
                startTime: DateTimeOffset.Now.AddSeconds(-1),
                status: NuGetOperationStatus.NoOp,
                packageCount: 1,
                endTime: DateTimeOffset.Now,
                duration: .40,
                isPackageSourceMappingEnabled: false);

            // Simulate UIActionEngine.AddUiActionEngineTelemetryProperties()
            var pkgAdded = new TelemetryEvent(eventName: null);

            pkgAdded.AddPiiData("id", VSTelemetryServiceUtility.NormalizePackageId(testPackageId));
            pkgAdded.AddPiiData("version", testPackageVersion.ToNormalizedString());

            var packages = new List <TelemetryEvent>
            {
                pkgAdded
            };

            evtActions.ComplexData["AddedPackages"] = packages;

            // Act
            service.EmitTelemetryEvent(evtHyperlink);
            var hyperlinkEmitted = lastTelemetryEvent;

            service.EmitTelemetryEvent(evtSearch);
            var searchEmitted = lastTelemetryEvent;

            service.EmitTelemetryEvent(evtActions);
            var actionEmitted = lastTelemetryEvent;

            // Assert
            var packageIdHyperlink = hyperlinkEmitted.GetPiiData().First(x => x.Key == HyperlinkClickedTelemetryEvent.AlternativePackageIdPropertyName).Value;
            var packageIdSearch    = searchEmitted.GetPiiData().First(x => x.Key == "PackageId").Value;
            var packageIdsAction   = (IEnumerable <TelemetryEvent>)actionEmitted.ComplexData["AddedPackages"];
            var packageIds         = packageIdsAction.Select(x => x.GetPiiData().First(x => x.Key == "id").Value);

            Assert.Equal(packageIdHyperlink, packageIdSearch);
            Assert.Contains(packageIdHyperlink, packageIds);
        }