|
| 1 | +// Copyright (c) .NET Foundation. All rights reserved. |
| 2 | +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.IO; |
| 6 | +using NuGet.Server.Core.Tests.Infrastructure; |
| 7 | +using Xunit; |
| 8 | + |
| 9 | +namespace NuGet.Server.Core.Tests.Core |
| 10 | +{ |
| 11 | + public class PackageFactoryTest |
| 12 | + { |
| 13 | + public class Open : IDisposable |
| 14 | + { |
| 15 | + private readonly TemporaryDirectory _directory; |
| 16 | + |
| 17 | + public Open() |
| 18 | + { |
| 19 | + _directory = new TemporaryDirectory(); |
| 20 | + } |
| 21 | + |
| 22 | + [Theory] |
| 23 | + [InlineData(null)] |
| 24 | + [InlineData("")] |
| 25 | + public void RejectsInvalidPaths(string path) |
| 26 | + { |
| 27 | + var ex = Assert.Throws<ArgumentNullException>( |
| 28 | + () => PackageFactory.Open(path)); |
| 29 | + Assert.Equal("fullPackagePath", ex.ParamName); |
| 30 | + } |
| 31 | + |
| 32 | + [Fact] |
| 33 | + public void InitializesPackageWithMetadata() |
| 34 | + { |
| 35 | + // Arrange |
| 36 | + var path = Path.Combine(_directory, "package.nupkg"); |
| 37 | + TestData.CopyResourceToPath(TestData.PackageResource, path); |
| 38 | + |
| 39 | + // Act |
| 40 | + var package = PackageFactory.Open(path); |
| 41 | + |
| 42 | + // Assert |
| 43 | + Assert.Equal(TestData.PackageId, package.Id); |
| 44 | + Assert.Equal(TestData.PackageVersion, package.Version); |
| 45 | + } |
| 46 | + |
| 47 | + [Fact] |
| 48 | + public void InitializesPackageWithSupportedFrameworks() |
| 49 | + { |
| 50 | + // Arrange |
| 51 | + var path = Path.Combine(_directory, "package.nupkg"); |
| 52 | + TestData.CopyResourceToPath(TestData.PackageResource, path); |
| 53 | + |
| 54 | + // Act |
| 55 | + var package = PackageFactory.Open(path); |
| 56 | + |
| 57 | + // Assert |
| 58 | + var frameworks = package.GetSupportedFrameworks(); |
| 59 | + var framework = Assert.Single(frameworks); |
| 60 | + Assert.Equal(VersionUtility.ParseFrameworkName("net40-client"), framework); |
| 61 | + } |
| 62 | + |
| 63 | + [Fact] |
| 64 | + public void InitializesPackageWhichCanBeCheckedForSymbols() |
| 65 | + { |
| 66 | + // Arrange |
| 67 | + var path = Path.Combine(_directory, "package.nupkg"); |
| 68 | + TestData.CopyResourceToPath(TestData.PackageResource, path); |
| 69 | + |
| 70 | + // Act |
| 71 | + var package = PackageFactory.Open(path); |
| 72 | + |
| 73 | + // Assert |
| 74 | + Assert.False(package.IsSymbolsPackage(), "The provided package is not a symbols package."); |
| 75 | + } |
| 76 | + |
| 77 | + public void Dispose() |
| 78 | + { |
| 79 | + _directory?.Dispose(); |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | +} |
0 commit comments