public void As_soon_as_it_gets_created_it_tries_to_get_handle_of_the_InProgress_sentinel()
        {
            var fileMock = new FileMock();
            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);

            fileMock.OpenFileWithRightParamsCalled.Should().BeTrue();
        }
        public void It_returns_false_to_the_in_progress_sentinel_already_exists_when_it_succeeds_in_getting_a_handle_to_it()
        {
            var fileMock = new FileMock();
            fileMock.InProgressSentinel = new MemoryStream();
            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);

            nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeFalse();
        }
        public void It_returns_true_to_the_in_progress_sentinel_already_exists_when_it_fails_to_get_a_handle_to_it()
        {
            var fileMock = new FileMock();
            fileMock.InProgressSentinel = null;
            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock);

            nugetCacheSentinel.InProgressSentinelAlreadyExists().Should().BeTrue();
        }
        public void It_returns_true_if_the_sentinel_exists()
        {
            _fileSystemMockBuilder.AddFiles(NUGET_CACHE_PATH, NuGetCacheSentinel.SENTINEL);

            var fileSystemMock = _fileSystemMockBuilder.Build();

            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);

            nugetCacheSentinel.Exists().Should().BeTrue();
        }
        public void It_disposes_of_the_handle_to_the_InProgressSentinel_when_NuGetCacheSentinel_is_disposed()
        {
            var mockStream = new MockStream();
            var fileMock = new FileMock();
            fileMock.InProgressSentinel = mockStream;
            using (var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileMock))
            {}

            mockStream.IsDisposed.Should().BeTrue();
        }
Example #6
0
        internal static int ProcessArgs(string[] args, ITelemetry telemetryClient = null)
        {
            // CommandLineApplication is a bit restrictive, so we parse things ourselves here. Individual apps should use CLA.

            bool? verbose = null;
            var success = true;
            var command = string.Empty;
            var lastArg = 0;
            using (INuGetCacheSentinel nugetCacheSentinel = new NuGetCacheSentinel())
            {
                for (; lastArg < args.Length; lastArg++)
                {
                    if (IsArg(args[lastArg], "v", "verbose"))
                    {
                        verbose = true;
                    }
                    else if (IsArg(args[lastArg], "version"))
                    {
                        PrintVersion();
                        return 0;
                    }
                    else if (IsArg(args[lastArg], "info"))
                    {
                        PrintInfo();
                        return 0;
                    }
                    else if (IsArg(args[lastArg], "h", "help"))
                    {
                        HelpCommand.PrintHelp();
                        return 0;
                    }
                    else if (args[lastArg].StartsWith("-"))
                    {
                        Reporter.Error.WriteLine($"Unknown option: {args[lastArg]}");
                        success = false;
                    }
                    else
                    {
                        ConfigureDotNetForFirstTimeUse(nugetCacheSentinel);

                        // It's the command, and we're done!
                        command = args[lastArg];
                        break;
                    }
                }
                if (!success)
                {
                    HelpCommand.PrintHelp();
                    return 1;
                }

                if (telemetryClient == null)
                {
                    telemetryClient = new Telemetry(nugetCacheSentinel);
                }
            }

            var appArgs = (lastArg + 1) >= args.Length ? Enumerable.Empty<string>() : args.Skip(lastArg + 1).ToArray();

            if (verbose.HasValue)
            {
                Environment.SetEnvironmentVariable(CommandContext.Variables.Verbose, verbose.ToString());
                Console.WriteLine($"Telemetry is: {(telemetryClient.Enabled ? "Enabled" : "Disabled")}");
            }

            if (string.IsNullOrEmpty(command))
            {
                command = "help";
            }

            telemetryClient.TrackEvent(command, null, null);

            int exitCode;
            Func<string[], int> builtIn;
            if (s_builtIns.TryGetValue(command, out builtIn))
            {
                exitCode = builtIn(appArgs.ToArray());
            }
            else
            {
                CommandResult result = Command.Create("dotnet-" + command, appArgs, FrameworkConstants.CommonFrameworks.NetStandardApp15)
                    .Execute();
                exitCode = result.ExitCode;
            }

            return exitCode;

        }
        public void It_creates_the_sentinel_in_the_nuget_cache_path_if_it_does_not_exist_already()
        {
            var fileSystemMock = _fileSystemMockBuilder.Build();
            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);

            nugetCacheSentinel.Exists().Should().BeFalse();

            nugetCacheSentinel.CreateIfNotExists();

            nugetCacheSentinel.Exists().Should().BeTrue();
        }
        public void It_returns_false_if_the_sentinel_does_not_exist()
        {
            var fileSystemMock = _fileSystemMockBuilder.Build();

            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);

            nugetCacheSentinel.Exists().Should().BeFalse();
        }
        public void It_does_not_create_the_sentinel_again_if_it_already_exists_in_the_nuget_cache_path()
        {
            const string contentToValidateSentinalWasNotReplaced = "some string";
            var sentinel = Path.Combine(NUGET_CACHE_PATH, NuGetCacheSentinel.SENTINEL);
            _fileSystemMockBuilder.AddFile(sentinel, contentToValidateSentinalWasNotReplaced);

            var fileSystemMock = _fileSystemMockBuilder.Build();

            var nugetCacheSentinel = new NuGetCacheSentinel(NUGET_CACHE_PATH, fileSystemMock.File);

            nugetCacheSentinel.Exists().Should().BeTrue();

            nugetCacheSentinel.CreateIfNotExists();

            fileSystemMock.File.ReadAllText(sentinel).Should().Be(contentToValidateSentinalWasNotReplaced);
        }