public override void Specify() { describe("the file module provided for node only needs fs and path", delegate() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); var fileToWrite = arrange(() => Path.Combine(testFolder.FullName, "file.txt")); it("allows path to be used", delegate() { var script = @" require(['env!env/args', 'file'], function (args, file) { file.saveUtf8File(args[0], 'hello, world'); }); "; expect(() => !File.Exists(fileToWrite)); context.compiler.RunWithArguments(script, new[] { fileToWrite }); expect(() => File.ReadAllText(fileToWrite) == "hello, world"); }); }); }
public void Find_Environment_With_Dir_Not_Existing() { using (var workDir = new TestFolder(Environment.SpecialFolder.LocalApplicationData)) { workDir.AddFolder("dir1"); workDir.AddFolder("dir1/subdir1"); var target = new EnvironmentProvider(Path.Combine(workDir.DirectoryInfo.FullName, "dir1/subdir1")); target.GetEnvironment("unittest"); } }
public void CreatesNestedFolder() { testFolder.PageList.Pages = new List<Page> {new TestPage {Name = "leaf1.html", Contents = "stuff"}}; var subFolder = new TestFolder { Path = "root\\Tests\\subfolder", PageList = {Pages = new List<Page> {new TestPage {Name = "leaf2.html", Contents = "stuff"}}} }; testFolder.FolderList.Folders = new List<Folder> {subFolder}; var tree = testFiles.Tree; Assert.AreEqual(",,True,[ ,leaf1,False,ignore[ ] ,subfolder,True,[ subfolder,leaf2,False,ignore[ ] ] ]", tree.List(Show)); }
public void ChecksResultInNestedFolder() { testFolder.PageList.Pages = new List<Page> {new TestPage {Name = "leaf1.html", Contents = "stuff"}}; var subFolder = new TestFolder { Path = "root\\Tests\\subfolder", PageList = {Pages = new List<Page> {new TestPage {Name = "leaf2.html", Contents = "stuff"}}} }; testFolder.FolderList.Folders = new List<Folder> {subFolder}; var resultSubFolder = new TestFolder { Path = "other\\Results\\subfolder", PageList = {Pages = new List<Page> {new TestPage {Name = "leaf2.html", Contents = "<!--2016-01-02 13:14:15,0,1,0,0-->" + Environment.NewLine}}} }; resultFolder.FolderList.Folders = new List<Folder> {resultSubFolder}; var tree = testFiles.Tree; Assert.AreEqual(",,True,[ ,leaf1,False,ignore[ ] ,subfolder,True,[ subfolder,leaf2,False,fail[ ] ] ]", tree.List(Show)); }
public void Transform_Read_Only_File() { var mock = new Mock<IEnvironmentSerializer>(); mock.Setup(provider => provider.Deserialize("unit")).Returns(GetUnitEnvironment()); var target = new TemplateEngine(); using (var dir = new TestFolder()) { dir.AddFile("read-only.template.txt", "whatever: ${var1}"); dir.AddFile("read-only.txt", "will be transformed").SetReadOnly(); // before the bugfix: this threw a Exception because the file was ReadOnly target.TransformDirectory(dir.DirectoryInfo.FullName, GetUnitEnvironment()); Assert.AreNotEqual("will be transformed", dir.ReadFile("read-only.txt")); } }
public void Find_Environment_In_Same_Dir() { var xml = @"<?xml version=""1.0""?> <environment name=""local"" description=""Used for unit tests, not a real environment""> <variable name=""Name"" value=""Tobi"" /> <variable name=""Jack"" value=""Bauer"" /> </environment>"; using (var workDir = new TestFolder(Environment.SpecialFolder.LocalApplicationData)) { workDir.AddFolder("dir1"); workDir.AddFolder("dir1/subdir1"); workDir.AddFolder(".powerdeploy"); workDir.AddFile(".powerdeploy/unittest.xml", xml); var target = new EnvironmentProvider(workDir.DirectoryInfo.FullName); var result = target.GetEnvironment("unittest"); Assert.AreEqual("local", result.Name); Assert.AreEqual("Tobi", result["Name"].Value); Assert.AreEqual("Bauer", result["Jack"].Value); } }
public async Task RetentionPruneCommand_PrunesOnPushWithMultiplePushes() { // Arrange using (var packagesFolder = new TestFolder()) using (var packagesFolder2 = 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, SymbolsEnabled = true, RetentionMaxStableVersions = 2, RetentionMaxPrereleaseVersions = 1 } }; // Initial packages var identities = new List <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-alpha")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta")), new PackageIdentity("b", NuGetVersion.Parse("3.0.0")), }; await InitCommand.InitAsync(context); // Push packages 1 at a time foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); 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); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(6); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("a", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("2.0.0"))).Should().BeTrue(); indexPackages.Contains(new PackageIdentity("b", NuGetVersion.Parse("3.0.0-beta"))).Should().BeTrue(); } }
public async Task PushCommand_GivenADifferentNuspecCasingVerifyPush() { // 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 testPackage = new TestNupkg("packageA", "1.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); using (var tempZip = new ZipArchive(zipFile.Open(FileMode.Open, FileAccess.ReadWrite, FileShare.None), ZipArchiveMode.Update)) { var nuspec = tempZip.Entries.Single(e => e.FullName == "packageA.nuspec"); using (var ms = new MemoryStream()) { using (var nuspecStream = nuspec.Open()) { nuspecStream.CopyTo(ms); } ms.Position = 0; nuspec.Delete(); var newEntry = tempZip.CreateEntry("PacKAGEa.NuSpec"); ms.CopyTo(newEntry.Open()); } } using (var zip = new ZipArchive(File.OpenRead(zipFile.FullName), ZipArchiveMode.Read, false)) { var input = PackageInput.Create(zipFile.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, indexPackages.Count); } } }
public async Task AddRemove_AddTwoPackagesOfUniqueIds() { // 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("packageB", "1.0.0"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); using (var zip1 = new ZipArchive(File.OpenRead(zipFile1.FullName), ZipArchiveMode.Read, false)) using (var zip2 = new ZipArchive(File.OpenRead(zipFile2.FullName), ZipArchiveMode.Read, false)) { var input1 = PackageInput.Create(zipFile1.FullName); var input2 = PackageInput.Create(zipFile2.FullName); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(2, catalogEntries.Count); Assert.Equal(2, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(2, indexPackages.Count); Assert.Equal(2, searchPackages.Count); Assert.Equal(2, autoCompletePackages.Count); } } }
public async Task GivenThatIAddAPackageWithTheCatalogDisabledVerifyItSucceeds() { // 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 } }; context.SourceSettings.CatalogEnabled = false; 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 catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); var catalogEntry = await registration.GetCatalogEntryFromPackageBlob(input.Identity); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEquivalentTo(new[] { input.Identity }); indexPackages.Should().BeEquivalentTo(new[] { input.Identity }); searchPackages.Should().BeEquivalentTo(new[] { input.Identity }); autoCompletePackages.Should().BeEquivalentTo(new[] { input.Identity.Id }); catalogLatest.Should().BeNull(); catalogEntry["version"].ToString().Should().Be("1.0.0"); catalogEntry["sleet:operation"].ToString().Should().Be("add"); } } }
public async Task Cleanup() { await TestFolder.DeleteAsync(StorageDeleteOption.PermanentDelete); await OutputFolder.DeleteAsync(StorageDeleteOption.PermanentDelete); }
public void RazerChromaApiGetsCalledOnGameEvents() { const string statusFile = "Status.json"; const string journalFile = "Journal.190101020000.01.log"; using var cpl = ColoreProviderLock.GetLock(); var chromaApi = new Mock <IChromaApi> { DefaultValue = DefaultValue.Mock }; var mockIA = chromaApi.Setup(x => x.InitializeAsync(It.IsAny <AppInfo>())); var mockCKEA = chromaApi.Setup(x => x.CreateKeyboardEffectAsync(It.IsAny <KeyboardEffectType>(), It.IsAny <It.IsValueType>())); var mockUA = chromaApi.Setup(x => x.UninitializeAsync()); using TestFolder dirRoot = new TestFolder(_gameRootFolder), dirOpts = new TestFolder(_gameOptionsFolder), dirJournal = new TestFolder(); dirJournal.WriteText(statusFile, EventSequence.BuildEvent("Status", new { Flags = 0 })); dirJournal.WriteText(journalFile, EventSequence.BuildEvent("Fileheader", new { part = 1, language = @"English\UK", gameversion = "3.5.0.200 EDH", build = "r210198/r0 " })); using var cc = new ChromaController(dirRoot.Name, dirOpts.Name, dirJournal.Name) { ChromaFactory = new ChromaFactory { ChromaApi = chromaApi.Object, ChromaAppInfo = null, }, AnimationFrameRate = 0, DetectGameInForeground = false, }; Assert.False(cc.DetectGameInForeground); using var ceIA = new CountdownEvent(1); mockIA.Callback(() => ceIA.Signal()); using var ceCKEA = new CountdownEvent(1); mockCKEA.Callback(() => ceCKEA.Signal()); using var ceUA = new CountdownEvent(1); mockUA.Callback(() => ceUA.Signal()); cc.Start(); Assert.True(ceIA.Wait(1000)); Assert.True(ceCKEA.Wait(1000)); var seq = BuildEventSequence(); ceCKEA.Reset(seq.Count(x => x.ChangesGameState)); seq.Play(dirJournal, journalFile, statusFile); Assert.True(ceCKEA.Wait(200 * seq.Count)); cc.Stop(); Assert.True(ceUA.Wait(1000)); }
public override void Specify() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); var expectedContent = Guid.NewGuid().ToString(); string relativeTargetPath = @"la\de\da\wrote.txt"; var targetPath = arrange(() => Path.Combine(testFolder.FullName, relativeTargetPath)); var writeScript = arrange(() => "require(['fs'], function(fs) { fs.writeFileSync( " + Serialize(targetPath) + ", " + Serialize(expectedContent) + ",'utf8'); });"); it("supports writeFileSync", delegate() { context.compiler.Execute(writeScript); expect(() => File.ReadAllText(targetPath) == expectedContent); }); it("supports readFileSync", delegate() { context.compiler.Execute(writeScript); var echoScript = arrange(() => "require(['fs', 'print'], function(fs, print) { print(fs.readFileSync( " + Serialize(targetPath) + ",'utf8')); });"); context.compiler.Execute(echoScript); context.ExpectLines(expectedContent); }); it("supports mkdirSync", delegate() { var otherDirectory = Path.Combine(testFolder.FullName, "CreatedByNativeFS"); expect(() => !Directory.Exists(otherDirectory)); var echoScript = "require(['fs'], function(fs) { fs.mkdirSync( " + Serialize(otherDirectory) + ",'0777'); });"; context.compiler.Execute(echoScript); expect(() => Directory.Exists(otherDirectory)); }); it("supports rmdirSync", delegate() { var otherDirectory = Path.Combine(testFolder.FullName, "CreatedByNativeFS"); Directory.CreateDirectory(otherDirectory); expect(() => Directory.Exists(otherDirectory)); var script = "require(['fs'], function(fs) { fs.rmdirSync( " + Serialize(otherDirectory) + "); });"; context.compiler.Execute(script); expect(() => !Directory.Exists(otherDirectory)); }); it("supports unlinkSync", delegate() { context.compiler.Execute(writeScript); expect(() => File.Exists(targetPath)); var script = "require(['fs'], function(fs) { fs.unlinkSync( " + Serialize(targetPath) + "); });"; context.compiler.Execute(script); expect(() => !File.Exists(targetPath)); }); foreach (var pathVariation in new[] { relativeTargetPath, ".\\" + relativeTargetPath }) { it("supports realpathSync for " + pathVariation, delegate() { context.compiler.Execute(writeScript); var realScript = "require(['fs', 'print'], function(fs, print) { print(fs.realpathSync( " + Serialize(pathVariation) + ",'utf8')); });"; context.compiler.Execute(realScript); context.ExpectLines(targetPath); }); } describe("statSync", delegate() { foreach (var expression in new Dictionary<string, string>() { {"fileStats.isFile()", "True"}, {"dirStats.isFile()", "False"}, {"fileStats.isDirectory()", "False"}, {"dirStats.isDirectory()", "True"} }) it("evalutes expression " + expression.Key + " as " + expression.Value, delegate() { context.compiler.Execute(writeScript); var statScript = @" require(['fs', 'print'], function(fs, print) { var fileStats = fs.statSync(" + Serialize(targetPath) + @"); var dirStats = fs.statSync(" + Serialize(new FileInfo(targetPath).Directory.FullName) + @"); print(" + expression.Key + @"); });"; context.compiler.Execute(statScript); context.ExpectLines(expression.Value); }); it("reports last modified time", delegate() { var before = (double)DateTime.UtcNow.ToFileTimeUtc(); context.compiler.Execute(writeScript); var after = (double)DateTime.UtcNow.ToFileTimeUtc(); var statScript = @" require(['fs', 'print'], function(fs, print) { var fileStats = fs.statSync(" + Serialize(targetPath) + @"); print(fileStats.mtime.getTime()); });"; context.compiler.Execute(statScript); var time = double.Parse(context.GetLines().Single()); expect(() => before <= time && time <= after); }); }); describe("readdirSync", delegate() { it("lists file and directory names", delegate() { Directory.CreateDirectory(Path.Combine(testFolder.FullName, "qux")); File.WriteAllText(Path.Combine(testFolder.FullName, "foo.txt"), "123"); File.WriteAllText(Path.Combine(testFolder.FullName, "bar.html"), "123"); File.WriteAllText(Path.Combine(testFolder.FullName, "baz.css"), "123"); var readdirScript = @" require(['fs', 'print'], function(fs, print) { var names = fs.readdirSync(" + Serialize(testFolder.FullName) + @"); print.apply(null, names); });"; context.compiler.Execute(readdirScript); context.ExpectLines("bar.html", "baz.css", "foo.txt", "qux"); }); }); }
public async Task GivenSetAndUnsetCombinedVerifyResult() { 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 context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() }; var success = await InitCommand.RunAsync(settings, fileSystem, log); success &= await FeedSettingsCommand.RunAsync( settings, fileSystem, unsetAll : false, getAll : false, getSettings : new string[] { }, unsetSettings : new string[] { }, setSettings : new string[] { "b:2", "a:1" }, log : log, token : context.Token); success &= await FeedSettingsCommand.RunAsync( settings, fileSystem, unsetAll : false, getAll : false, getSettings : new string[] { }, unsetSettings : new string[] { "b" }, setSettings : new string[] { "c:3" }, log : log, token : context.Token); success &= await FeedSettingsCommand.RunAsync( settings, fileSystem2, unsetAll : false, getAll : true, getSettings : new string[] { }, unsetSettings : new string[] { }, setSettings : new string[] { }, log : log, token : context.Token); success.Should().BeTrue(); log.GetMessages().Should().NotContain("b : 2"); log.GetMessages().Should().Contain("a : 1"); log.GetMessages().Should().Contain("c : 3"); } }
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"); Uri iconUri = null; // Act var actual = await CatalogUtility.CreatePackageDetailsAsync(input, catalog.CatalogBaseURI, nupkgUri, iconUri, 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_ReleaseCommand_MultipleNewVersions_TakeLowestValid() { using (var workingDir = new TestFolder()) { // Arrange var testPackageA = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "6.0.0" } }; var depGroup = new PackageDependencyGroup(NuGetFramework.Parse("net45"), new[] { new PackageDependency("b", VersionRange.Parse("5.0.0")) }); testPackageA.Nuspec.Dependencies.Add(depGroup); var testPackageB1 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "6.0.0" } }; var testPackageB2 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "7.0.0" } }; var testPackageB3 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "1.0.0" } }; var zipFileA = testPackageA.Save(workingDir.Root); var zipFileB1 = testPackageB1.Save(workingDir.Root); var zipFileB2 = testPackageB2.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "release", workingDir.Root, "-r", "beta" }, log); var nuspecA = GetNuspec(Path.Combine(workingDir.Root, "a.6.0.0-beta.nupkg")); var dependencyB = nuspecA.GetDependencyGroups().Single().Packages.Single(e => e.Id == "b"); var dependencyBString = dependencyB.VersionRange.ToLegacyShortString(); // Assert Assert.Equal(0, exitCode); Assert.Equal("6.0.0-beta", dependencyBString); } }
public async Task Command_ReleaseCommand_Label() { using (var workingDir = new TestFolder()) { // Arrange var testPackageA = new TestNupkg() { Nuspec = new TestNuspec() { Id = "a", Version = "1.0.0-beta.1.2" } }; var depGroup = new PackageDependencyGroup(NuGetFramework.Parse("net45"), new[] { new PackageDependency("b", VersionRange.Parse("2.0.0-alpha")), new PackageDependency("c", VersionRange.Parse("[1.0.0-beta]")) }); testPackageA.Nuspec.Dependencies.Add(depGroup); var testPackageB = new TestNupkg() { Nuspec = new TestNuspec() { Id = "b", Version = "2.0.0-alpha" } }; var testPackageC = new TestNupkg() { Nuspec = new TestNuspec() { Id = "c", Version = "1.0.0-beta" } }; var zipFileA = testPackageA.Save(workingDir.Root); var zipFileB = testPackageB.Save(workingDir.Root); var zipFileC = testPackageC.Save(workingDir.Root); var log = new TestLogger(); // Act var exitCode = await Program.MainCore(new[] { "release", workingDir.Root, "--label", "rc.1" }, log); var nuspecA = GetNuspec(Path.Combine(workingDir.Root, "a.1.0.0-rc.1.nupkg")); var nuspecB = GetNuspec(Path.Combine(workingDir.Root, "b.2.0.0-rc.1.nupkg")); var nuspecC = GetNuspec(Path.Combine(workingDir.Root, "c.1.0.0-rc.1.nupkg")); // Assert Assert.Equal(0, exitCode); Assert.Equal("1.0.0-rc.1", nuspecA.GetVersion().ToString()); Assert.Equal("2.0.0-rc.1", nuspecB.GetVersion().ToString()); Assert.Equal("1.0.0-rc.1", nuspecC.GetVersion().ToString()); Assert.Equal("2.0.0-rc.1", nuspecA.GetDependencyGroups().Single().Packages.Single(e => e.Id == "b").VersionRange.ToLegacyShortString()); Assert.Equal("[1.0.0-rc.1]", nuspecA.GetDependencyGroups().Single().Packages.Single(e => e.Id == "c").VersionRange.ToLegacyShortString()); } }
public async Task Feed_VerifyBaseUriIsAppliedToLocal(string baseUriString) { // Arrange using (var packagesFolder = new TestFolder()) using (var target = new TestFolder()) using (var cache = new LocalCache()) { var log = new TestLogger(); var fileSystemRoot = UriUtility.CreateUri(target.Root); var baseUri = new Uri(baseUriString); var fileSystem = new PhysicalFileSystem(cache, fileSystemRoot, baseUri); var settings = new LocalSettings(); var context = new SleetContext() { Token = CancellationToken.None, LocalSettings = settings, Log = log, Source = fileSystem, SourceSettings = new FeedSettings() { CatalogEnabled = true, SymbolsEnabled = true } }; 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); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile.FullName }, false, false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogLatest = await catalog.GetLatestEntryAsync(input.Identity); var regPackages = await registration.GetPackagesByIdAsync(input.Identity.Id); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(1, catalogEntries.Count); Assert.Equal(1, catalogExistingEntries.Count); Assert.Equal(1, regPackages.Count); Assert.Equal(1, indexPackages.Count); Assert.Equal(1, searchPackages.Count); Assert.Equal(1, autoCompletePackages.Count); // Walk json to check for bad urls await TestUtility.WalkJsonAsync(target.Root, (file, json, toCheck) => { // Check only URLs found if (toCheck.IndexOf("://") > -1) { var cleanUriSchema = toCheck.Replace(":///", string.Empty).Replace("://", string.Empty); var doubleSlash = cleanUriSchema.IndexOf("//") > -1; Assert.False(doubleSlash, toCheck); } }); } } }
public override void Specify() { var testFolder = new TestFolder(this); var context = new CompilerUsage(this, testFolder.FullName); it("supports existsSync", delegate() { var otherFile = Path.Combine(testFolder.FullName, "someOtherFile.txt"); File.WriteAllText(otherFile, "foo"); var otherfolder = Path.Combine(testFolder.FullName, "RabOof"); var script = @" require(['path', 'print'], function(path, print) { print(path.existsSync(" + Serialize(testFolder.FullName) + @")); print(path.existsSync(" + Serialize(otherfolder) + @")); print(path.existsSync(" + Serialize(otherFile) + @")); });"; context.compiler.Execute(script); context.ExpectLines("True", "False", "True"); }); it("supports normalize", delegate() { var further = Path.Combine(testFolder.FullName, "turtles\\turtles\\alltheway.txt"); var expected = further.ToLower(); var script = @" require(['path', 'print'], function(path, print) { print(path.normalize('.\\turtles\\turtles\\alltheway.txt')); print(path.normalize('.\\turtles\\turtles\\..\\turtles\\alltheway.txt')); print(path.normalize('TuRtLeS\\tUrTlEs\\alltheway.txt')); print(path.normalize(" + Serialize(further) + @")); });"; context.compiler.Execute(script); context.ExpectLines(expected, expected, expected, expected); }); it("supports join", delegate() { var script = @" require(['path', 'print'], function(path, print) { print(path.join('c:\\test')); print(path.join('c:\\test', 'second')); print(path.join('c:\\test', 'second\\')); print(path.join('c:\\test', 'second', 'third')); });"; context.compiler.Execute(script); context.ExpectLines(@"c:\test",@"c:\test\second",@"c:\test\second\",@"c:\test\second\third"); }); it("supports dirname", delegate() { var otherFile = Path.Combine(testFolder.FullName, "foo\\bar\\baz.txt"); var script = @" require(['path', 'print'], function(path, print) { var topPath = path.dirname(" + Serialize(otherFile)+ @"); print(topPath); var secondPath = path.dirname(topPath); print(secondPath); });"; context.compiler.Execute(script); string topPath = new FileInfo(otherFile).DirectoryName; string secondPath = new FileInfo(topPath).DirectoryName; context.ExpectLines(topPath,secondPath); }); }
public async Task GivenThatIRemoveAllPackagesWithTheCatalogDisabledVerifyItSucceeds() { // 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 } }; context.SourceSettings.CatalogEnabled = false; var testPackage1 = new TestNupkg("packageA", "1.0.1"); var testPackage2 = new TestNupkg("packageA", "1.0.2"); var testPackage3 = new TestNupkg("packageA", "1.0.3"); var zipFile1 = testPackage1.Save(packagesFolder.Root); var zipFile2 = testPackage2.Save(packagesFolder.Root); var zipFile3 = testPackage3.Save(packagesFolder.Root); var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); // Act // run commands await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile1.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile2.FullName }, false, false, context.Log); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { zipFile3.FullName }, false, false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.3", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.1", "", false, context.Log); await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "packageA", "1.0.2", "", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read outputs var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var regPackages = await registration.GetPackagesByIdAsync("packageA"); var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert validateOutput.Should().BeTrue("the feed is valid"); catalogEntries.Should().BeEmpty("the catalog is disabled"); catalogExistingEntries.Should().BeEmpty("the catalog is disabled"); regPackages.Should().BeEmpty("all packages were removed"); indexPackages.Should().BeEmpty("all packages were removed"); searchPackages.Should().BeEmpty("all packages were removed"); autoCompletePackages.Should().BeEmpty("all packages were removed"); } }
public async Task CatalogTest_CreatePackageDetails() { 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() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0-alpha.1", Authors = "authorA, authorB", Copyright = "Copyright info", Description = "Package A", IconUrl = "http://tempuri.org/icon.png", LicenseUrl = "http://tempuri.org/license.html", Language = "en-us", MinClientVersion = "3.3.0", DevelopmentDependency = "true", Owners = "ownerA, ownerB", ProjectUrl = "http://tempuri.org/project.html", ReleaseNotes = "release 1.0", RequireLicenseAcceptance = "true", Summary = "package summary.", Tags = "tagA tagB tagC", Title = "packageA title", Dependencies = new List <PackageDependencyGroup>() { new PackageDependencyGroup(NuGetFramework.AnyFramework, new List <PackageDependency>() { new PackageDependency("packageB", VersionRange.Parse("1.0.0")) }), new PackageDependencyGroup(NuGetFramework.Parse("net46"), new List <PackageDependency>()), new PackageDependencyGroup(NuGetFramework.Parse("net45"), new List <PackageDependency>() { new PackageDependency("packageAll"), new PackageDependency("packageExact", VersionRange.Parse("[2.0.0]")), }), }, FrameworkAssemblies = new List <KeyValuePair <string, List <NuGetFramework> > >() { new KeyValuePair <string, List <NuGetFramework> >("System.IO.Compression", new List <NuGetFramework>() { NuGetFramework.Parse("net45"), NuGetFramework.Parse("win8") }), new KeyValuePair <string, List <NuGetFramework> >("System.Threading", new List <NuGetFramework>() { NuGetFramework.Parse("net40") }), new KeyValuePair <string, List <NuGetFramework> >("System.All", new List <NuGetFramework>() { }) }, } }; 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-alpha.1/packageA.1.0.0-alpha.1.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; // Assert Assert.EndsWith(".json", actual["@id"].ToString()); Assert.Contains("/catalog/data/", actual["@id"].ToString()); Assert.Equal(testPackage.Nuspec.Authors, actual["authors"].ToString()); Assert.Equal(testPackage.Nuspec.Copyright, actual["copyright"].ToString()); Assert.Equal(testPackage.Nuspec.Description, actual["description"].ToString()); Assert.Equal(testPackage.Nuspec.IconUrl, actual["iconUrl"].ToString()); Assert.Equal(testPackage.Nuspec.LicenseUrl, actual["licenseUrl"].ToString()); Assert.Equal(testPackage.Nuspec.MinClientVersion, actual["minClientVersion"].ToString()); Assert.Equal(testPackage.Nuspec.ProjectUrl, actual["projectUrl"].ToString()); Assert.True(actual["requireLicenseAcceptance"].ToObject <bool>()); Assert.Equal(testPackage.Nuspec.Title, actual["title"].ToString()); Assert.Equal(testPackage.Nuspec.Id, actual["id"].ToString()); Assert.Equal(testPackage.Nuspec.Version, actual["version"].ToString()); Assert.Equal("tagA", ((JArray)actual["tags"])[0].ToString()); Assert.Equal("tagB", ((JArray)actual["tags"])[1].ToString()); Assert.Equal("tagC", ((JArray)actual["tags"])[2].ToString()); Assert.EndsWith(".nupkg", actual["packageContent"].ToString()); Assert.Null(dependencyGroups[0]["targetFramework"]); Assert.Equal("packageB", ((JArray)dependencyGroups[0]["dependencies"]).Single()["id"]); Assert.Equal("[1.0.0, )", ((JArray)dependencyGroups[0]["dependencies"]).Single()["range"]); Assert.Equal("net45", dependencyGroups[1]["targetFramework"]); Assert.NotNull(dependencyGroups[1]["dependencies"]); Assert.Equal("net46", dependencyGroups[2]["targetFramework"]); Assert.Null(dependencyGroups[2]["dependencies"]); Assert.Null(frameworkAssemblyGroups[0]["targetFramework"]); Assert.Equal("net40", frameworkAssemblyGroups[1]["targetFramework"]); Assert.Equal("net45", frameworkAssemblyGroups[2]["targetFramework"]); Assert.Equal("win8", frameworkAssemblyGroups[3]["targetFramework"]); Assert.Equal("System.All", ((JArray)frameworkAssemblyGroups[0]["assembly"]).Single()); Assert.Equal("System.Threading", ((JArray)frameworkAssemblyGroups[1]["assembly"]).Single()); Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[2]["assembly"]).Single()); Assert.Equal("System.IO.Compression", ((JArray)frameworkAssemblyGroups[3]["assembly"]).Single()); } } }
public async Task SubFeed_PushAndVerifyWithNestedFeedsVerifySuccess() { using (var packagesFolder = new TestFolder()) using (var testContext = new AzureTestContext()) using (var testContext2 = new AzureTestContext()) { // Use a subfeed for the filesystem var subFeedName = "testSubFeed"; var root = UriUtility.GetPath(testContext.Uri, subFeedName); testContext.FileSystem = new AzureFileSystem(testContext.LocalCache, root, root, testContext.StorageAccount, testContext.ContainerName, feedSubPath: subFeedName); 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); result &= await PushCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext.Logger); result &= await PushCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, new List <string>() { zipFile.FullName }, force : false, skipExisting : false, log : testContext2.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext.FileSystem, testContext.Logger); result &= await ValidateCommand.RunAsync(testContext.LocalSettings, testContext2.FileSystem, testContext2.Logger); result.Should().BeTrue(); await testContext.CleanupAsync(); await testContext2.CleanupAsync(); } }
public async Task CatalogTest_AddPackageAsync_SupportsWritingMultiplePages() { 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, CatalogPageSize = 1, } }; var catalog = new Catalog(context); var catalogIndex = await TemplateUtility.LoadTemplate( "CatalogIndex", DateTimeOffset.UtcNow, fileSystem.BaseURI); await fileSystem.Get("catalog/index.json").Write( JObject.Parse(catalogIndex), log, context.Token); var testPackageA = new TestNupkg("packageA", "1.0.0"); var testPackageB = new TestNupkg("packageB", "1.0.0"); var zipFileA = testPackageA.Save(packagesFolder.Root); var zipFileB = testPackageB.Save(packagesFolder.Root); using (var zipA = new ZipArchive(File.OpenRead(zipFileA.FullName), ZipArchiveMode.Read, false)) using (var zipB = new ZipArchive(File.OpenRead(zipFileB.FullName), ZipArchiveMode.Read, false)) { var inputA = PackageInput.Create(zipFileA.FullName); var inputB = PackageInput.Create(zipFileB.FullName); // Act await catalog.AddPackageAsync(inputA); await catalog.AddPackageAsync(inputB); await fileSystem.Commit(context.Log, context.Token); // Assert Assert.True( await fileSystem.Get("catalog/page.0.json").Exists(context.Log, context.Token), "The first catalog page should exist."); Assert.True( await fileSystem.Get("catalog/page.1.json").Exists(context.Log, context.Token), "The second catalog page should exist."); } } }
public async Task NuGetReader_PackageMetadataResourceAsync() { // Arrange using (var sourceCacheContext = new SourceCacheContext()) using (var packagesFolder = 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() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Authors = "author", Description = "desc", IconUrl = "http://www.tempuri.org/", Icon = "icon.png", Language = "en-us", MinClientVersion = "1.0.0", Title = "title", Tags = "a b d", Summary = "summary", LicenseUrl = "http://www.tempuri.org/lic", ProjectUrl = "http://www.tempuri.org/proj", ReleaseNotes = "notes", Owners = "owners", Copyright = "copyright", RequireLicenseAcceptance = "true" }, Files = new List <TestNupkgFile>() { new TestNupkgFile("icon.png") } }; var testPackage2 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "2.0.0", Authors = "author2", Description = "desc2", IconUrl = "http://www.tempuri2.org/", Icon = "icon.png", Language = "en-us", MinClientVersion = "1.0.0", Title = "title2", Tags = "a b c", Summary = "summary2", LicenseUrl = "http://www.tempuri.org/lic2", ProjectUrl = "http://www.tempuri.org/proj2", ReleaseNotes = "notes2", Owners = "owners2", Copyright = "copyright2", RequireLicenseAcceptance = "true" }, Files = new List <TestNupkgFile>() { new TestNupkgFile("icon.png") } }; 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 zipFile2 = testPackage2.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>() { zipFile2.FullName }, false, false, log); success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, 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 <PackageMetadataResource>(); var results = await resource.GetMetadataAsync("packageA", true, true, sourceCacheContext, log, CancellationToken.None); var resultArray = results.OrderBy(e => e.Identity.Version).ToArray(); // Assert Assert.True(success, log.ToString()); Assert.Equal(testPackage.Nuspec.Authors, resultArray[0].Authors); Assert.Equal(testPackage.Nuspec.Description, resultArray[0].Description); Assert.Null(resultArray[0].DownloadCount); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/1.0.0/icon", resultArray[0].IconUrl.AbsoluteUri); Assert.Equal(testPackage.Nuspec.Id, resultArray[0].Identity.Id); Assert.Equal(testPackage.Nuspec.Version.ToString(), resultArray[0].Identity.Version.ToString()); Assert.Equal(testPackage.Nuspec.LicenseUrl, resultArray[0].LicenseUrl.AbsoluteUri); Assert.Null(resultArray[0].Owners); Assert.Equal(testPackage.Nuspec.ProjectUrl, resultArray[0].ProjectUrl.AbsoluteUri); Assert.Equal(testPackage.Nuspec.Summary, resultArray[0].Summary); Assert.Equal("a, b, d", resultArray[0].Tags); Assert.Equal(testPackage.Nuspec.Title, resultArray[0].Title); Assert.True(resultArray[0].Published.Value.Year == DateTime.UtcNow.Year); Assert.Equal("https://localhost:8080/testFeed/", resultArray[0].ReportAbuseUrl.AbsoluteUri); Assert.True(resultArray[0].RequireLicenseAcceptance); Assert.Equal(testPackage2.Nuspec.Authors, resultArray[1].Authors); Assert.Equal(testPackage2.Nuspec.Description, resultArray[1].Description); Assert.Null(resultArray[1].DownloadCount); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/2.0.0/icon", resultArray[1].IconUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Id, resultArray[1].Identity.Id); Assert.Equal(testPackage2.Nuspec.Version.ToString(), resultArray[1].Identity.Version.ToString()); Assert.Equal(testPackage2.Nuspec.LicenseUrl, resultArray[1].LicenseUrl.AbsoluteUri); Assert.Null(resultArray[1].Owners); Assert.Equal(testPackage2.Nuspec.ProjectUrl, resultArray[1].ProjectUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Summary, resultArray[1].Summary); Assert.Equal("a, b, c", resultArray[1].Tags); Assert.Equal(testPackage2.Nuspec.Title, resultArray[1].Title); Assert.True(resultArray[1].Published.Value.Year == DateTime.UtcNow.Year); Assert.Equal("https://localhost:8080/testFeed/", resultArray[1].ReportAbuseUrl.AbsoluteUri); Assert.True(resultArray[1].RequireLicenseAcceptance); } }
public async Task SubFeed_InitMultipleFeedsVerifyDestroyDoesNotModifyOthers() { using (var packagesFolder = new TestFolder()) using (var testContext = new AmazonS3TestContext()) using (var testContext2 = new AmazonS3TestContext()) { // 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 AmazonS3FileSystem( testContext.LocalCache, root, root, testContext.Client, testContext.BucketName, ServerSideEncryptionMethod.None, feedSubPath: subFeedName ); testContext2.FileSystem = new AmazonS3FileSystem( testContext.LocalCache, root2, root2, testContext.Client, testContext.BucketName, ServerSideEncryptionMethod.None, 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(); } }
public void SetUp() { testFolder = new TestFolder { Path = "root\\Tests"}; resultFolder = new TestFolder { Path = "other\\Results"}; testFiles = new TestFiles(testFolder, resultFolder, new StoryTestSuite(new FileExclusions(), s => true)); }
public async Task NuGetReader_PackageSearchResourceAsync() { // Arrange using (var packagesFolder = 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() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Authors = "author", Description = "desc", IconUrl = "http://www.tempuri.org", Language = "en-us", MinClientVersion = "1.0.0", Title = "title", Tags = "a b d", Summary = "summary", LicenseUrl = "http://www.tempuri.org/lic", ProjectUrl = "http://www.tempuri.org/proj", ReleaseNotes = "notes", Owners = "owners", Copyright = "copyright", RequireLicenseAcceptance = "true" } }; var testPackage2 = new TestNupkg() { Nuspec = new TestNuspec() { Id = "packageA", Version = "2.0.0", Authors = "author2", Description = "desc2", IconUrl = "http://www.tempuri2.org/", Language = "en-us", MinClientVersion = "1.0.0", Title = "title2", Tags = "a b c", Summary = "summary2", LicenseUrl = "http://www.tempuri.org/lic2", ProjectUrl = "http://www.tempuri.org/proj2", ReleaseNotes = "notes2", Owners = "owners2", Copyright = "copyright2", RequireLicenseAcceptance = "true" } }; 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 zipFile2 = testPackage2.Save(packagesFolder.Root); var settings = LocalSettings.Load(sleetConfigPath); var fileSystem = FileSystemFactory.CreateFileSystem(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile2.FullName }, false, false, log); success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, 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 <PackageSearchResource>(); var results = await resource.SearchAsync(string.Empty, new SearchFilter(includePrerelease : true), 0, 10, log, CancellationToken.None); var result = results.Single(); var versions = await result.GetVersionsAsync(); // Assert Assert.True(success, log.ToString()); Assert.Equal(testPackage2.Nuspec.Authors, result.Authors); Assert.Equal(testPackage2.Nuspec.Description, result.Description); Assert.Equal(0, result.DownloadCount); Assert.Equal(testPackage2.Nuspec.IconUrl, result.IconUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Id, result.Identity.Id); Assert.Equal(testPackage2.Nuspec.Version.ToString(), result.Identity.Version.ToString()); Assert.Equal(testPackage2.Nuspec.LicenseUrl, result.LicenseUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Owners, result.Owners); Assert.Equal(testPackage2.Nuspec.ProjectUrl, result.ProjectUrl.AbsoluteUri); Assert.Equal(testPackage2.Nuspec.Summary, result.Summary); Assert.Equal("a, b, c", result.Tags); Assert.Equal(testPackage2.Nuspec.Title, result.Title); Assert.Equal(2, versions.Count()); Assert.Equal("1.0.0", versions.First().Version.ToString()); Assert.Equal("2.0.0", versions.Skip(1).First().Version.ToString()); } }
public async Task RetentionPruneCommand_NoopsWhenNoPackagesNeedToBeRemoved() { // 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, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>() { new PackageIdentity("a", NuGetVersion.Parse("1.0.0")), new PackageIdentity("a", NuGetVersion.Parse("2.0.0")), new PackageIdentity("a", NuGetVersion.Parse("3.0.0")), new PackageIdentity("a", NuGetVersion.Parse("4.0.0")), new PackageIdentity("a", NuGetVersion.Parse("5.0.0")), }; foreach (var id in identities) { var testPackage = new TestNupkg(id.Id, id.Version.ToFullString()); var zipFile = testPackage.Save(packagesFolder.Root); } await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); var pruneContext = new RetentionPruneCommandContext() { StableVersionMax = 10, PrereleaseVersionMax = 10 }; // Run prune await RetentionPruneCommand.PrunePackages(context, pruneContext); // Validate var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var packageIndex = new PackageIndex(context); var indexPackages = await packageIndex.GetPackagesAsync(); // Assert indexPackages.Count().Should().Be(5); } }
public void SmokeTestCreateDocument() { IDictionary <string, object> properties = new Dictionary <string, object>(); properties[PropertyIds.Name] = "test-smoke.txt"; properties[PropertyIds.ObjectTypeId] = DefaultDocumentType; byte[] content = UTF8Encoding.UTF8.GetBytes("Hello World!"); ContentStream contentStream = new ContentStream(); contentStream.FileName = properties[PropertyIds.Name] as string; contentStream.MimeType = "text/plain"; contentStream.Length = content.Length; contentStream.Stream = new MemoryStream(content); IDocument doc = TestFolder.CreateDocument(properties, contentStream, null); // check doc Assert.NotNull(doc); Assert.NotNull(doc.Id); Assert.AreEqual(properties[PropertyIds.Name], doc.Name); Assert.AreEqual(BaseTypeId.CmisDocument, doc.BaseTypeId); Assert.True(doc.AllowableActions.Actions.Contains(Actions.CanGetProperties)); Assert.False(doc.AllowableActions.Actions.Contains(Actions.CanGetChildren)); // check type IObjectType type = doc.ObjectType; Assert.NotNull(type); Assert.NotNull(type.Id); Assert.AreEqual(properties[PropertyIds.ObjectTypeId], type.Id); // check versions IList <IDocument> versions = doc.GetAllVersions(); Assert.NotNull(versions); Assert.AreEqual(1, versions.Count); //Assert.AreEqual(doc.Id, versions[0].Id); // check content IContentStream retrievedContentStream = doc.GetContentStream(); Assert.NotNull(retrievedContentStream); Assert.NotNull(retrievedContentStream.Stream); MemoryStream byteStream = new MemoryStream(); byte[] buffer = new byte[4096]; int b = 1; while (b > 0) { b = retrievedContentStream.Stream.Read(buffer, 0, buffer.Length); byteStream.Write(buffer, 0, b); } byte[] retrievedContent = byteStream.ToArray(); Assert.NotNull(retrievedContent); Assert.AreEqual(content.Length, retrievedContent.Length); for (int i = 0; i < content.Length; i++) { Assert.AreEqual(content[i], retrievedContent[i]); } // update name properties = new Dictionary <string, object>(); properties[PropertyIds.Name] = "test2-smoke.txt"; IObjectId newId = doc.UpdateProperties(properties); IDocument doc2 = Session.GetObject(newId) as IDocument; Assert.NotNull(doc2); doc2.Refresh(); Assert.AreEqual(properties[PropertyIds.Name], doc2.Name); Assert.AreEqual(properties[PropertyIds.Name], doc2.GetPropertyValue(PropertyIds.Name)); IProperty nameProperty = doc2[PropertyIds.Name]; Assert.NotNull(nameProperty.PropertyType); Assert.AreEqual(properties[PropertyIds.Name], nameProperty.Value); Assert.AreEqual(properties[PropertyIds.Name], nameProperty.FirstValue); byte[] content2 = UTF8Encoding.UTF8.GetBytes("Hello Universe!"); ContentStream contentStream2 = new ContentStream(); contentStream2.FileName = properties[PropertyIds.Name] as string; contentStream2.MimeType = "text/plain"; contentStream2.Length = content2.Length; contentStream2.Stream = new MemoryStream(content2); // doc.SetContentStream(contentStream2, true); doc2.Delete(true); try { doc.Refresh(); Assert.Fail("Document shouldn't exist anymore!"); } catch (CmisObjectNotFoundException) { } }
public async Task AddRemove_AddManyPackagesThenRemoveSome() { // 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, SymbolsEnabled = true } }; var identities = new HashSet <PackageIdentity>(); var ids = new[] { "a", "b", "c", "d" }; foreach (var id in ids) { for (var i = 0; i < 50; i++) { var testPackage = new TestNupkg(id, $"{i}.0.0"); var zipFile = testPackage.Save(packagesFolder.Root); identities.Add(new PackageIdentity(testPackage.Nuspec.Id, NuGetVersion.Parse(testPackage.Nuspec.Version))); } } var catalog = new Catalog(context); var registration = new Registrations(context); var packageIndex = new PackageIndex(context); var search = new Search(context); var autoComplete = new AutoComplete(context); await InitCommand.InitAsync(context); await PushCommand.RunAsync(context.LocalSettings, context.Source, new List <string>() { packagesFolder.Root }, false, false, context.Log); // Act // run delete command await DeleteCommand.RunAsync(context.LocalSettings, context.Source, "b", null, "removing", false, context.Log); var validateOutput = await ValidateCommand.RunAsync(context.LocalSettings, context.Source, context.Log); // read output var catalogEntries = await catalog.GetIndexEntriesAsync(); var catalogExistingEntries = await catalog.GetExistingPackagesIndexAsync(); var catalogPackages = await catalog.GetPackagesAsync(); var regPackages = new HashSet <PackageIdentity>(); foreach (var id in ids) { regPackages.UnionWith(await registration.GetPackagesByIdAsync(id)); } var indexPackages = await packageIndex.GetPackagesAsync(); var searchPackages = await search.GetPackagesAsync(); var autoCompletePackages = await autoComplete.GetPackageIds(); // Assert Assert.True(validateOutput); Assert.Equal(identities.Count + 50, catalogEntries.Count); Assert.Equal(identities.Count - 50, catalogExistingEntries.Count); regPackages.Count.Should().Be(identities.Count - 50); Assert.Equal(identities.Count - 50, indexPackages.Count); Assert.Equal(identities.Count - 50, searchPackages.Count); Assert.Equal(ids.Length - 1, autoCompletePackages.Count); } }
public void TestCleanup() { // Runs after each test. (Optional) TestFolder.Delete(true); // PURGE EVERYTHING }
public async Task NuGetReader_DependencyInfoResource_DependencyGroupsAsync() { // Arrange using (var packagesFolder = 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() { Nuspec = new TestNuspec() { Id = "packageA", Version = "1.0.0", Dependencies = new List <PackageDependencyGroup>() { new PackageDependencyGroup(NuGetFramework.Parse("net46"), new List <PackageDependency>() { }), new PackageDependencyGroup(NuGetFramework.Parse("net45"), new[] { new PackageDependency("packageB", VersionRange.Parse("1.0.0")), new PackageDependency("packageC", VersionRange.Parse("2.0.0")) }), new PackageDependencyGroup(NuGetFramework.Parse("any"), new List <PackageDependency>() { new PackageDependency("packageB", VersionRange.Parse("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 = FileSystemFactory.CreateFileSystem(settings, cache, "local"); var success = await InitCommand.RunAsync(settings, fileSystem, log); // Act // Run sleet success &= await PushCommand.RunAsync(settings, fileSystem, new List <string>() { zipFile.FullName }, 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 dependencyInfoResource = await localSource.GetResourceAsync <DependencyInfoResource>(); var dependencyPackagesNet46 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net46"), log, CancellationToken.None); var dependencyPackageNet46 = dependencyPackagesNet46.Single(); var depString46 = string.Join("|", dependencyPackageNet46.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); var dependencyPackagesNet45 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net45"), log, CancellationToken.None); var dependencyPackageNet45 = dependencyPackagesNet45.Single(); var depString45 = string.Join("|", dependencyPackageNet45.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); var dependencyPackagesNet40 = await dependencyInfoResource.ResolvePackages("packageA", NuGetFramework.Parse("net40"), log, CancellationToken.None); var dependencyPackageNet40 = dependencyPackagesNet40.Single(); var depString40 = string.Join("|", dependencyPackageNet40.Dependencies.Select(d => d.Id + " " + d.VersionRange.ToNormalizedString())); // Assert Assert.True(success, log.ToString()); Assert.Equal("https://localhost:8080/testFeed/flatcontainer/packagea/1.0.0/packagea.1.0.0.nupkg", dependencyPackageNet46.DownloadUri.AbsoluteUri); Assert.True(dependencyPackageNet46.Listed); Assert.Equal("packageA", dependencyPackageNet46.Id); Assert.Equal("1.0.0", dependencyPackageNet46.Version.ToNormalizedString()); Assert.Equal("", depString46); Assert.Equal("packageB [1.0.0, )|packageC [2.0.0, )", depString45); Assert.Equal("packageB [1.0.0, )", depString40); } }
public void SmokeTestCreateFolder() { IDictionary <string, object> properties = new Dictionary <string, object>(); properties[PropertyIds.Name] = "test-smoke"; properties[PropertyIds.ObjectTypeId] = DefaultFolderType; IFolder folder = TestFolder.CreateFolder(properties); // check folder Assert.NotNull(folder); Assert.NotNull(folder.Id); Assert.AreEqual(properties[PropertyIds.Name], folder.Name); Assert.AreEqual(BaseTypeId.CmisFolder, folder.BaseTypeId); Assert.AreEqual(TestFolder.Id, folder.FolderParent.Id); Assert.False(folder.IsRootFolder); Assert.True(folder.Path.StartsWith("/")); Assert.True(folder.AllowableActions.Actions.Contains(Actions.CanGetProperties)); Assert.True(folder.AllowableActions.Actions.Contains(Actions.CanGetChildren)); Assert.False(folder.AllowableActions.Actions.Contains(Actions.CanGetContentStream)); // check children foreach (ICmisObject cmisObject in folder.GetChildren()) { Assert.Fail("Folder shouldn't have children!"); } // check descendants bool?descSupport = Session.RepositoryInfo.Capabilities.IsGetDescendantsSupported; if (descSupport.HasValue && descSupport.Value) { IList <ITree <IFileableCmisObject> > list = folder.GetDescendants(-1); if (list != null) { foreach (ITree <IFileableCmisObject> desc in list) { Assert.Fail("Folder shouldn't have children!"); } } } else { Console.WriteLine("GetDescendants not supported!"); } // check folder tree bool?folderTreeSupport = Session.RepositoryInfo.Capabilities.IsGetFolderTreeSupported; if (folderTreeSupport.HasValue && folderTreeSupport.Value) { IList <ITree <IFileableCmisObject> > list = folder.GetFolderTree(-1); if (list != null) { foreach (ITree <IFileableCmisObject> desc in list) { Assert.Fail("Folder shouldn't have children!"); } } } else { Console.WriteLine("GetFolderTree not supported!"); } // check parents IFolder parent = folder.FolderParent; Assert.NotNull(parent); Assert.AreEqual(TestFolder.Id, parent.Id); IList <IFolder> parents = folder.Parents; Assert.NotNull(parents); Assert.True(parents.Count > 0); bool found = false; foreach (IFolder p in parents) { if (TestFolder.Id == p.Id) { found = true; break; } } Assert.True(found); folder.Delete(true); try { folder.Refresh(); Assert.Fail("Folder shouldn't exist anymore!"); } catch (CmisObjectNotFoundException) { } }