Disposable class to create a temporary file and delete it again when disposed.
Наследование: IDisposable
Пример #1
0
        public void TestBuildStubNeedsTerminal()
        {
            if (!WindowsUtils.IsWindows) Assert.Ignore("StubBuilder is only used on Windows");

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
                new FeedTarget(FeedTest.Test1Uri, FeedTest.CreateTestFeed()).BuildRunStub(tempFile, new SilentTaskHandler(), needsTerminal: true);
        }
        public void TestSaveLoad()
        {
            CapabilityList capabilityList1 = CreateTestCapabilityList(), capabilityList2;
            Assert.That(capabilityList1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                capabilityList1.SaveXml(tempFile);
                capabilityList2 = XmlStorage.LoadXml<CapabilityList>(tempFile);
            }

            // Ensure data stayed the same
            Assert.AreEqual(capabilityList1, capabilityList2, "Serialized objects should be equal.");
            Assert.AreEqual(capabilityList1.GetHashCode(), capabilityList2.GetHashCode(), "Serialized objects' hashes should be equal.");
            Assert.IsFalse(ReferenceEquals(capabilityList1, capabilityList2), "Serialized objects should not return the same reference.");
        }
Пример #3
0
        public void TestSaveLoad()
        {
            FeedPreferences preferences1 = CreateTestFeedPreferences(), preferences2;
            Assert.That(preferences1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                preferences1.SaveXml(tempFile);
                preferences2 = XmlStorage.LoadXml<FeedPreferences>(tempFile);
            }

            // Ensure data stayed the same
            preferences2.Should().Be(preferences1, because: "Serialized objects should be equal.");
            preferences2.GetHashCode().Should().Be(preferences1.GetHashCode(), because: "Serialized objects' hashes should be equal.");
            preferences2.Should().NotBeSameAs(preferences1, because: "Serialized objects should not return the same reference.");
        }
Пример #4
0
        public void TestSaveLoad()
        {
            Catalog catalog1 = CreateTestCatalog(), catalog2;
            Assert.That(catalog1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                catalog1.SaveXml(tempFile);
                catalog2 = XmlStorage.LoadXml<Catalog>(tempFile);
            }

            // Ensure data stayed the same
            catalog2.Should().Be(catalog1, because: "Serialized objects should be equal.");
            catalog2.GetHashCode().Should().Be(catalog1.GetHashCode(), because: "Serialized objects' hashes should be equal.");
            catalog2.Should().NotBeSameAs(catalog1, 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
            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.");
        }
        public void TestSaveLoad()
        {
            InterfacePreferences preferences1 = CreateTestInterfacePreferences(), preferences2;
            Assert.That(preferences1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                preferences1.SaveXml(tempFile);
                preferences2 = XmlStorage.LoadXml<InterfacePreferences>(tempFile);
            }

            // Ensure data stayed the same
            Assert.AreEqual(preferences1, preferences2, "Serialized objects should be equal.");
            Assert.AreEqual(preferences1.GetHashCode(), preferences2.GetHashCode(), "Serialized objects' hashes should be equal.");
            Assert.IsFalse(ReferenceEquals(preferences1, preferences2), "Serialized objects should not return the same reference.");
        }
 public void SetUp()
 {
     _appListFile = new TemporaryFile("0install-unit-tests");
     new AppList().SaveXml(_appListFile);
     _integrationManager = new IntegrationManager(_appListFile, new MockTaskHandler());
 }
Пример #8
0
        public void TestNormalizeHash()
        {
            var feed = CreateTestFeed();

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                feed.SaveXml(tempFile);
                var feedReload = XmlStorage.LoadXml<Feed>(tempFile);

                feed.Normalize(new FeedUri(tempFile));
                feedReload.Normalize(new FeedUri(tempFile));
                feedReload.GetHashCode().Should().Be(feed.GetHashCode());
            }
        }
Пример #9
0
 public void TestIsExecutable()
 {
     using (var tempFile = new TemporaryFile("unit-tests"))
         FileUtils.IsExecutable(tempFile).Should().BeFalse(because: "File was incorrectly identified as executable");
 }
Пример #10
0
 public void TestIsRegularFile()
 {
     using (var tempFile = new TemporaryFile("unit-tests"))
         FileUtils.IsRegularFile(tempFile).Should().BeTrue(because: "Regular file should be detected as such");
 }
Пример #11
0
        public void TestSaveLoad()
        {
            Feed feed1 = CreateTestFeed(), feed2;
            Assert.That(feed1, Is.XmlSerializable);
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                feed1.SaveXml(tempFile);
                feed2 = XmlStorage.LoadXml<Feed>(tempFile);
            }

            // Ensure data stayed the same
            Assert.AreEqual(feed1, feed2, "Serialized objects should be equal.");
            Assert.AreEqual(feed1.GetHashCode(), feed2.GetHashCode(), "Serialized objects' hashes should be equal.");
            Assert.IsFalse(ReferenceEquals(feed1, feed2), "Serialized objects should not return the same reference.");
        }
Пример #12
0
        private static void TestSaveLoad(AppList appList)
        {
            Assert.That(appList, Is.XmlSerializable);

            AppList appList2;
            using (var tempFile = new TemporaryFile("0install-unit-tests"))
            {
                // Write and read file
                appList.SaveXml(tempFile);
                appList2 = XmlStorage.LoadXml<AppList>(tempFile);
            }

            // Ensure data stayed the same
            appList2.Should().Be(appList, because: "Serialized objects should be equal.");
            appList2.GetHashCode().Should().Be(appList.GetHashCode(), because: "Serialized objects' hashes should be equal.");
            appList2.Should().NotBeSameAs(appList, because: "Serialized objects should not return the same reference.");
        }