示例#1
0
        public void TestSave()
        {
            using var tempFile = new TemporaryFile("0install-unit-tests");
            var original = new TrustDB();

            original.Save(tempFile);

            var loaded = TrustDB.Load(tempFile);

            original.Save().Should().BeFalse(because: "No loaded-from path to save back to");
            loaded.Save().Should().BeTrue(because: "Loaded from disk");
        }
示例#2
0
        [Fact] // Ensures that methods for adding and removing trusted keys work correctly.
        public void TestAddRemoveTrust()
        {
            var trust = new TrustDB();

            trust.IsTrusted("abc", new Domain("domain")).Should().BeFalse();

            trust.TrustKey("abc", new Domain("domain"));
            trust.Keys.Should().Equal(new Key {
                Fingerprint = "abc", Domains = { new Domain("domain") }
            });
            trust.IsTrusted("abc", new Domain("domain")).Should().BeTrue();

            trust.UntrustKey("abc", new Domain("domain"));
            trust.IsTrusted("abc", new Domain("domain")).Should().BeFalse();
        }
示例#3
0
        public void TestAddRemoveTrust()
        {
            var trust = new TrustDB();

            Assert.IsFalse(trust.IsTrusted("abc", new Domain("domain")));

            trust.TrustKey("abc", new Domain("domain"));
            CollectionAssert.AreEqual(new[] { new Key {
                                                  Fingerprint = "abc", Domains = { new Domain("domain") }
                                              } }, trust.Keys);
            Assert.IsTrue(trust.IsTrusted("abc", new Domain("domain")));

            trust.UntrustKey("abc", new Domain("domain"));
            Assert.IsFalse(trust.IsTrusted("abc", new Domain("domain")));
        }
示例#4
0
        [Fact] // Ensures that the class is correctly serialized and deserialized.
        public void TestSaveLoad()
        {
            TrustDB trust1 = CreateTestTrust(), trust2;

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                trust1.Save(tempFile);
                trust2 = TrustDB.Load(tempFile);
            }

            // Ensure data stayed the same
            trust2.Should().Be(trust1, because: "Serialized objects should be equal.");
            trust2.GetHashCode().Should().Be(trust1.GetHashCode(), because: "Serialized objects' hashes should be equal.");
            ReferenceEquals(trust1, trust2).Should().BeFalse(because: "Serialized objects should not return the same reference.");
        }
示例#5
0
        public void TestSaveLoad()
        {
            TrustDB trust1 = CreateTestTrust(), trust2;

            Assert.That(trust1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                trust1.SaveXml(tempFile);
                trust2 = XmlStorage.LoadXml <TrustDB>(tempFile);
            }

            // Ensure data stayed the same
            Assert.AreEqual(trust1, trust2, "Serialized objects should be equal.");
            Assert.AreEqual(trust1.GetHashCode(), trust2.GetHashCode(), "Serialized objects' hashes should be equal.");
            Assert.IsFalse(ReferenceEquals(trust1, trust2), "Serialized objects should not return the same reference.");
        }