#17745: Decoding Nuget paths.

--HG--
branch : 1.x
This commit is contained in:
Andre Rodrigues
2011-04-15 16:44:12 -07:00
parent 8c67c9f386
commit 674fe6ecb8
5 changed files with 114 additions and 63 deletions

View File

@@ -149,6 +149,7 @@
<Compile Include="Indexing\LuceneIndexProviderTests.cs" />
<Compile Include="Indexing\LuceneSearchBuilderTests.cs" />
<Compile Include="Media\Services\MediaServiceTests.cs" />
<Compile Include="Packaging\Services\FileBasedProjectSystemTests.cs" />
<Compile Include="Packaging\Services\FolderUpdaterTests.cs" />
<Compile Include="Packaging\Services\PackageInstallerTests.cs" />
<Compile Include="Recipes\RecipeHandlers\ModuleRecipeHandlerTest.cs" />
@@ -162,7 +163,6 @@
<Compile Include="Scripting\SimpleScriptingTests.cs" />
<Compile Include="DatabaseEnabledTestsBase.cs" />
<Compile Include="Media\Extensions\LongExtensionsTests.cs" />
<EmbeddedResource Include="Packaging\Services\HelloDriver.cs.txt" />
<Compile Include="Packaging\Services\PackageBuilderTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Roles\Controllers\AdminControllerTests.cs" />
@@ -296,12 +296,7 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Packaging\Services\Hello.World.csproj.txt" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Recipes\Services\FoldersData\Sample1\Module.txt" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<EmbeddedResource Include="Recipes\Services\FoldersData\Sample1\Recipes\cms.recipe.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@@ -0,0 +1,103 @@
using System.IO;
using Autofac;
using Moq;
using NuGet;
using NUnit.Framework;
using Orchard.Caching;
using Orchard.Environment;
using Orchard.Environment.Extensions;
using Orchard.Environment.Extensions.Models;
using Orchard.FileSystems.VirtualPath;
using Orchard.FileSystems.WebSite;
using Orchard.Packaging.Services;
using Orchard.Tests.Stubs;
using Orchard.UI.Notify;
using IPackageBuilder = Orchard.Packaging.Services.IPackageBuilder;
using PackageBuilder = Orchard.Packaging.Services.PackageBuilder;
namespace Orchard.Tests.Modules.Packaging.Services {
[TestFixture]
public class FileBasedProjectSystemTests : ContainerTestBase {
private const string PackageIdentifier = "Hello.World";
private readonly string _basePath = Path.Combine(Path.GetTempPath(), "PackageInstallerTests");
private Mock<IVirtualPathProvider> _mockedVirtualPathProvider;
protected override void Register(ContainerBuilder builder) {
builder.RegisterType<PackageBuilder>().As<IPackageBuilder>();
builder.RegisterType<PackageInstaller>().As<IPackageInstaller>();
builder.RegisterType<ExtensionManager>().As<IExtensionManager>();
builder.RegisterType<FolderUpdater>().As<IFolderUpdater>();
builder.RegisterInstance(new Mock<INotifier>().Object);
builder.RegisterType<StubCacheManager>().As<ICacheManager>();
_mockedVirtualPathProvider = new Mock<IVirtualPathProvider>();
builder.RegisterInstance(_mockedVirtualPathProvider.Object).As<IVirtualPathProvider>();
builder.RegisterType<DefaultOrchardFrameworkAssemblies>().As<IOrchardFrameworkAssemblies>();
builder.RegisterType<InMemoryWebSiteFolder>().As<IWebSiteFolder>()
.As<InMemoryWebSiteFolder>().InstancePerLifetimeScope();
}
[SetUp]
public override void Init() {
base.Init();
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
Directory.CreateDirectory(_basePath);
}
[TestFixtureTearDown]
public void Clean() {
if (Directory.Exists(_basePath)) {
Directory.Delete(_basePath, true);
}
}
private Stream BuildHelloWorld(IPackageBuilder packageBuilder) {
// add some content because NuGet requires it
var folder = _container.Resolve<InMemoryWebSiteFolder>();
using (var sourceStream = GetType().Assembly.GetManifestResourceStream(GetType(), "Hello.World.csproj.txt")) {
folder.AddFile("~/Modules/Hello.World/Hello.World.csproj", new StreamReader(sourceStream).ReadToEnd());
}
return packageBuilder.BuildPackage(new ExtensionDescriptor {
ExtensionType = DefaultExtensionTypes.Module,
Id = PackageIdentifier,
Version = "1.0",
Description = "a",
Author = "b"
});
}
[Test]
public void ValidPathsTest() {
IPackageBuilder packageBuilder = _container.Resolve<IPackageBuilder>();
Stream stream = BuildHelloWorld(packageBuilder);
string filename = Path.Combine(_basePath, "package.nupkg");
using (var fileStream = File.Create(filename)) {
stream.CopyTo(fileStream);
}
ZipPackage zipPackage = new ZipPackage(filename);
IPackageInstaller packageInstaller = _container.Resolve<IPackageInstaller>();
_mockedVirtualPathProvider.Setup(v => v.MapPath(It.IsAny<string>()))
.Returns<string>(path => Path.Combine(_basePath, path.Replace("~\\", "")));
_mockedVirtualPathProvider.Setup(v => v.Combine(It.IsAny<string[]>()))
.Returns<string[]>(Path.Combine);
PackageInfo packageInfo = packageInstaller.Install(zipPackage, _basePath, _basePath);
Assert.That(packageInfo, Is.Not.Null);
Assert.That(Directory.Exists(Path.Combine(_basePath, "Modules/Hello.World")));
Assert.That(File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Hello.World.csproj")));
Assert.That(!File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Service%References/SomeReference.cs")));
Assert.That(File.Exists(Path.Combine(_basePath, "Modules/Hello.World/Service References/SomeReference.cs")));
}
}
}

View File

@@ -70,37 +70,9 @@
</ItemGroup>
<ItemGroup>
<Compile Include="AdminMenu.cs" />
<Compile Include="Commands\GalleryCommands.cs" />
<Compile Include="Commands\PackagingCommands.cs" />
<Compile Include="Controllers\GalleryController.cs" />
<Compile Include="DefaultPackagingUpdater.cs" />
<Compile Include="ResourceManifest.cs" />
<Compile Include="Services\AtomExtensions.cs" />
<Compile Include="Services\IPackageBuilder.cs" />
<Compile Include="Services\IPackageExpander.cs" />
<Compile Include="Services\IPackageManager.cs" />
<Compile Include="Services\IPackagingSourceManager.cs" />
<Compile Include="Services\PackageBuilder.cs" />
<Compile Include="Services\PackageData.cs" />
<Compile Include="Services\PackageExpander.cs" />
<Compile Include="Services\PackageManager.cs" />
<Compile Include="Services\PackagingEntry.cs" />
<Compile Include="Services\PackagingSource.cs" />
<Compile Include="Services\PackagingSourceManager.cs" />
<Compile Include="ViewModels\PackagingAddSourceViewModel.cs" />
<Compile Include="ViewModels\PackagingHarvestViewModel.cs" />
<Compile Include="ViewModels\PackagingModulesViewModel.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModels\PackagingSourcesViewModel.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Module.txt" />
<Content Include="Styles\admin.css" />
<Content Include="Views\Gallery\AddSource.cshtml" />
<Content Include="Views\Gallery\Harvest.cshtml" />
<Content Include="Views\Gallery\Modules.cshtml" />
<Content Include="Views\Gallery\Sources.cshtml" />
<Content Include="Views\Gallery\_Subnav.cshtml" />
<Content Include="Service References\SomeReference.cs" />
<Content Include="Views\Web.config" />
</ItemGroup>
<ItemGroup>

View File

@@ -1,9 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Orchard.Tests.Modules.Packaging {
class HelloDriver {
}
}

View File

@@ -47,7 +47,7 @@ namespace Orchard.Packaging.Services {
}
public string GetFullPath(string path) {
return Path.Combine(Root, path);
return Path.Combine(Root, Uri.UnescapeDataString(path));
}
protected virtual string GetReferencePath(string name) {
@@ -55,12 +55,12 @@ namespace Orchard.Packaging.Services {
}
public void AddFile(string path, Stream stream) {
EnsureDirectory(Path.GetDirectoryName(path));
string fullPath = GetFullPath(path);
EnsureDirectory(Path.GetDirectoryName(fullPath));
using (Stream outputStream = File.Create(GetFullPath(path))) {
using (Stream outputStream = File.Create(fullPath)) {
stream.CopyTo(outputStream);
}
}
public void DeleteFile(string path) {
@@ -88,9 +88,7 @@ namespace Orchard.Packaging.Services {
path = GetFullPath(path);
Directory.Delete(path, recursive);
}
catch (DirectoryNotFoundException) {
}
catch (DirectoryNotFoundException) {}
}
public void AddReference(string referencePath, Stream stream) {
@@ -125,12 +123,8 @@ namespace Orchard.Packaging.Services {
return Directory.EnumerateFiles(path, filter)
.Select(MakeRelativePath);
}
catch (UnauthorizedAccessException) {
}
catch (DirectoryNotFoundException) {
}
catch (UnauthorizedAccessException) {}
catch (DirectoryNotFoundException) {}
return Enumerable.Empty<string>();
}
@@ -144,12 +138,8 @@ namespace Orchard.Packaging.Services {
return Directory.EnumerateDirectories(path)
.Select(MakeRelativePath);
}
catch (UnauthorizedAccessException) {
}
catch (DirectoryNotFoundException) {
}
catch (UnauthorizedAccessException) {}
catch (DirectoryNotFoundException) {}
return Enumerable.Empty<string>();
}