public void NuGetTelemetryService_EmitProjectInformation(NuGetProjectType projectType)
        {
            // Arrange
            var            telemetrySession   = new Mock <ITelemetrySession>();
            TelemetryEvent lastTelemetryEvent = null;

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

            var projectInformation = new ProjectTelemetryEvent(
                "3.5.0-beta2",
                "15e9591f-9391-4ddf-a246-ca9e0351277d",
                projectType,
                true,
                @"C:\path\to\project.csproj");
            var target = new NuGetVSTelemetryService(telemetrySession.Object);

            // Act
            target.EmitTelemetryEvent(projectInformation);

            // Assert
            telemetrySession.Verify(x => x.PostEvent(It.IsAny <TelemetryEvent>()), Times.Once);
            Assert.NotNull(lastTelemetryEvent);
            Assert.Equal("ProjectInformation", lastTelemetryEvent.Name);
            Assert.Equal(4, lastTelemetryEvent.Count);

            var nuGetVersion = lastTelemetryEvent["NuGetVersion"];

            Assert.NotNull(nuGetVersion);
            Assert.IsType <string>(nuGetVersion);
            Assert.Equal(projectInformation.NuGetVersion, nuGetVersion);

            var projectId = lastTelemetryEvent["ProjectId"];

            Assert.NotNull(projectId);
            Assert.IsType <string>(projectId);
            Assert.Equal(projectInformation.ProjectId.ToString(), projectId);

            var actualProjectType = lastTelemetryEvent["NuGetProjectType"];

            Assert.NotNull(actualProjectType);
            Assert.IsType <NuGetProjectType>(actualProjectType);
            Assert.Equal(projectInformation.NuGetProjectType, actualProjectType);

            var isPRUpgradable = lastTelemetryEvent["IsPRUpgradable"];

            Assert.NotNull(isPRUpgradable);
            Assert.IsType <bool>(isPRUpgradable);
            Assert.Equal(projectInformation.IsProjectPRUpgradable, isPRUpgradable);

            var projectFilePath = lastTelemetryEvent
                                  .GetPiiData()
                                  .Where(kv => kv.Key == ProjectTelemetryEvent.ProjectFilePath)
                                  .First()
                                  .Value;

            Assert.IsType <string>(projectFilePath);
            Assert.True(!string.IsNullOrEmpty((string)projectFilePath));
        }
Exemple #2
0
        public void NuGetTelemetryService_EmitProjectInformation(NuGetProjectType projectType)
        {
            // Arrange
            var            telemetrySession   = new Mock <ITelemetrySession>();
            TelemetryEvent lastTelemetryEvent = null;

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

            var projectInformation = new ProjectTelemetryEvent(
                "3.5.0-beta2",
                "15e9591f-9391-4ddf-a246-ca9e0351277d",
                projectType,
                3,
                true);
            var target = new NuGetVSTelemetryService(telemetrySession.Object);

            // Act
            target.EmitTelemetryEvent(projectInformation);

            // Assert
            telemetrySession.Verify(x => x.PostEvent(It.IsAny <TelemetryEvent>()), Times.Once);
            Assert.NotNull(lastTelemetryEvent);
            Assert.Equal("ProjectInformation", lastTelemetryEvent.Name);
            Assert.Equal(5, lastTelemetryEvent.Count);

            var nuGetVersion = lastTelemetryEvent["NuGetVersion"];

            Assert.NotNull(nuGetVersion);
            Assert.IsType <string>(nuGetVersion);
            Assert.Equal(projectInformation.NuGetVersion, nuGetVersion);

            var projectId = lastTelemetryEvent["ProjectId"];

            Assert.NotNull(projectId);
            Assert.IsType <string>(projectId);
            Assert.Equal(projectInformation.ProjectId.ToString(), projectId);

            var actualProjectType = lastTelemetryEvent["NuGetProjectType"];

            Assert.NotNull(actualProjectType);
            Assert.IsType <NuGetProjectType>(actualProjectType);
            Assert.Equal(projectInformation.NuGetProjectType, actualProjectType);

            var installedPackageCount = lastTelemetryEvent["InstalledPackageCount"];

            Assert.NotNull(installedPackageCount);
            Assert.IsType <int>(installedPackageCount);
            Assert.Equal(projectInformation.InstalledPackageCount, installedPackageCount);

            var isPRUpgradable = lastTelemetryEvent["IsPRUpgradable"];

            Assert.NotNull(isPRUpgradable);
            Assert.IsType <bool>(isPRUpgradable);
            Assert.Equal(projectInformation.IsProjectPRUpgradable, isPRUpgradable);
        }
Exemple #3
0
        public void NuGetTelemetryService_EmitProjectInformation(NuGetProjectType projectType)
        {
            // Arrange
            var            telemetrySession   = new Mock <ITelemetrySession>();
            TelemetryEvent lastTelemetryEvent = null;

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

            var projectInformation = new ProjectTelemetryEvent(
                "3.5.0-beta2",
                "15e9591f-9391-4ddf-a246-ca9e0351277d",
                projectType,
                3);
            var target = new NuGetProjectTelemetryService(telemetrySession.Object);

            // Act
            target.EmitProjectInformation(projectInformation);

            // Assert
            telemetrySession.Verify(x => x.PostEvent(It.IsAny <TelemetryEvent>()), Times.Once);
            Assert.NotNull(lastTelemetryEvent);
            Assert.Equal("VS/NuGet/ProjectInformation", lastTelemetryEvent.Name);
            Assert.Equal(4, lastTelemetryEvent.Properties.Count);

            object nuGetVersion;

            Assert.True(lastTelemetryEvent.Properties.TryGetValue("VS.NuGet.NuGetVersion", out nuGetVersion));
            Assert.IsType <string>(nuGetVersion);
            Assert.Equal(projectInformation.NuGetVersion, nuGetVersion);

            object projectId;

            Assert.True(lastTelemetryEvent.Properties.TryGetValue("VS.NuGet.ProjectId", out projectId));
            Assert.IsType <string>(projectId);
            Assert.Equal(projectInformation.ProjectId.ToString(), projectId);

            object actualProjectType;

            Assert.True(lastTelemetryEvent.Properties.TryGetValue("VS.NuGet.NuGetProjectType", out actualProjectType));
            Assert.IsType <NuGetProjectType>(actualProjectType);
            Assert.Equal(projectInformation.NuGetProjectType, actualProjectType);

            object installedPackageCount;

            Assert.True(lastTelemetryEvent.Properties.TryGetValue("VS.NuGet.InstalledPackageCount", out installedPackageCount));
            Assert.IsType <int>(installedPackageCount);
            Assert.Equal(projectInformation.InstalledPackageCount, installedPackageCount);
        }