Esempio n. 1
0
            public void PiecesWithTrailingSlashesAreIgnored()
            {
                bool interleaved;
                bool ignored = !Nupkg.IsValidPartName(Nupkg.GetLogicalPartName("foo.txt/[13].piece/", out interleaved).ToString());

                Assert.True(ignored);
            }
Esempio n. 2
0
            public void PrependsSlash()
            {
                bool   interleaved;
                string name = Nupkg.GetLogicalPartName("file1.xml", out interleaved).ToString();

                Assert.False(interleaved);
                Assert.True(name.StartsWith("/", StringComparison.Ordinal));
            }
Esempio n. 3
0
            public void UnderstandsNonInterleavedItems()
            {
                bool   interleaved;
                string name = Nupkg.GetLogicalPartName("folder1/file1.xml", out interleaved).ToString();

                Assert.False(interleaved);
                Assert.True(name.IndexOf("folder1/file1.xml", StringComparison.Ordinal) > 0);
                Assert.False(name.EndsWith("/", StringComparison.Ordinal));
            }
Esempio n. 4
0
            public void ReturnsNothingForNoFilesAndNoFrameworkReferences()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream();
                var fakeNupkg  = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Empty(fx);
            }
Esempio n. 5
0
            public void ExtractTheManifest()
            {
                var packageStream = CreateTestPackageStream();
                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    Assert.Equal("TestPackage", nupkg.Metadata.Id);
                    Assert.Equal(SemanticVersion.Parse("0.0.0.1"), nupkg.Metadata.Version);
                    Assert.Equal("Trivial Description", nupkg.Metadata.Description);
                }
            }
Esempio n. 6
0
            public void ExtractTheManifest()
            {
                var packageStream = CreateTestPackageStream();

                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    Assert.Equal("TestPackage", nupkg.Metadata.Id);
                    Assert.Equal(SemanticVersion.Parse("0.0.0.1"), nupkg.Metadata.Version);
                    Assert.Equal("Trivial Description", nupkg.Metadata.Description);
                }
            }
Esempio n. 7
0
            public void ExtractThePartsList()
            {
                var packageStream = CreateTestPackageStream();
                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    var parts = nupkg.Parts;
                    Assert.Contains("/[Content_Types].xml", parts);
                    Assert.Contains("/_rels/.rels", parts);
                    Assert.Contains("/TestPackage.nuspec", parts);
                    Assert.Contains("/content/HelloWorld.cs", parts);
                }
            }
Esempio n. 8
0
            public void ExtractThePartsList()
            {
                var packageStream = CreateTestPackageStream();

                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    var parts = nupkg.Parts;
                    Assert.Contains("/[Content_Types].xml", parts);
                    Assert.Contains("/_rels/.rels", parts);
                    Assert.Contains("/TestPackage.nuspec", parts);
                    Assert.Contains("/content/HelloWorld.cs", parts);
                }
            }
Esempio n. 9
0
            public void ReturnsFilePathFrameworksIfPresent(string directoryName, FrameworkName fxName)
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.Files.Add(CreateMockPackageFile(@"lib\" + directoryName + @"\file.dll"));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    fxName,
                }, fx.ToArray());
            }
Esempio n. 10
0
            public void ExtractTheFilesList()
            {
                var packageStream = CreateTestPackageStream();
                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    var files = nupkg.GetFiles();
                    Assert.DoesNotContain("/_rels/.rels", files);
                    Assert.DoesNotContain("/[Content_Types].xml", files);
                    Assert.DoesNotContain("_rels/.rels", files);
                    Assert.DoesNotContain("[Content_Types].xml", files);
                    Assert.Contains("TestPackage.nuspec", files);
                    Assert.Contains("content/HelloWorld.cs", files);
                }
            }
Esempio n. 11
0
            public void ExtractTheFilesList()
            {
                var packageStream = CreateTestPackageStream();

                packageStream.Position = 0;

                // Act
                using (var nupkg = new Nupkg(packageStream, leaveOpen: false))
                {
                    var files = nupkg.GetFiles();
                    Assert.DoesNotContain("/_rels/.rels", files);
                    Assert.DoesNotContain("/[Content_Types].xml", files);
                    Assert.DoesNotContain("_rels/.rels", files);
                    Assert.DoesNotContain("[Content_Types].xml", files);
                    Assert.Contains("TestPackage.nuspec", files);
                    Assert.Contains("content/HelloWorld.cs", files);
                }
            }
        private async Task EnsureNuGetExe()
        {
            if (await _fileStorageService.FileExistsAsync(Constants.DownloadsFolderName, "nuget.exe"))
            {
                // Ensure the file exists on blob storage.
                return;
            }

            var package = _packageService.FindPackageByIdAndVersion("NuGet.CommandLine", version: null, allowPrerelease: false);
            if (package == null)
            {
                throw new InvalidOperationException("Unable to find NuGet.CommandLine.");
            }

            using (Stream packageStream = await _packageFileService.DownloadPackageFileAsync(package))
            {
                var nupkg = new Nupkg(packageStream, leaveOpen: true);
                await ExtractNuGetExe(nupkg);
            }
        }
Esempio n. 13
0
            public void ReturnsFrameworkAssemblyReferenceFrameworksIfNoFileFrameworks()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("foo", new[] {
                        VersionUtility.ParseFrameworkName("net45"),
                        VersionUtility.ParseFrameworkName("sl-wp70")
                    }));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    new FrameworkName(".NETFramework, Version=4.5"),
                    new FrameworkName("Silverlight, Version=v0.0, Profile=wp70")
                }, fx.ToArray());
            }
Esempio n. 14
0
        private async Task EnsureNuGetExe()
        {
            if (await _fileStorageService.FileExistsAsync(Constants.DownloadsFolderName, "nuget.exe"))
            {
                // Ensure the file exists on blob storage.
                return;
            }

            var package = _packageService.FindPackageByIdAndVersion("NuGet.CommandLine", version: null, allowPrerelease: false);

            if (package == null)
            {
                throw new InvalidOperationException("Unable to find NuGet.CommandLine.");
            }

            using (Stream packageStream = await _packageFileService.DownloadPackageFileAsync(package))
            {
                var nupkg = new Nupkg(packageStream, leaveOpen: true);
                await ExtractNuGetExe(nupkg);
            }
        }
Esempio n. 15
0
            public void ReturnsUnionOfFrameworkReferenceAndFileFrameworks()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.Files.Add(CreateMockPackageFile(@"lib\net40\file.dll"));
                    b.Files.Add(CreateMockPackageFile(@"lib\win\file.dll"));
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("Windows", new[] { new FrameworkName("Windows, Version=0.0") }));
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("System.Net.Http", new[] { new FrameworkName(".NETFramework, Version=2.0") }));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    new FrameworkName("Windows, Version=0.0"),
                    new FrameworkName(".NETFramework, Version=2.0"),
                    new FrameworkName(".NETFramework, Version=4.0"),
                }, fx.ToArray());
            }
Esempio n. 16
0
            public void ConvertsBackSlashesToSlashes()
            {
                var canon = Nupkg.CanonicalName(@"Dir1\Dir2\foo.txt");

                Assert.Equal("Dir1/Dir2/foo.txt", canon);
            }
Esempio n. 17
0
            public void RemovesLeadingBackSlashes()
            {
                var canon = Nupkg.CanonicalName(@"\foo.txt");

                Assert.Equal("foo.txt", canon);
            }
Esempio n. 18
0
            public void PartsWithDotOnlyISegmentsAreIgnored(string logicalPartName)
            {
                bool valid = Nupkg.IsValidPartName(logicalPartName);

                Assert.False(valid);
            }
Esempio n. 19
0
            public void PartsWithTrailingSlashesAreIgnored()
            {
                bool valid = Nupkg.IsValidPartName("/content/");

                Assert.False(valid);
            }
Esempio n. 20
0
            public void EmptyPartNamesAreIgnored()
            {
                bool valid = Nupkg.IsValidPartName("/");

                Assert.False(valid);
            }
Esempio n. 21
0
            public void LegitPartNamesAreAccepted(string logicalPartName)
            {
                bool valid = Nupkg.IsValidPartName(logicalPartName);

                Assert.True(valid);
            }
Esempio n. 22
0
            public void ReturnsNothingForNoFilesAndNoFrameworkReferences()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream();
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Empty(fx);
            }
Esempio n. 23
0
            public void ReturnsFrameworkAssemblyReferenceFrameworksIfNoFileFrameworks()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("foo", new[] { 
                        VersionUtility.ParseFrameworkName("net45"),
                        VersionUtility.ParseFrameworkName("sl-wp70")
                    }));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    new FrameworkName(".NETFramework, Version=4.5"),
                    new FrameworkName("Silverlight, Version=v0.0, Profile=wp70")
                }, fx.ToArray());
            }
Esempio n. 24
0
            public void ReturnsFilePathFrameworksIfPresent(string directoryName, FrameworkName fxName)
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.Files.Add(CreateMockPackageFile(@"lib\" + directoryName + @"\file.dll"));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    fxName,
                }, fx.ToArray());
            }
Esempio n. 25
0
            public void ReturnsUnionOfFrameworkReferenceAndFileFrameworks()
            {
                // Arrange
                var fakeStream = CreateTestPackageStream(b =>
                {
                    b.Files.Add(CreateMockPackageFile(@"lib\net40\file.dll"));
                    b.Files.Add(CreateMockPackageFile(@"lib\win\file.dll"));
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("Windows", new[] { new FrameworkName("Windows, Version=0.0") }));
                    b.FrameworkReferences.Add(new FrameworkAssemblyReference("System.Net.Http", new[] { new FrameworkName(".NETFramework, Version=2.0") }));
                });
                var fakeNupkg = new Nupkg(fakeStream, leaveOpen: false);

                // Act
                var fx = fakeNupkg.GetSupportedFrameworks();

                // Assert
                Assert.Equal(new[] {
                    new FrameworkName("Windows, Version=0.0"),
                    new FrameworkName(".NETFramework, Version=2.0"),
                    new FrameworkName(".NETFramework, Version=4.0"),
                }, fx.ToArray());
            }