示例#1
0
        public async Task PackageIndexFile_RemoveAllPackagesVerifyFileRemoved()
        {
            using (var testContext = new SleetTestContext())
            {
                var inputA = TestUtility.GetPackageInput("a", testContext);
                var inputB = TestUtility.GetPackageInput("b", testContext);

                var file = new PackageIndexFile(testContext.SleetContext, "test.json", persistWhenEmpty: false);
                await file.AddPackageAsync(inputA);

                await file.AddPackageAsync(inputB);

                await file.RemovePackageAsync(inputA.Identity);

                await file.RemovePackageAsync(inputB.Identity);

                await testContext.Commit();

                var packages = await file.GetPackagesAsync();

                var path = Path.Combine(testContext.Target, "test.json");

                File.Exists(path).Should().BeFalse();
            }
        }
示例#2
0
        public async Task InitWithEnvVarsWithNonSleetNetConfigVerifyFeedOutput()
        {
            using (var testContext = new SleetTestContext())
            {
                var dir  = Path.Combine(testContext.Root, "sub");
                var args = $"init -c none";

                Directory.CreateDirectory(dir);

                File.WriteAllText(Path.Combine(dir, Config.FileName), @"
[config]
    editor = code
");

                var envVars = new Dictionary <string, string>()
                {
                    { "SLEET_FEED_TYPE", "local" },
                    { "SLEET_FEED_PATH", dir }
                };

                var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, args, envVars);

                result.Success.Should().BeTrue();
                File.Exists(Path.Combine(dir, "sleet.settings.json")).Should().BeTrue();
            }
        }
示例#3
0
        public static PackageInput GetPackageInput(string id, SleetTestContext testContext, bool isSymbols)
        {
            var testPackage = new TestNupkg(id, "1.0.0");

            testPackage.Nuspec.IsSymbolPackage = isSymbols;
            var zipFile = testPackage.Save(testContext.Packages);

            return(testContext.GetPackageInput(zipFile));
        }
示例#4
0
        public async Task GivenABadCommandVerifyFailure(string arguments)
        {
            using (var testContext = new SleetTestContext())
            {
                var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, testContext.Root, arguments);

                result.Success.Should().BeFalse();
            }
        }
示例#5
0
        public async Task RunToolWithCreateConfigVerifySuccess()
        {
            using (var testContext = new SleetTestContext())
            {
                var dir = Path.Combine(testContext.Root, "project");
                Directory.CreateDirectory(dir);

                var dotnetExe    = GetDotnetPath();
                var exeFile      = new FileInfo(dotnetExe);
                var nupkgsFolder = Path.Combine(exeFile.Directory.Parent.FullName, "artifacts", "nupkgs");

                var sleetNupkg = LocalFolderUtility.GetPackagesV2(nupkgsFolder, "Sleet", NullLogger.Instance)
                                 .OrderByDescending(e => e.Nuspec.GetVersion())
                                 .First();

                var sleetVersion = sleetNupkg.Nuspec.GetVersion().ToNormalizedString();

                var result = await CmdRunner.RunAsync(dotnetExe, dir, "new classlib");

                result.Success.Should().BeTrue();

                var projectPath = Path.Combine(dir, "project.csproj");

                var pathContext  = NuGetPathContext.Create(dir);
                var pathResolver = new FallbackPackagePathResolver(pathContext);

                // Delete restore assets file
                var toolInstallPath = Path.Combine(pathContext.UserPackageFolder, ".tools", "sleet");
                Delete(new DirectoryInfo(toolInstallPath));

                // Delete the tool package itself if it exists
                var toolPackagePath = Path.Combine(pathContext.UserPackageFolder, "sleet", sleetVersion);
                Delete(new DirectoryInfo(toolPackagePath));

                // Add a reference to the tool
                var xml = XDocument.Load(projectPath);
                xml.Root.Add(new XElement(XName.Get("ItemGroup"),
                                          new XElement(XName.Get("DotNetCliToolReference"),
                                                       new XAttribute("Include", "Sleet"),
                                                       new XAttribute("Version", sleetVersion))));
                xml.Save(projectPath);

                // Restore the tool
                result = await CmdRunner.RunAsync(dotnetExe, dir, $"restore --source {nupkgsFolder}");

                result.Success.Should().BeTrue();

                // Run the tool
                result = await CmdRunner.RunAsync(dotnetExe, dir, $"sleet createconfig");

                result.Success.Should().BeTrue();

                File.Exists(Path.Combine(dir, "sleet.json")).Should().BeTrue();
            }
        }
示例#6
0
        public async Task RunAllCommandsWithInputProperties()
        {
            using (var packagesFolder = new TestFolder())
                using (var testContext = new SleetTestContext())
                {
                    var testPackage = new TestNupkg("packageA", "1.0.0");
                    var zipFile     = testPackage.Save(packagesFolder.Root);
                    var dir         = Path.Combine(testContext.Root, "sub");
                    Directory.CreateDirectory(dir);

                    var extraArgs = $" -p SLEET_FEED_TYPE=local -p \"SLEET_FEED_PATH={dir}\" -c none";
                    var output    = Path.Combine(testContext.Root, "out");
                    Directory.CreateDirectory(output);

                    var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, "init" + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"push {zipFile.FullName} " + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"delete -i packageA " + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"download -o {output} " + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"stats" + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"validate" + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"recreate" + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"feed-settings --get-all" + extraArgs);

                    result.Success.Should().BeTrue();

                    result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, $"destroy" + extraArgs);

                    result.Success.Should().BeTrue();
                }
        }
示例#7
0
        public async Task PackageIndexFile_InitANewFileVerifyCreated()
        {
            using (var testContext = new SleetTestContext())
            {
                var file = new PackageIndexFile(testContext.SleetContext, "test.json", persistWhenEmpty: true);
                await file.InitAsync();

                await testContext.SleetContext.Source.Commit(testContext.SleetContext.Log, testContext.SleetContext.Token);

                var path = Path.Combine(testContext.Target, "test.json");

                File.Exists(path).Should().BeTrue();
            }
        }
示例#8
0
        public async Task InitWithPropertiesVerifyFeedOutput()
        {
            using (var testContext = new SleetTestContext())
            {
                var dir  = Path.Combine(testContext.Root, "sub");
                var args = $"init -p SLEET_FEED_TYPE=local -p \"SLEET_FEED_PATH={dir}\" -c none";

                Directory.CreateDirectory(dir);

                var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, args);

                result.Success.Should().BeTrue();
                File.Exists(Path.Combine(dir, "sleet.settings.json")).Should().BeTrue();
            }
        }
示例#9
0
        public async Task RunCreateConfigVerifySuccess()
        {
            using (var testContext = new SleetTestContext())
            {
                var args = "createconfig";

                var dir = Path.Combine(testContext.Root, "sub");
                Directory.CreateDirectory(dir);

                var result = await CmdRunner.RunAsync(ExeUtils.SleetExePath, dir, args);

                result.Success.Should().BeTrue();
                File.Exists(Path.Combine(dir, "sleet.json")).Should().BeTrue();
            }
        }
示例#10
0
        public async Task PackageIndexFile_AddPackageVerifyAdd()
        {
            using (var testContext = new SleetTestContext())
            {
                var input = TestUtility.GetPackageInput("a", testContext);

                var file = new PackageIndexFile(testContext.SleetContext, "test.json", persistWhenEmpty: true);
                await file.AddPackageAsync(input);

                var packages = await file.GetPackagesAsync();

                packages.ShouldBeEquivalentTo(new[] { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")) });

                var symbols = await file.GetSymbolsPackagesAsync();

                symbols.Should().BeEmpty();
            }
        }
示例#11
0
        public async Task InstallToolVerifySuccess()
        {
            using (var testContext = new SleetTestContext())
            {
                var dir = Path.Combine(testContext.Root, "tooloutput");
                Directory.CreateDirectory(dir);

                var dotnetExe    = GetDotnetPath();
                var exeFile      = new FileInfo(dotnetExe);
                var nupkgsFolder = Path.Combine(exeFile.Directory.Parent.FullName, "artifacts", "nupkgs");

                var packages = LocalFolderUtility.GetPackagesV2(nupkgsFolder, "Sleet", NullLogger.Instance).ToList();

                if (packages.Count < 1)
                {
                    throw new Exception("Run build.ps1 first to create the nupkgs.");
                }

                var sleetNupkg = packages
                                 .OrderByDescending(e => e.Nuspec.GetVersion())
                                 .First();

                var sleetVersion = sleetNupkg.Nuspec.GetVersion().ToNormalizedString();

                var result = await CmdRunner.RunAsync(dotnetExe, testContext.Root, $"tool install sleet --version {sleetVersion} --add-source {nupkgsFolder} --tool-path {dir}");

                result.Success.Should().BeTrue(result.AllOutput);

                var sleetDllPath = Path.Combine(dir, ".store", "sleet", sleetVersion, "sleet", sleetVersion, "tools", "net5.0", "any", "Sleet.dll");

                if (!File.Exists(sleetDllPath))
                {
                    throw new Exception("Tool did not install to the expected location: " + sleetDllPath);
                }

                // Run the tool

                result = await CmdRunner.RunAsync(dotnetExe, dir, $"{sleetDllPath} createconfig");

                result.Success.Should().BeTrue(result.AllOutput);

                File.Exists(Path.Combine(dir, "sleet.json")).Should().BeTrue("sleet should have generated the config file");
            }
        }
示例#12
0
 public static PackageInput GetPackageInput(string id, SleetTestContext testContext)
 {
     return(GetPackageInput(id, testContext, isSymbols: false));
 }