public void FindPackagesById_IgnoresPackagesWithoutHashFiles() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); fileSystem.AddFile(Path.Combine("foo", "1.0.0", "foo.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg.sha512"), "345sha"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg"), "content"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-402", "bar.nuspec"), "content"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-402", "bar.nupkg"), "content"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-402", "bar.1.0.0-beta1-402.nupkg"), "nupkg contents"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg.sha512"), "beta1 hash"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg"), "content"); var repository = new ExpandedPackageRepository(fileSystem); // Act var packages = repository.FindPackagesById("Bar").OrderBy(p => p.Identity.Version).ToList(); // Assert Assert.Equal(2, packages.Count); Assert.Equal(SemanticVersion.Parse("1.0.0-beta1"), packages[0].Identity.Version); Assert.Equal(SemanticVersion.Parse("1.0.0-beta1-345"), packages[1].Identity.Version); }
private void GetPackageLocally(string packageId, string version, string workDirectory) { //Add the default source if there are none present var workingFileSystem = new PhysicalFileSystem(workDirectory); foreach (string source in Sources) { Uri uri; if (Uri.TryCreate(source, UriKind.Absolute, out uri)) { AggregateRepository repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(PackageRepositoryFactory.Default, CreateSourceProvider(new[] {source}), new[] {source}); IPackage package; if (repository.TryFindPackage(packageId, new Version(version), out package)) { Console.WriteLine("Attempting to download package {0}.{1} via {2}", packageId, version, uri.ToString()); try { string filepath = Path.Combine(workDirectory, package.Id + "-" + package.Version + ".nupkg"); workingFileSystem.AddFile(filepath, package.GetStream()); break; } catch (Exception e) { Console.WriteError(e); } } } } }
public void DeleteReadonlyFile() { // Arrange var root = Path.Combine(Path.GetTempPath()); var path = Path.GetRandomFileName(); var target = new PhysicalFileSystem(root); using (var memStream = new MemoryStream( System.Text.Encoding.UTF8.GetBytes("hello"))) { target.AddFile(path, memStream); } // Make the file read-only var fullPath = Path.Combine(root, path); File.SetAttributes(fullPath, File.GetAttributes(fullPath) | FileAttributes.ReadOnly); Assert.True(File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly)); // Act target.DeleteFile(path); // Assert Assert.True(!File.Exists(fullPath)); }
private void GetPackageLocally(string packageId, string version, string workDirectory) { //Add the default source if there are none present var workingFileSystem = new PhysicalFileSystem(workDirectory); foreach (string source in Sources) { Uri uri; if (Uri.TryCreate(source, UriKind.Absolute, out uri)) { AggregateRepository repository = AggregateRepositoryHelper.CreateAggregateRepositoryFromSources(PackageRepositoryFactory.Default, CreateSourceProvider(new[] { source }), new[] { source }); IPackage package; if (repository.TryFindPackage(packageId, new SemanticVersion(version), out package)) { Console.WriteLine("Attempting to download package {0}.{1} via {2}", packageId, version, uri.ToString()); try { string filepath = Path.Combine(workDirectory, package.Id + "-" + package.Version + ".nupkg"); workingFileSystem.AddFile(filepath, package.GetStream()); break; } catch (Exception e) { Console.WriteError(e); } } } } }
public void FindPackageById_ReturnsSpecificVersionIfHashFileExists() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); fileSystem.AddFile(Path.Combine("foo", "1.0.0", "foo.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg.sha512"), "hash"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.1.0.0-beta1-345.nupkg"), "content"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>test-author</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg.sha512"), "cotnent"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.1.0.0-beta1.nupkg"), "cotnent"); var repository = new ExpandedPackageRepository(fileSystem); // Act var package = repository.FindPackage("Bar", NuGetVersion.Parse("1.0.0.0-beta1")); // Assert Assert.NotNull(package); Assert.Equal(SemanticVersion.Parse("1.0.0-beta1"), package.Identity.Version); var author = package.Nuspec.GetAuthors(); Assert.Equal("test-author", author); }
public void AddFileThrowsArgumentNullExceptionIfWriteToStreamIsNull() { // Arrange var root = Path.GetRandomFileName(); var target = new PhysicalFileSystem(root); // Act and Assert ExceptionAssert.ThrowsArgNull(() => target.AddFile(Path.GetRandomFileName(), writeToStream: null), "writeToStream"); }
public void FindPackageById_IgnoresVersionsWithoutHashFiles() { // Arrange var fileSystem = new PhysicalFileSystem(tmpDir.Path); fileSystem.AddFile(Path.Combine("foo", "1.0.0", "foo.nupkg"), @"Foo.nupkg contents"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1-345", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine("bar", "1.0.0-beta1", "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>test-author</authors><description>None</description></metadata></package>"); var repository = new ExpandedPackageRepository(fileSystem); // Act var package = repository.FindPackage("Foo", NuGetVersion.Parse("1.0.0")); // Assert Assert.Null(package); }
public void GetPackages_SkipsPackagesWithoutHashFile() { // Arrange var barPackage = new PackageBuilder { Id = "Foo", Version = NuGetVersion.Parse("1.0.0-beta1-345"), Description = "Some description", }; barPackage.Authors.Add("test author"); barPackage.Files.Add( CreateMockedPackageFile(@"lib\net45", "Foo.dll", "lib contents").Object); var fileSystem = new PhysicalFileSystem(tmpDir.Path); var fooRoot = Path.Combine(fileSystem.Root, "foo", "1.0.0"); fileSystem.AddFile(Path.Combine(fooRoot, "foo.1.0.0.nupkg"), ""); fileSystem.AddFile(Path.Combine(fooRoot, "foo.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>"); var barRoot = Path.Combine("bar", "1.0.0-beta1-345"); fileSystem.AddFile(Path.Combine(barRoot, "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1-345</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1-345.nupkg.sha512"), "123"); fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1-345.nupkg"), GetPackageStream(barPackage)); var repository = new ExpandedPackageRepository(fileSystem); // Act var packages = repository.GetPackages().ToList(); // Assert var package = Assert.Single(packages); Assert.Equal("bar", package.Identity.Id); Assert.Equal(NuGetVersion.Parse("1.0.0-beta1-345"), package.Identity.Version); }
public void Can_Read_And_Deserialize_Macro_From_Disc() { // Arrange var serviceStackSerializer = new ServiceStackJsonSerializer(); var serializationService = new SerializationService(serviceStackSerializer); var fileSystem = new PhysicalFileSystem("~/App_Data/Macros"); var macro = new Macro { Alias = "test", CacheByPage = false, CacheByMember = false, DontRender = true, Name = "Test", Xslt = "/xslt/testMacro.xslt", UseInEditor = false }; macro.Properties = new List <IMacroProperty>(); macro.Properties.Add(new MacroProperty { Alias = "level", Name = "Level", SortOrder = 0, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Number() }); macro.Properties.Add(new MacroProperty { Alias = "fixedTitle", Name = "Fixed Title", SortOrder = 1, PropertyType = new Umbraco.Core.Macros.PropertyTypes.Text() }); // Act var json = serializationService.ToStream(macro); string jsonString = json.ResultStream.ToJsonString(); fileSystem.AddFile("test-serialized-Macro.macro", json.ResultStream, true); Stream stream = fileSystem.OpenFile("test-serialized-Macro.macro"); object o = serializationService.FromStream(stream, typeof(Macro)); var deserialized = o as IMacro; // Assert Assert.That(json.Success, Is.True); Assert.That(jsonString, Is.Not.Empty); Assert.That(fileSystem.FileExists("test-serialized-Macro.macro"), Is.True); Assert.That(deserialized, Is.Not.Null); Assert.That(deserialized.Name, Is.EqualTo(macro.Name)); Assert.That(deserialized.Alias, Is.EqualTo(macro.Alias)); }
public void SetUpFileSystem() { var path = GlobalSettings.UmbracoScriptsPath; _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, LoggerFactory.CreateLogger <PhysicalFileSystem>(), HostingEnvironment.MapPathWebRoot(path), HostingEnvironment.ToAbsolute(path)); _fileSystems = FileSystemsCreator.CreateTestFileSystems( LoggerFactory, IOHelper, GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment, null, null, null, _fileSystem, null); using (var stream = CreateStream("Umbraco.Sys.registerNamespace(\"Umbraco.Utils\");")) { _fileSystem.AddFile("test-script.js", stream); } }
public void SetUpFileSystem() { var path = HostingEnvironment.MapPathWebRoot(GlobalSettings.UmbracoCssPath); _fileSystem = new PhysicalFileSystem(IOHelper, HostingEnvironment, GetRequiredService <ILogger <PhysicalFileSystem> >(), path, "/css"); _fileSystems = FileSystemsCreator.CreateTestFileSystems( LoggerFactory, IOHelper, GetRequiredService <IOptions <GlobalSettings> >(), HostingEnvironment, null, null, _fileSystem, null, null); var stream = CreateStream("body {background:#EE7600; color:#FFF;}"); _fileSystem.AddFile("styles.css", stream); }
private Attempt <CodeFileDisplay> UpdateFile(CodeFileDisplay file) { // if the file is an appsettings.json file, save a backup of the original. if (file.VirtualPath.InvariantEndsWith("appsettings.json")) { _fileSystem.CopyFile(file.VirtualPath, $"{file.VirtualPath}.{DateTime.Now:yyyyMMdd-HHmmss}"); } // file.VirtualPath = file.VirtualPath.EnsureCorrectFileExtension(configFileExtension); // file.Name = file.Name.EnsureCorrectFileExtension(configFileExtension); //if (!Path.GetFileNameWithoutExtension(file.VirtualPath).InvariantEquals(Path.GetFileNameWithoutExtension(file.Name))) //{ // _themesFileSystem.DeleteFile(file.VirtualPath); // string[] strArray = file.VirtualPath.Split('/'); // file.VirtualPath = string.Join("/", ((IEnumerable<string>)strArray).Take(strArray.Length - 1)).EnsureEndsWith('/') + file.Name; //} Attempt <CodeFileDisplay> attempt; try { using (MemoryStream memoryStream = new()) { using StreamWriter streamWriter = new(memoryStream); streamWriter.Write(file.Content); streamWriter.Flush(); _fileSystem.AddFile(file.VirtualPath.TrimStart('/'), memoryStream, true); } attempt = Attempt <CodeFileDisplay> .Succeed(file); } catch (IOException ioe) { _logger.LogError(ioe, "Could not save file {file}", file.Path); attempt = Attempt <CodeFileDisplay> .Fail(); } return(attempt); }
public void GetPackages_ReturnsAllPackagesInsideDirectory() { // Arrange var fooPackage = new PackageBuilder { Id = "Foo", Version = NuGetVersion.Parse("1.0.0"), Description = "Some description", }; fooPackage.Authors.Add("test author"); fooPackage.Files.Add( CreateMockedPackageFile(@"lib\net40", "Foo.dll", "lib contents").Object); var barPackage = new PackageBuilder { Id = "Bar", Version = NuGetVersion.Parse("1.0.0-beta1"), Description = "Some description", }; barPackage.Authors.Add("test author"); barPackage.Files.Add( CreateMockedPackageFile("", "README.md", "lib contents").Object); barPackage.Files.Add( CreateMockedPackageFile(@"content", "qwerty.js", "bar contents").Object); barPackage.Files.Add( CreateMockedPackageFile(@"lib\net451", "test.dll", "test-dll").Object); var fileSystem = new PhysicalFileSystem(tmpDir.Path); var fooRoot = Path.Combine(fileSystem.Root, "foo", "1.0.0"); fileSystem.AddFile(Path.Combine(fooRoot, "foo.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Foo</id><version>1.0.0</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine(fooRoot, "foo.1.0.0.nupkg.sha512"), "Foo-sha"); fileSystem.AddFile(Path.Combine(fooRoot, "foo.1.0.0.nupkg"), GetPackageStream(fooPackage)); var barRoot = Path.Combine(fileSystem.Root, "bar", "1.0.0-beta1"); fileSystem.AddFile(Path.Combine(barRoot, "bar.nuspec"), @"<?xml version=""1.0""?><package><metadata><id>Bar</id><version>1.0.0.0-beta1</version><authors>None</authors><description>None</description></metadata></package>"); fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1.nupkg.sha512"), "bar-sha"); fileSystem.AddFile(Path.Combine(barRoot, "bar.1.0.0-beta1.nupkg"), GetPackageStream(barPackage)); var repository = new ExpandedPackageRepository(fileSystem); // Act var packages = repository.GetPackages().OrderBy(p => p.Identity.Id).ToList(); // Assert Assert.Equal(2, packages.Count); var package = packages[1]; Assert.Equal("foo", package.Identity.Id); Assert.Equal(SemanticVersion.Parse("1.0.0"), package.Identity.Version); using (var reader = package.GetReader()) { Assert.Equal("Foo", reader.GetIdentity().Id); Assert.Equal(package.Identity, reader.GetIdentity()); } }