public async void InstallsForRealWithSpecificVersion()
        {
            var platform = DotNetPlatform.Windows;
            var arch     = DotNetArchitecture.x64;
            var version  = "2.1.4";

            var parms     = new DotNetDistributionParameters(InstallDir, DotNetPlatform.Windows, DotNetArchitecture.x64, version);
            var installer = new DotNetCoreInstaller();
            await installer.InstallStandalone(parms);

            var expectedInstallPath = Path.Combine(InstallDir, "shared", "Microsoft.NETCore.App", version);

            Assert.True(Directory.Exists(expectedInstallPath));
        }
        public async void InstallsForRealWithLatestVersion()
        {
            var platform = DotNetPlatform.Windows;
            var arch     = DotNetArchitecture.x64;
            var version  = "2.1";

            var parms     = new DotNetDistributionParameters(InstallDir, DotNetPlatform.Windows, DotNetArchitecture.x64, version);
            var installer = new DotNetCoreInstaller();
            await installer.InstallStandalone(parms);

            var matchingDirectories = Directory.GetDirectories(Path.Combine(InstallDir, "shared", "Microsoft.NETCore.App"), version + "*");

            Assert.True(matchingDirectories.Length == 1 && Directory.Exists(matchingDirectories[0]));
        }
        private async Task InstallsMocked(
            DotNetDistributionParameters parms,
            bool earlyExit = false, bool forcedOverwrite = false, bool failExtract = false, bool expectsLatestVersionLookup = false)
        {
            var platform = parms.Platform;
            var arch     = parms.Architecture;
            var version  = parms.Version;

            var mockDownloader = CreateMockDownloader();
            var mockExtractor  = CreateMockExtractor();

            var mockFilesystem = CreateMockFilesystem();

            var mockFile      = Mock.Get(mockFilesystem.Object.File);
            var mockDirectory = Mock.Get(mockFilesystem.Object.Directory);

            var installer = new DotNetCoreInstaller(mockDownloader.Object, mockExtractor.Object, mockFilesystem.Object);

            var archiveExt = (parms.Platform == DotNetPlatform.Windows) ? "zip" : "tar.gz";

            var assetDir            = (parms.Runtime == DotNetRuntime.NETCore) ? "Microsoft.NETCore.App" : "Microsoft.AspNetCore.App";
            var expectedPackageRoot = Path.Combine(InstallDir, "shared", assetDir);

            mockDirectory.Setup(d => d.Exists(expectedPackageRoot)).Returns(true); // Just test the true case; the false case is uninteresting and the code is covered by other tests anyway.
            mockDirectory.Setup(d => d.GetDirectories(expectedPackageRoot, parms.Version + "*")).Returns(
                earlyExit ? new [] { version + ".3" } : new string[0]
                );

            if (expectsLatestVersionLookup)
            {
                var expectedLatestUri = (parms.Runtime == DotNetRuntime.NETCore)
                    ? new Uri($"{DotNetDistributionParameters.DefaultUncachedFeed}/Runtime/{version}/latest.version")
                    : new Uri($"{DotNetDistributionParameters.DefaultUncachedFeed}/aspnetcore/Runtime/{version}/latest.version");

                mockDownloader.Setup(d => d(expectedLatestUri, It.IsAny <string>())).Returns(Task.CompletedTask); // Download latest.version File

                version = version + ".3";                                                                         // Pretend that the latest of, e.g. 2.2, is 2.2.3.

                mockFile.Setup(f => f.ReadAllText(It.IsAny <string>())).Returns($"some-hash\n{version}");
            }

            var expectedUri = (parms.Runtime == DotNetRuntime.NETCore)
                ? new Uri($"{DotNetDistributionParameters.DefaultCachedFeed}/Runtime/{version}/dotnet-runtime-{version}-{platform}-{arch}.{archiveExt}")
                : new Uri($"{DotNetDistributionParameters.DefaultCachedFeed}/aspnetcore/Runtime/{version}/aspnetcore-runtime-{version}-{platform}-{arch}.{archiveExt}");
            var expectedInstallPath = Path.Combine(InstallDir, "shared", assetDir, version);

            if (earlyExit)
            {
                mockDirectory.Setup(d => d.Exists(expectedInstallPath)).ReturnsInOrder(true);                               // Checking for version directory.
            }
            else
            {
                bool initiallyPresent = forcedOverwrite ? true : false;
                bool finallyPresent   = failExtract ? false : true;

                mockDirectory.Setup(d => d.Exists(expectedInstallPath)).ReturnsInOrder(initiallyPresent, finallyPresent);   // Checking for version directory.
                mockDirectory.Setup(d => d.CreateDirectory(parms.InstallDir)).Returns(value: null);                         // Creating the root install dir.
                mockDownloader.Setup(d => d(expectedUri, It.IsAny <string>())).Returns(Task.CompletedTask);                 // Download
                mockExtractor.Setup(e => e(It.IsAny <string>(), parms.InstallDir, forcedOverwrite))                         // Extract
                .Returns(Task.CompletedTask);
                mockFile.Setup(f => f.Delete(It.IsAny <string>()));                                                         // Deleting the temporary zip file.
            }

            await installer.InstallStandalone(parms);

            mockDownloader.VerifyAll();
            mockExtractor.VerifyAll();
        }