public async Task CatalogTest_CreatePackageDetails_Minimal() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { // Arrange var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; var catalog = new Catalog(context); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); var nupkgUri = UriUtility.CreateUri("http://tempuri.org/flatcontainer/packageA/1.0.0/packageA.1.0.0.nupkg"); // Act var actual = await CatalogUtility.CreatePackageDetailsAsync(input, catalog.CatalogBaseURI, nupkgUri, context.CommitId, writeFileList : true); var dependencyGroups = actual["dependencyGroups"] as JArray; var frameworkAssemblyGroups = actual["frameworkAssemblyGroup"] as JArray; var tags = actual["tags"] as JArray; // Assert Assert.EndsWith(".json", actual["@id"].ToString()); Assert.Equal(string.Empty, actual["authors"].ToString()); Assert.Equal(string.Empty, actual["copyright"].ToString()); Assert.Equal(string.Empty, actual["description"].ToString()); Assert.Equal(string.Empty, actual["iconUrl"].ToString()); Assert.Equal(string.Empty, actual["licenseUrl"].ToString()); Assert.Null(actual["minClientVersion"]); Assert.Equal(string.Empty, actual["projectUrl"].ToString()); Assert.False(actual["requireLicenseAcceptance"].ToObject <bool>()); Assert.Null(actual["title"]); Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString()); Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString()); Assert.EndsWith(".nupkg", actual["packageContent"].ToString()); Assert.Empty(dependencyGroups); Assert.Empty(frameworkAssemblyGroups); Assert.Empty(tags); } } }
public async Task Command_ContentFilesCommand_Multiple() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "nuspec", "contentfiles", "add", zipFile.FullName, "--include", "**/*.*" }, log); exitCode = await Program.MainCore(new[] { "nuspec", "contentfiles", "add", zipFile.FullName, "--include", "**/*.txt" }, log); var nuspec = GetNuspec(zipFile.FullName); // Assert Assert.Equal(0, exitCode); Assert.Equal(2, nuspec.GetContentFiles().Count()); } }
public async Task Command_ReleaseCommand_NoCollisionOnNewVersionWhenSymbols() { using (var workingDir = new TestFolder()) { // Arrange var testPackageA1 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var zipFileA1 = testPackageA1.Save(workingDir.Root); var symbolsPath = zipFileA1.FullName.Replace(".nupkg", ".symbols.nupkg"); File.Copy(zipFileA1.FullName, symbolsPath); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "release", workingDir.Root, "-n", "3.0.0" }, log); // Assert Assert.Equal(0, exitCode); var nuspecA1 = GetNuspec(Path.Combine(workingDir.Root, "a.3.0.0.nupkg")); var nuspecA2 = GetNuspec(Path.Combine(workingDir.Root, "a.3.0.0.symbols.nupkg")); Assert.Equal("3.0.0", nuspecA1.GetVersion().ToNormalizedString()); Assert.Equal("3.0.0", nuspecA2.GetVersion().ToNormalizedString()); } }
public async Task Command_VersionCommand_MatchOnDirectory() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0-beta.1.2" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "version", workingDir.Root }, log); // Assert Assert.Equal(0, exitCode); Assert.Equal("1.0.0-beta.1.2", string.Join("|", log.Messages)); } }
public async Task Symbols_AddSymbolsPackageAndValidateVerifyNoFailures() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var testPackage = new TestNupkg("a", "1.0.0"); testPackage.Files.Clear(); testPackage.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); testPackage.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); testPackage.Nuspec.IsSymbolPackage = true; var zipFile = testPackage.Save(testContext.Packages); var packageInput = testContext.GetPackageInput(zipFile); var service = new Symbols(context); await service.AddSymbolsPackageAsync(packageInput); // Validate var messages = await service.ValidateAsync(); var hasErrors = messages.Any(e => e.Level == LogLevel.Error); hasErrors.Should().BeFalse(); } }
public async Task Command_IdCommand() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "id", zipFile.FullName }, log); // Assert Assert.Equal(0, exitCode); Assert.Equal("a", string.Join("|", log.Messages)); } }
public async Task GivenAStorageAccountVerifyPushSucceeds() { using (var packagesFolder = new TestFolder()) using (var testContext = new AmazonS3TestContext()) { await testContext.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); var result = await InitCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, enableCatalog : true, enableSymbols : true, log : testContext.Logger, token : CancellationToken.None); result &= await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); } }
public async Task Command_NuspecEditCommand() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "nuspec", "edit", zipFile.FullName, "-p", "version", "-s", "2.0.0-beta" }, log); exitCode += await Program.MainCore(new[] { "nuspec", "show", zipFile.FullName }, log); // Assert Assert.Equal(0, exitCode); Assert.Contains("<version>2.0.0-beta</version>", string.Join("|", log.Messages)); } }
public async Task Command_ContentFilesCommand() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "nuspec", "contentfiles", "add", zipFile.FullName, "--include", "**/*.*", "--exclude", "**/*.txt", "--build-action", "none", "--copy-to-output", "true", "--flatten", "true" }, log); var nuspec = GetNuspec(zipFile.FullName); // Assert Assert.Equal(0, exitCode); Assert.Equal("none", nuspec.GetContentFiles().Single().BuildAction); Assert.True(nuspec.GetContentFiles().Single().CopyToOutput); Assert.Equal("**/*.txt", nuspec.GetContentFiles().Single().Exclude); Assert.Equal("**/*.*", nuspec.GetContentFiles().Single().Include); Assert.True(nuspec.GetContentFiles().Single().Flatten); } }
public async Task GivenPushCreatesAContainerVerifyNuGetCanRead() { using (var packagesFolder = new TestFolder()) using (var testContext = new AzureTestContext()) using (var sourceContext = new SourceCacheContext()) { // Skip creation and allow it to be done during push. testContext.CreateContainerOnInit = false; await testContext.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); var result = await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); // Read the feed with NuGet.Protocol var feedIndex = $"{testContext.FileSystem.Root.AbsoluteUri}index.json"; var repo = Repository.Factory.GetCoreV3(feedIndex); var resource = await repo.GetResourceAsync <FindPackageByIdResource>(CancellationToken.None); var packageResults = (await resource.GetAllVersionsAsync("packageA", sourceContext, NullLogger.Instance, CancellationToken.None)).ToList(); packageResults.Count.Should().Be(1); packageResults[0].ToIdentityString().Should().Be("1.0.0"); await testContext.CleanupAsync(); } }
public async Task GivenThatIWantToDestroyAFeedVerifyAFeedWithNupkgsSucceeds() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) using (var cache2 = new LocalCache()) using (var outputFolder = new TestFolder()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var root = new DirectoryInfo(target); await InitCommand.RunAsync(settings, fileSystem, enableCatalog : true, enableSymbols : true, log : log, token : CancellationToken.None); var packageA = new TestNupkg("a", "1.0"); var packageB = new TestNupkg("b", "2.0.0-beta+blah"); packageA.Save(packagesFolder.Root); packageB.Save(packagesFolder.Root); await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log); var success = await DestroyCommand.RunAsync(settings, fileSystem2, log); var files = root.GetFiles("*", SearchOption.AllDirectories); var dirs = root.GetDirectories(); success.ShouldBeEquivalentTo(true, "the command should exit without errors"); files.Length.ShouldBeEquivalentTo(0, "all files should be gone"); dirs.Length.ShouldBeEquivalentTo(0, "all directories should be gone"); } }
// Add a.1.0.0.nupkg and a.symbols.1.0.0.nupkg private static async Task AddBasicPackagesAsync(SleetTestContext testContext, Symbols service) { var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); var symPkgA = new TestNupkg("a", "1.0.0"); symPkgA.Files.Clear(); symPkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); symPkgA.AddFile("lib/net45/a.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); symPkgA.Nuspec.IsSymbolPackage = true; var pkgAZip = pkgA.Save(testContext.Packages); var pkgAInput = testContext.GetPackageInput(pkgAZip); var symPkgAZip = symPkgA.Save(testContext.Packages); var symPkgAInput = testContext.GetPackageInput(symPkgAZip); await service.AddPackageAsync(pkgAInput); await service.AddSymbolsPackageAsync(symPkgAInput); }
public async Task GivenACatalogVerifyPackagesShownFromList() { // Arrange using (var cache = new LocalCache()) using (var cacheContext = new SourceCacheContext()) using (var workingDir = new TestFolder()) { var beforeDate = DateTimeOffset.UtcNow; var catalogLog = new TestLogger(); var log = new TestLogger(); var baseUri = Sleet.UriUtility.CreateUri("https://localhost:8080/testFeed/"); var feedFolder = Path.Combine(workingDir, "feed"); var nupkgsFolder = Path.Combine(workingDir, "nupkgs"); var nupkgsOutFolder = Path.Combine(workingDir, "nupkgsout"); Directory.CreateDirectory(feedFolder); Directory.CreateDirectory(nupkgsFolder); Directory.CreateDirectory(nupkgsOutFolder); var packageA = new TestNupkg("a", "1.0.0"); TestNupkg.Save(nupkgsFolder, packageA); await CatalogReaderTestHelpers.CreateCatalogAsync(workingDir, feedFolder, nupkgsFolder, baseUri, catalogLog); var feedUri = Sleet.UriUtility.CreateUri(baseUri.AbsoluteUri + "index.json"); var httpSource = CatalogReaderTestHelpers.GetHttpSource(cache, feedFolder, baseUri); var args = new string[] { "list", feedUri.AbsoluteUri }; var exitCode = await NuGetMirror.Program.MainCore(args, httpSource, log); exitCode.Should().Be(0); log.GetMessages().Should().Contain("a 1.0.0"); } }
public async Task GivenAStorageAccountWithNoContainerVerifyPushSucceeds() { using (var packagesFolder = new TestFolder()) using (var testContext = new AmazonS3TestContext()) { // Skip creation and allow it to be done during push. testContext.CreateBucketOnInit = false; await testContext.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); var result = await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); } }
public async Task BadgeFile_VerifyBadgesUpdatedAfterDeleteAll() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { BadgesEnabled = true } }; // Initial packages var identities = new HashSet <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("2.0.0")) }; foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); } // Push await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); // Remove await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "a", "2.0.0", "test", true, context.Log); // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); validateOutput.Should().BeTrue(); // read output var stablePath = Path.Combine(target.Root, "badges/v/a.svg"); var prePath = Path.Combine(target.Root, "badges/vpre/a.svg"); File.Exists(stablePath).Should().BeFalse(); File.Exists(prePath).Should().BeFalse(); var stablePathJson = Path.Combine(target.Root, "badges/v/a.json"); var prePathJson = Path.Combine(target.Root, "badges/vpre/a.json"); File.Exists(stablePathJson).Should().BeFalse(); File.Exists(prePathJson).Should().BeFalse(); } }
public async Task Symbols_ValidationVerifyExtraSymbolsPackageInIndexCausesFailure() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var service = new Symbols(context); // Corrupt feed var index = new PackageIndex(context); var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Files.Clear(); pkgA.Nuspec.IsSymbolPackage = true; pkgA.AddFile("lib/net45/a.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); var pkgAZip = pkgA.Save(testContext.Packages); var pkgAInput = testContext.GetPackageInput(pkgAZip); await index.AddSymbolsPackageAsync(pkgAInput); // Validate var messages = await service.ValidateAsync(); var hasErrors = messages.Any(e => e.Level == LogLevel.Error); hasErrors.Should().BeTrue(); } }
public async Task GivenAStorageAccountWithNoInitVerifyPushSucceeds() { using (var packagesFolder = new TestFolder()) using (var testContext = new AzureTestContext()) { await testContext.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); // Skip init var result = await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); } }
public async Task Command_FrameworkAssembliesClear() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; testPackage.Nuspec.FrameworkAssemblies.Add(new KeyValuePair <string, List <NuGetFramework> >("test", new List <NuGetFramework>() { NuGetFramework.Parse("net45") })); var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "nuspec", "frameworkassemblies", "clear", zipFile.FullName }, log); var nuspec = GetNuspec(zipFile.FullName); // Assert Assert.Equal(0, exitCode); nuspec.GetFrameworkReferenceGroups().Should().BeEmpty(); } }
public async Task Symbols_VerifyFilesExistAfterPush() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var testPackage = new TestNupkg("packageA", "1.0.0"); testPackage.Files.Clear(); testPackage.AddFile("lib/net45/SymbolsTestA.dll", TestUtility.GetResource("SymbolsTestAdll").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestA.pdb", TestUtility.GetResource("SymbolsTestApdb").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestB.dll", TestUtility.GetResource("SymbolsTestBdll").GetBytes()); testPackage.AddFile("lib/net45/SymbolsTestB.pdb", TestUtility.GetResource("SymbolsTestBpdb").GetBytes()); var zipFile = testPackage.Save(testContext.Packages); // run commands await InitCommand.InitAsync(context); // add package await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); // validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); validateOutput.Should().BeTrue(); } }
public async Task Command_AddFilesCommand_Remove() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0" } }; var inputFile = Path.Combine(workingDir.Root, "test.dll"); File.WriteAllText(inputFile, "a"); var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "files", "add", zipFile.FullName, "-p", "lib/win8/test.dll", "-f", inputFile }, log); exitCode = await Program.MainCore(new[] { "files", "remove", zipFile.FullName, "-p", "lib/win8/test.dll" }, log); var files = GetFiles(zipFile.FullName); // Assert Assert.True(0 == exitCode, string.Join("|", log.Messages)); Assert.DoesNotContain("lib/win8/test.dll", string.Join("|", files)); Assert.Contains("removing", string.Join("|", log.Messages)); } }
public async Task Command_ValidateCommand_Invalid() { using (var workingDir = new TestFolder()) { // Arrange var testPackage = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "b" } }; var zipFile = testPackage.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "validate", workingDir.Root }, log); // Assert Assert.Equal(1, exitCode); Assert.Contains("error", string.Join("|", log.Messages)); } }
public async Task Symbols_AddSymbolsPackageWithNoValidSymbolsVerifyFeed() { using (var testContext = new SleetTestContext()) { var context = testContext.SleetContext; context.SourceSettings.SymbolsEnabled = true; var symbols = new Symbols(context); var packageIndex = new PackageIndex(context); var catalog = new Catalog(context); var autoComplete = new AutoComplete(context); var flatContainer = new FlatContainer(context); var registrations = new Registrations(context); var search = new Search(context); // Create package var pkgA = new TestNupkg("a", "1.0.0"); pkgA.Nuspec.IsSymbolPackage = true; var zip = pkgA.Save(testContext.Packages); var pkgInput = testContext.GetPackageInput(zip); // Init var success = await InitCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, enableCatalog : true, enableSymbols : true, log : testContext.SleetContext.Log, token : CancellationToken.None); // Push success &= await PushCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, new List <string>() { zip.FullName }, force : false, skipExisting : false, log : testContext.SleetContext.Log); // Validate success &= await ValidateCommand.RunAsync( testContext.SleetContext.LocalSettings, testContext.SleetContext.Source, testContext.SleetContext.Log); success.Should().BeTrue(); // The nupkg should exist, but there should not be any assets added. (await symbols.GetSymbolsPackagesAsync()).Should().BeEmpty(); (await packageIndex.GetSymbolsPackagesAsync()).Should().NotBeEmpty(); // Verify nupkg exists var nupkgPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "a.1.0.0.symbols.nupkg"); File.Exists(nupkgPath).Should().BeTrue(); // Verify package details var detailsPath = Path.Combine(testContext.Target, "symbols", "packages", "a", "1.0.0", "package.json"); File.Exists(detailsPath).Should().BeTrue(); } }
public async Task AddRemove_AddAndDeletePackagesAsync() { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true } }; var testPackage1 = new TestNupkg("packageA", "1.0.0"); var testPackage2 = new TestNupkg("packageA", "2.0.0"); var testPackage3 = new TestNupkg("packageB", "2.0.0"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var zipFile3 = testPackage3.Save(packagesFolder.Root); var toDelete = new List <PackageIdentity>() { new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), new PackageIdentity("packageB", NuGetVersion.Parse("2.0.0")) }; // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); await DeleteCommand.DeletePackagesAsync(context.LocalSettings, context.Source, toDelete, string.Empty, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert Assert.True(validateOutput); Assert.Equal(1, indexPackages.Count); Assert.Equal("packageA", indexPackages.First().Id); Assert.Equal("2.0.0", indexPackages.First().Version.ToNormalizedString()); } }
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)); }
public async Task GivenThatTheFeedHasMissingPackagesVerifyExistingPackagesAreDownloaded() { using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) using (var cache2 = new LocalCache()) using (var outputFolder = new TestFolder()) { var log = new TestLogger(); var fileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(target.Root)); var fileSystem2 = new PhysicalFileSystem(cache2, UriUtility.CreateUri(target.Root)); var settings = new LocalSettings(); await InitCommand.RunAsync(settings, fileSystem, log); var expected = new List <string>(); for (var i = 0; i < 100; i++) { var package = new TestNupkg("a", $"{i}.0.0"); package.Save(packagesFolder); if (i != 50) { expected.Add($"a.{i}.0.0.nupkg"); } } await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder }, false, false, log); var root = new DirectoryInfo(target); foreach (var file in root.GetFiles("a.50.0.0*", SearchOption.AllDirectories)) { // Corrupt the feed file.Delete(); } var success = await DownloadCommand.RunAsync(settings, fileSystem2, outputFolder, false, log); var fileNames = Directory.GetFiles(outputFolder, "*.nupkg", SearchOption.AllDirectories) .Select(e => Path.GetFileName(e)) .OrderBy(e => e, StringComparer.OrdinalIgnoreCase) .ToArray(); success.ShouldBeEquivalentTo(false, "the feed is not valid"); fileNames.ShouldBeEquivalentTo(expected, "all files but the deleted one"); log.GetMessages().Should().NotContain("The feed does not contain any packages"); log.GetMessages().Should().Contain("Failed to download all packages!"); foreach (var file in expected) { log.GetMessages().Should().Contain(file); } } }
public async Task VerifyStartTimeIsExclusiveAndEndTimeIsInclusive() { // Arrange using (var cache = new LocalCache()) using (var cacheContext = new SourceCacheContext()) using (var workingDir = new TestFolder()) { var log = new TestLogger(); var baseUri = Sleet.UriUtility.CreateUri("https://localhost:8080/testFeed/"); var feedFolder = Path.Combine(workingDir, "feed"); var nupkgsFolder = Path.Combine(workingDir, "nupkgs"); Directory.CreateDirectory(feedFolder); Directory.CreateDirectory(nupkgsFolder); const int packageCount = 10; await CatalogReaderTestHelpers.CreateCatalogAsync( workingDir, feedFolder, nupkgsFolder, baseUri, catalogPageSize : 2, log : log); foreach (var i in Enumerable.Range(0, packageCount)) { var nupkgFolder = Path.Combine(nupkgsFolder, i.ToString()); TestNupkg.Save(nupkgFolder, new TestNupkg($"Package{i}", "1.0.0")); await CatalogReaderTestHelpers.PushPackagesAsync(workingDir, nupkgFolder, baseUri, log); } var feedUri = Sleet.UriUtility.CreateUri(baseUri.AbsoluteUri + "index.json"); var httpSource = CatalogReaderTestHelpers.GetHttpSource(cache, feedFolder, baseUri); using (var catalogReader = new CatalogReader(feedUri, httpSource, cacheContext, TimeSpan.FromMinutes(1), log)) { var allEntries = await catalogReader.GetEntriesAsync(); var timestamps = allEntries .OrderBy(x => x.CommitTimeStamp) .Select(x => x.CommitTimeStamp) .ToList(); var start = timestamps[2]; var end = timestamps[packageCount - 3]; // Act var entries = await catalogReader.GetEntriesAsync(start, end, CancellationToken.None); // Assert Assert.Equal( timestamps.Skip(3).Take(5), entries.Select(x => x.CommitTimeStamp)); Assert.Equal(packageCount, timestamps.Distinct().Count()); } } }
public async Task Command_ListCommand_GlobbingPath() { using (var workingDir = new TestFolder()) { // Arrange var testPackageA = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0-beta.2.2" } }; var testPackageB = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "1.0.0-beta.1.2" } }; var testPackageC = new TestNupkg() { Nuspec = new TestNuspec() { Id = "c", Version = "2.0.0" } }; var subFolder = Path.Combine(workingDir.Root, "subFolder"); var zipFileA = testPackageA.Save(subFolder); var zipFileB = testPackageB.Save(subFolder); var zipFileC = testPackageC.Save(subFolder); var log = new TestLogger(); var input = workingDir.Root + Path.DirectorySeparatorChar + "**/*.nupkg"; // Act var exitCode = await Program.MainCore(new[] { "list", input }, log); var files = log.Messages.Select(e => Path.GetFileName(e.Message)).OrderBy(s => s, StringComparer.OrdinalIgnoreCase).ToList(); // Assert Assert.Equal(0, exitCode); Assert.Equal(3, files.Count); Assert.Equal("a.1.0.0-beta.2.2.nupkg", files[0]); Assert.Equal("b.1.0.0-beta.1.2.nupkg", files[1]); Assert.Equal("c.2.0.0.nupkg", files[2]); } }
public async Task NuGetReader_DownloadPackageAsync() { // Arrange using (var packagesFolder = new TestFolder()) using (var globalFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var outputRoot = Path.Combine(target.Root, "output"); var baseUri = UriUtility.CreateUri("https://localhost:8080/testFeed/"); var log = new TestLogger(); var testPackage = new TestNupkg("packageA", "1.0.0"); var sleetConfig = TestUtility.CreateConfigWithLocal("local", outputRoot, baseUri.AbsoluteUri); var sleetConfigPath = Path.Combine(target.Root, "sleet.config"); await JsonUtility.SaveJsonAsync(new FileInfo(sleetConfigPath), sleetConfig); var zipFile = testPackage.Save(packagesFolder.Root); var settings = LocalSettings.Load(sleetConfigPath); var fileSystem = await FileSystemFactory.CreateFileSystemAsync(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { packagesFolder.Root }, false, false, log); // Create a repository abstraction for nuget var nugetFileSystem = new PhysicalFileSystem(cache, UriUtility.CreateUri(outputRoot), baseUri); var localSource = GetSource(outputRoot, baseUri, nugetFileSystem); var resource = await localSource.GetResourceAsync <DownloadResource>(); var cacheContext = new SourceCacheContext() { NoCache = true }; var downloadContext = new PackageDownloadContext(cacheContext, globalFolder, directDownload: false); var result = await resource.GetDownloadResourceResultAsync(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), downloadContext, globalFolder, log, CancellationToken.None); // Assert Assert.True(success, log.ToString()); Assert.Equal(DownloadResourceResultStatus.Available, result.Status); Assert.True(result.PackageStream.Length > 0); Assert.Equal(new PackageIdentity("packageA", NuGetVersion.Parse("1.0.0")), result.PackageReader.GetIdentity()); } }
public async Task Command_ListCommandNoFilters() { using (var workingDir = new TestFolder()) using (var workingDir2 = new TestFolder()) using (var workingDir3 = new TestFolder()) { // Arrange var testPackageA = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0-beta.2.2" } }; var testPackageB = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "1.0.0-beta.1.2" } }; var testPackageC = new TestNupkg() { Nuspec = new TestNuspec() { Id = "c", Version = "2.0.0" } }; var zipFileA = testPackageA.Save(workingDir.Root); var zipFileB = testPackageB.Save(workingDir2.Root); var zipFileC = testPackageC.Save(workingDir3.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "list", workingDir.Root, workingDir2.Root, zipFileC.FullName }, log); var files = log.Messages.Select(e => Path.GetFileName(e.Message)).OrderBy(s => s, StringComparer.OrdinalIgnoreCase).ToList(); // Assert Assert.Equal(0, exitCode); Assert.Equal(3, files.Count); Assert.Equal("a.1.0.0-beta.2.2.nupkg", files[0]); Assert.Equal("b.1.0.0-beta.1.2.nupkg", files[1]); Assert.Equal("c.2.0.0.nupkg", files[2]); } }
public async Task SubFeed_InitMultipleFeedsVerifyDestroyDoesNotModifyOthers() { using (var packagesFolder = new TestFolder()) using (var testContext = new AzureTestContext()) using (var testContext2 = new AzureTestContext()) { // Use a subfeed for the filesystem var subFeedName = "testSubFeedA"; var subFeedName2 = "testSubFeedB"; var root = UriUtility.GetPath(testContext.Uri, subFeedName); var root2 = UriUtility.GetPath(testContext.Uri, subFeedName2); testContext.FileSystem = new AzureFileSystem(testContext.LocalCache, root, root, testContext.StorageAccount, testContext.ContainerName, feedSubPath: subFeedName); testContext2.FileSystem = new AzureFileSystem(testContext.LocalCache, root2, root2, testContext.StorageAccount, testContext.ContainerName, feedSubPath: subFeedName2); await testContext.InitAsync(); await testContext2.InitAsync(); var testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); var result = await InitCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, enableCatalog : true, enableSymbols : true, log : testContext.Logger, token : CancellationToken.None); result &= await InitCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, enableCatalog : true, enableSymbols : true, log : testContext2.Logger, token : CancellationToken.None); // Destroy feed2 result &= await DestroyCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, testContext2.Logger); // Validate feed1 result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); await testContext2.CleanupAsync(); } }