Helper methods for manipulating Implementations.
Esempio n. 1
0
        public void BuildSingleFile()
        {
            using var originalStream = SingleFileData.ToStream();
            using var microServer    = new MicroServer(SingleFileName, originalStream);
            var implementation = ImplementationUtils.Build(new SingleFile {
                Href = microServer.FileUri, Destination = SingleFileName
            }, new SilentTaskHandler());

            ("sha256new_" + implementation.ManifestDigest.Sha256New).Should().Be(_singleFileSha256Digest);

            var file = (SingleFile)implementation.RetrievalMethods[0];

            file.Size.Should().Be(originalStream.Length);
        }
Esempio n. 2
0
        public void BuildSingleFile()
        {
            using (var originalStream = SingleFileData.ToStream())
                using (var microServer = new MicroServer(SingleFileName, originalStream))
                {
                    var implementation = ImplementationUtils.Build(new SingleFile {
                        Href = microServer.FileUri, Destination = SingleFileName
                    }, new SilentTaskHandler());
                    Assert.AreEqual(_singleFileSha256Digest, "sha256new_" + implementation.ManifestDigest.Sha256New);

                    var file = (SingleFile)implementation.RetrievalMethods[0];
                    Assert.AreEqual(originalStream.Length, file.Size);
                }
        }
Esempio n. 3
0
        public void BuildArchive()
        {
            using (var stream = typeof(ExtractorTest).GetEmbeddedStream("testArchive.zip"))
                using (var microServer = new MicroServer("archive.zip", stream))
                {
                    var implementation = ImplementationUtils.Build(new Archive {
                        Href = microServer.FileUri
                    }, new SilentTaskHandler());
                    Assert.AreEqual(ArchiveSha256Digest, implementation.ManifestDigest.Sha256New);

                    var archive = (Archive)implementation.RetrievalMethods[0];
                    Assert.AreEqual(Archive.MimeTypeZip, archive.MimeType);
                    Assert.AreEqual(stream.Length, archive.Size);
                }
        }
Esempio n. 4
0
        public void BuildArchive()
        {
            using var stream      = typeof(ImplementationUtilsTest).GetEmbeddedStream("testArchive.zip");
            using var microServer = new MicroServer("archive.zip", stream);
            var implementation = ImplementationUtils.Build(new Archive {
                Href = microServer.FileUri
            }, new SilentTaskHandler());

            implementation.ManifestDigest.Sha256New.Should().Be(ArchiveSha256Digest);

            var archive = (Archive)implementation.RetrievalMethods[0];

            archive.MimeType.Should().Be(Archive.MimeTypeZip);
            archive.Size.Should().Be(stream.Length);
        }
Esempio n. 5
0
        public void BuildRecipe()
        {
            using (var stream = typeof(ArchiveExtractorTest).GetEmbeddedStream("testArchive.zip"))
                using (var microServer = new MicroServer("archive.zip", stream))
                {
                    var implementation = ImplementationUtils.Build(new Recipe {
                        Steps = { new Archive {
                                      Href = microServer.FileUri
                                  } }
                    }, new SilentTaskHandler());
                    implementation.ManifestDigest.Sha256New.Should().Be(ArchiveSha256Digest);

                    var archive = (Archive)((Recipe)implementation.RetrievalMethods[0]).Steps[0];
                    archive.MimeType.Should().Be(Archive.MimeTypeZip);
                    archive.Size.Should().Be(stream.Length);
                }
        }
Esempio n. 6
0
        public void TestGenerateDigest()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                new PackageBuilder().AddFolder("subdir")
                .AddFile("file", "AAA", new DateTime(2000, 1, 1))
                .WritePackageInto(packageDir);

                ManifestDigest digest1 = ImplementationUtils.GenerateDigest(packageDir, new MockTaskHandler());
                Assert.IsNullOrEmpty(digest1.Sha1); // sha1 is deprecated
                Assert.IsNotNullOrEmpty(digest1.Sha1New);
                Assert.IsNotNullOrEmpty(digest1.Sha256);
                Assert.IsNotNullOrEmpty(digest1.Sha256New);

                ManifestDigest digest2 = ImplementationUtils.GenerateDigest(packageDir, new MockTaskHandler());
                Assert.AreEqual(digest1, digest2);
            }
        }
Esempio n. 7
0
        public void GenerateDigest()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                new PackageBuilder().AddFolder("subdir")
                .AddFile("file", "AAA", new DateTime(2000, 1, 1))
                .WritePackageInto(packageDir);

                ManifestDigest digest1 = ImplementationUtils.GenerateDigest(packageDir, new MockTaskHandler());
                digest1.Sha1.Should().BeNullOrEmpty(because: "sha1 is deprecated");
                digest1.Sha1New.Should().NotBeNullOrEmpty();
                digest1.Sha256.Should().NotBeNullOrEmpty();
                digest1.Sha256New.Should().NotBeNullOrEmpty();

                ManifestDigest digest2 = ImplementationUtils.GenerateDigest(packageDir, new MockTaskHandler());
                digest2.Should().Be(digest1);
            }
        }