Inheritance: TestWithMocks
Esempio n. 1
0
        private string DeployPackage(string id, PackageBuilder builder)
        {
            string path = Path.Combine(_tempDir, id);

            builder.WritePackageInto(path);
            ManifestTest.CreateDotFile(path, ManifestFormat.FromPrefix(id), _handler);
            FileUtils.EnableWriteProtection(path);
            return(path);
        }
Esempio n. 2
0
        public void ShouldAllowToAddFolder()
        {
            using var testDir = new TemporaryDirectory("0install-unit-tests");
            var digest = new ManifestDigest(ManifestTest.CreateDotFile(testDir, ManifestFormat.Sha256, _handler));

            _implementationStore.AddDirectory(testDir, digest, _handler);

            _implementationStore.Contains(digest).Should().BeTrue(because: "After adding, Store must contain the added package");
            _implementationStore.ListAll().Should().Equal(new[] { digest }, because: "After adding, Store must show the added package in the complete list");
        }
        public void ShouldAllowToAddFolder()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                var digest = new ManifestDigest(ManifestTest.CreateDotFile(packageDir, ManifestFormat.Sha256, _handler));
                _store.AddDirectory(packageDir, digest, _handler);

                Assert.IsTrue(_store.Contains(digest), "After adding, Store must contain the added package");
                CollectionAssert.AreEqual(new[] { digest }, _store.ListAll(), "After adding, Store must show the added package in the complete list");
            }
        }
Esempio n. 4
0
        public void TestAuditPass()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                new PackageBuilder().AddFolder("subdir")
                .AddFile("file", "AAA", new DateTime(2000, 1, 1))
                .WritePackageInto(packageDir);
                var digest = new ManifestDigest(ManifestTest.CreateDotFile(packageDir, ManifestFormat.Sha1New, _handler));
                _store.AddDirectory(packageDir, digest, _handler);

                _store.Verify(digest, _handler);
                _handler.LastQuestion.Should().BeNull();
            }
        }
Esempio n. 5
0
        public void ShouldRecreateMissingStoreDir()
        {
            Directory.Delete(_tempDir, recursive: true);

            using var testDir = new TemporaryDirectory("0install-unit-tests");
            var digest = new ManifestDigest(ManifestTest.CreateDotFile(testDir, ManifestFormat.Sha256, _handler));

            _implementationStore.AddDirectory(testDir, digest, _handler);

            _implementationStore.Contains(digest).Should().BeTrue(because: "After adding, Store must contain the added package");
            _implementationStore.ListAll().Should().Equal(new[] { digest }, because: "After adding, Store must show the added package in the complete list");

            Directory.Exists(_tempDir).Should().BeTrue(because: "Store directory should have been recreated");
        }
        public void ShouldRecreateMissingStoreDir()
        {
            Directory.Delete(_tempDir, recursive: true);

            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                var digest = new ManifestDigest(ManifestTest.CreateDotFile(packageDir, ManifestFormat.Sha256, _handler));
                _store.AddDirectory(packageDir, digest, _handler);

                Assert.IsTrue(_store.Contains(digest), "After adding, Store must contain the added package");
                CollectionAssert.AreEqual(new[] { digest }, _store.ListAll(), "After adding, Store must show the added package in the complete list");

                Assert.IsTrue(Directory.Exists(_tempDir), "Store directory should have been recreated");
            }
        }
Esempio n. 7
0
        public void StressTest()
        {
            using var testDir = new TemporaryDirectory("0install-unit-tests");
            new TestRoot {
                new TestFile("file")
                {
                    Contents = "AAA"
                }
            }.Build(testDir);

            var digest = new ManifestDigest(ManifestTest.CreateDotFile(testDir, ManifestFormat.Sha256, _handler));

            Exception?exception = null;
            var       threads   = new Thread[100];

            for (int i = 0; i < threads.Length; i++)
            {
                threads[i] = new Thread(() =>
                {
                    try
                    {
                        // ReSharper disable once AccessToDisposedClosure
                        _implementationStore.AddDirectory(testDir, digest, _handler);
                        _implementationStore.Remove(digest, _handler);
                    }
                    catch (ImplementationAlreadyInStoreException)
                    {}
                    catch (ImplementationNotFoundException)
                    {}
                    catch (Exception ex)
                    {
                        exception = ex;
                    }
                });
                threads[i].Start();
            }

            foreach (var thread in threads)
            {
                thread.Join();
            }
            if (exception != null)
            {
                throw exception.PreserveStack();
            }

            _implementationStore.Contains(digest).Should().BeFalse();
        }
Esempio n. 8
0
        public void TestAuditPass()
        {
            using var testDir = new TemporaryDirectory("0install-unit-tests");
            new TestRoot {
                new TestFile("file")
                {
                    Contents = "AAA"
                }
            }.Build(testDir);
            var digest = new ManifestDigest(ManifestTest.CreateDotFile(testDir, ManifestFormat.Sha1New, _handler));

            _implementationStore.AddDirectory(testDir, digest, _handler);

            _implementationStore.Verify(digest, _handler);
            _handler.LastQuestion.Should().BeNull();
        }
Esempio n. 9
0
        public void StressTest()
        {
            using (var packageDir = new TemporaryDirectory("0install-unit-tests"))
            {
                new PackageBuilder().AddFolder("subdir")
                .AddFile("file", "AAA", new DateTime(2000, 1, 1))
                .WritePackageInto(packageDir);

                var digest = new ManifestDigest(ManifestTest.CreateDotFile(packageDir, ManifestFormat.Sha256, _handler));

                Exception exception = null;
                var       threads   = new Thread[100];
                for (int i = 0; i < threads.Length; i++)
                {
                    threads[i] = new Thread(() =>
                    {
                        try
                        {
                            // ReSharper disable once AccessToDisposedClosure
                            _store.AddDirectory(packageDir, digest, _handler);
                            _store.Remove(digest, _handler);
                        }
                        catch (ImplementationAlreadyInStoreException)
                        {}
                        catch (ImplementationNotFoundException)
                        {}
                        catch (Exception ex)
                        {
                            exception = ex;
                        }
                    });
                    threads[i].Start();
                }

                foreach (var thread in threads)
                {
                    thread.Join();
                }
                if (exception != null)
                {
                    Assert.Fail(exception.ToString());
                }

                _store.Contains(digest).Should().BeFalse();
            }
        }