-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
465 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
|
||
namespace NuGet.Server.Core | ||
{ | ||
/// <summary> | ||
/// A file system implementation that persists nothing. This is intended to be used with | ||
/// <see cref="OptimizedZipPackage"/> so that package files are never actually extracted anywhere on disk. | ||
/// </summary> | ||
public class NullFileSystem : IFileSystem | ||
{ | ||
public static NullFileSystem Instance { get; } = new NullFileSystem(); | ||
|
||
public Stream CreateFile(string path) => Stream.Null; | ||
public bool DirectoryExists(string path) => true; | ||
public bool FileExists(string path) => false; | ||
public string GetFullPath(string path) => null; | ||
public Stream OpenFile(string path) => Stream.Null; | ||
|
||
public ILogger Logger { get => throw new NotSupportedException(); set => throw new NotSupportedException(); } | ||
public string Root => throw new NotSupportedException(); | ||
public void AddFile(string path, Stream stream) => throw new NotSupportedException(); | ||
public void AddFile(string path, Action<Stream> writeToStream) => throw new NotSupportedException(); | ||
public void AddFiles(IEnumerable<IPackageFile> files, string rootDir) => throw new NotSupportedException(); | ||
public void DeleteDirectory(string path, bool recursive) => throw new NotSupportedException(); | ||
public void DeleteFile(string path) => throw new NotSupportedException(); | ||
public void DeleteFiles(IEnumerable<IPackageFile> files, string rootDir) => throw new NotSupportedException(); | ||
public DateTimeOffset GetCreated(string path) => throw new NotSupportedException(); | ||
public IEnumerable<string> GetDirectories(string path) => throw new NotSupportedException(); | ||
public IEnumerable<string> GetFiles(string path, string filter, bool recursive) => throw new NotSupportedException(); | ||
public DateTimeOffset GetLastAccessed(string path) => throw new NotSupportedException(); | ||
public DateTimeOffset GetLastModified(string path) => throw new NotSupportedException(); | ||
public void MakeFileWritable(string path) => throw new NotSupportedException(); | ||
public void MoveFile(string source, string destination) => throw new NotSupportedException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace NuGet.Server.Core | ||
{ | ||
public static class PackageFactory | ||
{ | ||
public static IPackage Open(string fullPackagePath) | ||
{ | ||
if (string.IsNullOrEmpty(fullPackagePath)) | ||
{ | ||
throw new ArgumentNullException(nameof(fullPackagePath)); | ||
} | ||
|
||
var directoryName = Path.GetDirectoryName(fullPackagePath); | ||
var fileName = Path.GetFileName(fullPackagePath); | ||
|
||
var fileSystem = new PhysicalFileSystem(directoryName); | ||
|
||
return new OptimizedZipPackage( | ||
fileSystem, | ||
fileName, | ||
NullFileSystem.Instance); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.IO; | ||
using NuGet.Server.Core.Tests.Infrastructure; | ||
using Xunit; | ||
|
||
namespace NuGet.Server.Core.Tests.Core | ||
{ | ||
public class PackageFactoryTest | ||
{ | ||
public class Open : IDisposable | ||
{ | ||
private readonly TemporaryDirectory _directory; | ||
|
||
public Open() | ||
{ | ||
_directory = new TemporaryDirectory(); | ||
} | ||
|
||
[Theory] | ||
[InlineData(null)] | ||
[InlineData("")] | ||
public void RejectsInvalidPaths(string path) | ||
{ | ||
var ex = Assert.Throws<ArgumentNullException>( | ||
() => PackageFactory.Open(path)); | ||
Assert.Equal("fullPackagePath", ex.ParamName); | ||
} | ||
|
||
[Fact] | ||
public void InitializesPackageWithMetadata() | ||
{ | ||
// Arrange | ||
var path = Path.Combine(_directory, "package.nupkg"); | ||
TestData.CopyResourceToPath(TestData.PackageResource, path); | ||
|
||
// Act | ||
var package = PackageFactory.Open(path); | ||
|
||
// Assert | ||
Assert.Equal(TestData.PackageId, package.Id); | ||
Assert.Equal(TestData.PackageVersion, package.Version); | ||
} | ||
|
||
[Fact] | ||
public void InitializesPackageWithSupportedFrameworks() | ||
{ | ||
// Arrange | ||
var path = Path.Combine(_directory, "package.nupkg"); | ||
TestData.CopyResourceToPath(TestData.PackageResource, path); | ||
|
||
// Act | ||
var package = PackageFactory.Open(path); | ||
|
||
// Assert | ||
var frameworks = package.GetSupportedFrameworks(); | ||
var framework = Assert.Single(frameworks); | ||
Assert.Equal(VersionUtility.ParseFrameworkName("net40-client"), framework); | ||
} | ||
|
||
[Fact] | ||
public void InitializesPackageWhichCanBeCheckedForSymbols() | ||
{ | ||
// Arrange | ||
var path = Path.Combine(_directory, "package.nupkg"); | ||
TestData.CopyResourceToPath(TestData.PackageResource, path); | ||
|
||
// Act | ||
var package = PackageFactory.Open(path); | ||
|
||
// Assert | ||
Assert.False(package.IsSymbolsPackage(), "The provided package is not a symbols package."); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_directory?.Dispose(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.