public void It_does_add_telemetry_when_no_firsttimeuse_values_run()
        {
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(true);

            Dictionary <string, double> measurements = new Dictionary <string, double>();
            var dotnetFirstTimeUseConfigurer         = new DotnetFirstTimeUseConfigurer(
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: false,
                    telemetryOptout: false,
                    addGlobalToolsToPath: false,
                    nologo: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object,
                measurements);

            dotnetFirstTimeUseConfigurer.Configure();

            measurements.Should().HaveCount(0);
            measurements.Should().NotContainKey("AddPackageExecutablePath Time");
            measurements.Should().NotContainKey("FirstTimeUseNotice Time");
            measurements.Should().NotContainKey("GenerateAspNetCertificate Time");
        }
예제 #2
0
        public void It_does_not_prime_the_cache_if_the_cache_sentinel_reports_Unauthorized()
        {
            _nugetCacheSentinelMock.Setup(n => n.UnauthorizedAccess).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #3
0
        private static void ConfigureDotNetForFirstTimeUse(
            INuGetCacheSentinel nugetCacheSentinel,
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
            CliFallbackFolderPathCalculator cliFallbackFolderPathCalculator)
        {
            using (PerfTrace.Current.CaptureTiming())
            {
                var nugetPackagesArchiver = new NuGetPackagesArchiver();
                var environmentProvider   = new EnvironmentProvider();
                var commandFactory        = new DotNetCommandFactory(alwaysRunOutOfProc: true);
                var nugetCachePrimer      = new NuGetCachePrimer(
                    nugetPackagesArchiver,
                    nugetCacheSentinel,
                    cliFallbackFolderPathCalculator);
                var dotnetConfigurer = new DotnetFirstTimeUseConfigurer(
                    nugetCachePrimer,
                    nugetCacheSentinel,
                    firstTimeUseNoticeSentinel,
                    environmentProvider,
                    Reporter.Output,
                    cliFallbackFolderPathCalculator.CliFallbackFolderPath);

                dotnetConfigurer.Configure();
            }
        }
예제 #4
0
        public void It_does_not_print_the_first_time_use_notice_when_the_user_has_set_the_DOTNET_PRINT_TELEMETRY_MESSAGE_environemnt_variable()
        {
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: false,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)), Times.Never);
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #5
0
        private static void ConfigureDotNetForFirstTimeUse(
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
            IAspNetCertificateSentinel aspNetCertificateSentinel,
            IFileSentinel toolPathSentinel,
            bool isDotnetBeingInvokedFromNativeInstaller,
            DotnetFirstRunConfiguration dotnetFirstRunConfiguration,
            IEnvironmentProvider environmentProvider)
        {
            using (PerfTrace.Current.CaptureTiming())
            {
                var environmentPath            = EnvironmentPathFactory.CreateEnvironmentPath(isDotnetBeingInvokedFromNativeInstaller, environmentProvider);
                var commandFactory             = new DotNetCommandFactory(alwaysRunOutOfProc: true);
                var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
                var dotnetConfigurer           = new DotnetFirstTimeUseConfigurer(
                    firstTimeUseNoticeSentinel,
                    aspNetCertificateSentinel,
                    aspnetCertificateGenerator,
                    toolPathSentinel,
                    dotnetFirstRunConfiguration,
                    Reporter.Output,
                    CliFolderPathCalculator.CliFallbackFolderPath,
                    environmentPath);

                dotnetConfigurer.Configure();

                if (isDotnetBeingInvokedFromNativeInstaller && RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    DotDefaultPathCorrector.Correct();
                }
            }
        }
예제 #6
0
        public void It_generates_the_aspnet_https_development_certificate_if_the_sentinel_does_not_exist()
        {
            _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)));
            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.NugetCachePrimeMessage)));
            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.AspNetCertificateInstalled)));
            _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Once);
        }
예제 #7
0
        public void It_prints_the_unauthorized_notice_if_the_cache_sentinel_reports_Unauthorized()
        {
            _nugetCacheSentinelMock.Setup(n => n.UnauthorizedAccess).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r =>
                                 r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)));
            _reporterMock.Verify(r =>
                                 r.WriteLine(It.Is <string>(str =>
                                                            str == string.Format(LocalizableStrings.UnauthorizedAccessMessage, CliFallbackFolderPath))));
            _reporterMock.Verify(
                r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.NugetCachePrimeMessage)),
                Times.Never);
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #8
0
파일: Program.cs 프로젝트: baronfel/sdk
        private static void ConfigureDotNetForFirstTimeUse(
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
            IAspNetCertificateSentinel aspNetCertificateSentinel,
            IFileSentinel toolPathSentinel,
            bool isDotnetBeingInvokedFromNativeInstaller,
            DotnetFirstRunConfiguration dotnetFirstRunConfiguration,
            IEnvironmentProvider environmentProvider,
            Dictionary <string, double> performanceMeasurements)
        {
            var environmentPath            = EnvironmentPathFactory.CreateEnvironmentPath(isDotnetBeingInvokedFromNativeInstaller, environmentProvider);
            var commandFactory             = new DotNetCommandFactory(alwaysRunOutOfProc: true);
            var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
            var dotnetConfigurer           = new DotnetFirstTimeUseConfigurer(
                firstTimeUseNoticeSentinel,
                aspNetCertificateSentinel,
                aspnetCertificateGenerator,
                toolPathSentinel,
                dotnetFirstRunConfiguration,
                Reporter.Output,
                CliFolderPathCalculator.CliFallbackFolderPath,
                environmentPath,
                performanceMeasurements);

            dotnetConfigurer.Configure();

            if (isDotnetBeingInvokedFromNativeInstaller && OperatingSystem.IsWindows())
            {
                DotDefaultPathCorrector.Correct();
            }
        }
예제 #9
0
        public void It_does_not_prime_the_cache_if_the_sentinel_does_not_exist_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environment_variable()
        {
            _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: true
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #10
0
        public void It_does_not_add_the_tool_path_to_the_environment_if_the_tool_path_sentinel_exists()
        {
            _toolPathSentinelMock.Setup(s => s.Exists()).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _toolPathSentinelMock.Verify(s => s.Create(), Times.Never);
            _pathAdderMock.Verify(p => p.AddPackageExecutablePathToUserPath(), Times.Never);
        }
예제 #11
0
        public void It_adds_the_tool_path_to_the_environment_if_the_tool_path_sentinel_does_not_exist()
        {
            _toolPathSentinelMock.Setup(s => s.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    telemetryOptout: false,
                    addGlobalToolsToPath: true,
                    nologo: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _toolPathSentinelMock.Verify(s => s.Create(), Times.Once);
            _pathAdderMock.Verify(p => p.AddPackageExecutablePathToUserPath(), Times.Once);
        }
예제 #12
0
        public void It_does_not_prime_the_cache_if_first_run_experience_is_already_happening()
        {
            _nugetCacheSentinelMock.Setup(n => n.InProgressSentinelAlreadyExists()).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #13
0
        private static void ConfigureDotNetForFirstTimeUse(
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
            IAspNetCertificateSentinel aspNetCertificateSentinel,
            IFileSentinel toolPathSentinel,
            bool hasSuperUserAccess,
            DotnetFirstRunConfiguration dotnetFirstRunConfiguration,
            IEnvironmentProvider environmentProvider)
        {
            using (PerfTrace.Current.CaptureTiming())
            {
                var environmentPath            = EnvironmentPathFactory.CreateEnvironmentPath(hasSuperUserAccess, environmentProvider);
                var commandFactory             = new DotNetCommandFactory(alwaysRunOutOfProc: true);
                var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
                var dotnetConfigurer           = new DotnetFirstTimeUseConfigurer(
                    firstTimeUseNoticeSentinel,
                    aspNetCertificateSentinel,
                    aspnetCertificateGenerator,
                    toolPathSentinel,
                    dotnetFirstRunConfiguration,
                    Reporter.Output,
                    CliFolderPathCalculator.CliFallbackFolderPath,
                    environmentPath);

                dotnetConfigurer.Configure();
            }
        }
예제 #14
0
        public void It_prints_the_telemetry_if_the_sentinel_does_not_exist()
        {
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: true,
                    telemetryOptout: false,
                    addGlobalToolsToPath: true,
                    nologo: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str.Contains(LocalizableStrings.FirstTimeMessageMoreInformation))));
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #15
0
        public void It_prints_the_unauthorized_notice_if_the_cache_sentinel_reports_Unauthorized()
        {
            _nugetCacheSentinelMock.Setup(n => n.UnauthorizedAccess).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdder.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r =>
                                 r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)));
            _reporterMock.Verify(r =>
                                 r.WriteLine(It.Is <string>(str =>
                                                            str == string.Format(LocalizableStrings.UnauthorizedAccessMessage, CliFallbackFolderPath))));
            _reporterMock.Verify(
                r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.NugetCachePrimeMessage)),
                Times.Never);
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #16
0
        public void It_generates_the_aspnet_https_development_certificate_if_the_sentinel_does_not_exist()
        {
            _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false);
            _environmentProviderMock.Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true))
            .Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)));
            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.NugetCachePrimeMessage)));
            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.AspNetCertificateInstalled)));
            _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Once);
        }
예제 #17
0
        public void It_prints_the_first_time_use_notice_if_the_cache_sentinel_exists_but_the_first_notice_sentinel_does_not()
        {
            _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(true);
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r =>
                                 r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)));
            _reporterMock.Verify(
                r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.NugetCachePrimeMessage)),
                Times.Never);
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #18
0
        private static void ConfigureDotNetForFirstTimeUse(
            INuGetCacheSentinel nugetCacheSentinel,
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel,
            IAspNetCertificateSentinel aspNetCertificateSentinel,
            CliFolderPathCalculator cliFolderPathCalculator,
            bool hasSuperUserAccess)
        {
            var environmentProvider = new EnvironmentProvider();

            using (PerfTrace.Current.CaptureTiming())
            {
                var nugetPackagesArchiver = new NuGetPackagesArchiver();
                var environmentPath       =
                    EnvironmentPathFactory.CreateEnvironmentPath(cliFolderPathCalculator, hasSuperUserAccess, environmentProvider);
                var commandFactory   = new DotNetCommandFactory(alwaysRunOutOfProc: true);
                var nugetCachePrimer = new NuGetCachePrimer(
                    nugetPackagesArchiver,
                    nugetCacheSentinel,
                    cliFolderPathCalculator);
                var aspnetCertificateGenerator = new AspNetCoreCertificateGenerator();
                var dotnetConfigurer           = new DotnetFirstTimeUseConfigurer(
                    nugetCachePrimer,
                    nugetCacheSentinel,
                    firstTimeUseNoticeSentinel,
                    aspNetCertificateSentinel,
                    aspnetCertificateGenerator,
                    environmentProvider,
                    Reporter.Output,
                    cliFolderPathCalculator.CliFallbackFolderPath,
                    environmentPath);

                dotnetConfigurer.Configure();
            }
        }
예제 #19
0
        public void It_does_not_generate_the_aspnet_https_development_certificate_when_the_user_has_set_the_DOTNET_GENERATE_ASPNET_CERTIFICATE_environment_variable()
        {
            _aspNetCertificateSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: false,
                    printTelemetryMessage: true,
                    skipFirstRunExperience: false
                ),
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.AspNetCertificateInstalled)), Times.Never);
            _aspNetCoreCertificateGeneratorMock.Verify(s => s.GenerateAspNetCoreDevelopmentCertificate(), Times.Never);
        }
        private Telemetry RunConfigUsingMocks(bool isInstallerRun)
        {
            // Assume the following objects set up are in sync with production behavior.
            // subject to future refactoring to de-dup with production code.

            var  _environmentProviderObject = _environmentProvider.Object;
            bool generateAspNetCertificate  =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true);
            bool skipFirstRunExperience =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false);
            bool telemetryOptout =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", false);

            IAspNetCertificateSentinel  aspNetCertificateSentinel;
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel;
            IFileSentinel toolPathSentinel;

            if (isInstallerRun)
            {
                aspNetCertificateSentinel  = new NoOpAspNetCertificateSentinel();
                firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel();
                toolPathSentinel           = new NoOpFileSentinel(exists: false);

                // When running through a native installer, we want the cache expansion to happen, so
                // we need to override this.
                skipFirstRunExperience = false;
            }
            else
            {
                aspNetCertificateSentinel  = _aspNetCertificateSentinelMock;
                firstTimeUseNoticeSentinel = _firstTimeUseNoticeSentinelMock;
                toolPathSentinel           = _toolPathSentinelMock;
            }

            var configurer = new DotnetFirstTimeUseConfigurer(
                firstTimeUseNoticeSentinel: firstTimeUseNoticeSentinel,
                aspNetCertificateSentinel: aspNetCertificateSentinel,
                aspNetCoreCertificateGenerator: _aspNetCoreCertificateGeneratorMock.Object,
                toolPathSentinel: toolPathSentinel,
                dotnetFirstRunConfiguration: new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: generateAspNetCertificate,
                    skipFirstRunExperience: skipFirstRunExperience,
                    telemetryOptout: telemetryOptout
                ),
                reporter: _reporterMock,
                cliFallbackFolderPath: CliFallbackFolderPath,
                pathAdder: _pathAdderMock.Object);

            configurer.Configure();

            return(new Telemetry(firstTimeUseNoticeSentinel,
                                 "test",
                                 environmentProvider: _environmentProviderObject,
                                 senderCount: 0));
        }
        private Telemetry RunConfigUsingMocks(bool isInstallerRun)
        {
            // Assume the following objects set up are in sync with production behavior.
            // subject to future refactoring to de-dup with production code.

            var  _environmentProviderObject = _environmentProvider.Object;
            bool generateAspNetCertificate  =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_GENERATE_ASPNET_CERTIFICATE", true);
            bool telemetryOptout =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_CLI_TELEMETRY_OPTOUT", false);
            bool addGlobalToolsToPath =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_ADD_GLOBAL_TOOLS_TO_PATH", defaultValue: true);
            bool nologo =
                _environmentProviderObject.GetEnvironmentVariableAsBool("DOTNET_NOLOGO", defaultValue: false);

            IAspNetCertificateSentinel  aspNetCertificateSentinel;
            IFirstTimeUseNoticeSentinel firstTimeUseNoticeSentinel;
            IFileSentinel toolPathSentinel;

            if (isInstallerRun)
            {
                aspNetCertificateSentinel  = new NoOpAspNetCertificateSentinel();
                firstTimeUseNoticeSentinel = new NoOpFirstTimeUseNoticeSentinel();
                toolPathSentinel           = new NoOpFileSentinel(exists: false);
            }
            else
            {
                aspNetCertificateSentinel  = _aspNetCertificateSentinelMock;
                firstTimeUseNoticeSentinel = _firstTimeUseNoticeSentinelMock;
                toolPathSentinel           = _toolPathSentinelMock;
            }

            var configurer = new DotnetFirstTimeUseConfigurer(
                firstTimeUseNoticeSentinel: firstTimeUseNoticeSentinel,
                aspNetCertificateSentinel: aspNetCertificateSentinel,
                aspNetCoreCertificateGenerator: _aspNetCoreCertificateGeneratorMock.Object,
                toolPathSentinel: toolPathSentinel,
                dotnetFirstRunConfiguration: new DotnetFirstRunConfiguration
                (
                    generateAspNetCertificate: generateAspNetCertificate,
                    telemetryOptout: telemetryOptout,
                    addGlobalToolsToPath: addGlobalToolsToPath,
                    nologo: nologo
                ),
                reporter: _reporterMock,
                cliFallbackFolderPath: CliFallbackFolderPath,
                pathAdder: _pathAdderMock.Object);

            configurer.Configure();

            return(new Telemetry(firstTimeUseNoticeSentinel,
                                 "test",
                                 environmentProvider: _environmentProviderObject,
                                 senderCount: 0));
        }
예제 #22
0
        public void It_primes_the_cache_if_the_sentinel_does_not_exist()
        {
            _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _environmentProviderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Once);
        }
예제 #23
0
        public void It_does_not_prime_the_cache_if_first_run_experience_is_already_happening()
        {
            _nugetCacheSentinelMock.Setup(n => n.InProgressSentinelAlreadyExists()).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _environmentProviderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #24
0
        public void It_does_not_prime_the_cache_if_the_cache_sentinel_reports_Unauthorized()
        {
            _nugetCacheSentinelMock.Setup(n => n.UnauthorizedAccess).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #25
0
        public void It_does_not_prime_the_cache_if_the_sentinel_exists_but_the_user_has_set_the_DOTNET_SKIP_FIRST_TIME_EXPERIENCE_environemnt_variable()
        {
            _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(false);
            _environmentProviderMock
            .Setup(e => e.GetEnvironmentVariableAsBool("DOTNET_SKIP_FIRST_TIME_EXPERIENCE", false))
            .Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _environmentProviderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #26
0
        public void It_does_not_prime_the_cache_if_cache_is_missing()
        {
            _nugetCachePrimerMock.Setup(n => n.SkipPrimingTheCache()).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdder.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _nugetCachePrimerMock.Verify(r => r.PrimeCache(), Times.Never);
        }
예제 #27
0
        public void It_prints_the_telemetry_if_the_sentinel_does_not_exist()
        {
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str.StartsWith("Welcome to .NET Core!"))));
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #28
0
        public void It_does_not_print_the_first_time_use_notice_if_the_sentinel_exists()
        {
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(true);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath);

            dotnetFirstTimeUseConfigurer.Configure();

            _reporterMock.Verify(r => r.WriteLine(It.Is <string>(str => str == LocalizableStrings.FirstTimeWelcomeMessage)), Times.Never);
            _reporterMock.Verify(r => r.Write(It.IsAny <string>()), Times.Never);
        }
예제 #29
0
        public void It_adds_the_tool_path_to_the_environment_if_the_first_run_experience_is_not_skipped()
        {
            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                _nugetCacheSentinelMock.Object,
                _firstTimeUseNoticeSentinelMock.Object,
                _aspNetCertificateSentinelMock.Object,
                _aspNetCoreCertificateGeneratorMock.Object,
                _toolPathSentinelMock.Object,
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdderMock.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _pathAdderMock.Verify(p => p.AddPackageExecutablePathToUserPath(), Times.Once);
        }
예제 #30
0
        public void It_adds_executable_package_path_to_environment_path_when_the_first_notice_sentinel_does_not_exist()
        {
            _nugetCacheSentinelMock.Setup(n => n.Exists()).Returns(true);
            _firstTimeUseNoticeSentinelMock.Setup(n => n.Exists()).Returns(false);

            var dotnetFirstTimeUseConfigurer = new DotnetFirstTimeUseConfigurer(
                _nugetCachePrimerMock.Object,
                new FakeCreateWillExistNuGetCacheSentinel(false, true),
                new FakeCreateWillExistFirstTimeUseNoticeSentinel(false),
                _environmentProviderMock.Object,
                _reporterMock.Object,
                CliFallbackFolderPath,
                _pathAdder.Object);

            dotnetFirstTimeUseConfigurer.Configure();

            _pathAdder.Verify(p => p.AddPackageExecutablePathToUserPath(), Times.AtLeastOnce);
        }