示例#1
0
        public void Save_AppliesDeletionReorderingDisabling()
        {
            StringResource resource = new StringResource(Resources.ComplexHostsFile_Before);

            HostsFile file = new HostsFile(resource);

            var entry1 = file.Entries.Where(c => c.Hostname == "host1.localhost").First();
            var entry2 = file.Entries.Where(c => c.Hostname == "host2.localhost").First();
            var entry3 = file.Entries.Where(c => c.Hostname == "host3.localhost").First();
            var entry4 = file.Entries.Where(c => c.Hostname == "host4.localhost").First();
            var entry5 = file.Entries.Where(c => c.Hostname == "host5.localhost").First();
            var entry6 = new HostEntry("host6.localhost", "127.0.0.1", "comment 6");

            entry1.Enabled = false;
            entry2.Enabled = true;
            entry3.Enabled = false;

            entry3.SwapLine(entry5); // swap two with a deleted in between
            entry6.SwapLine(entry2); // new swapped with existing

            file.DeleteEntry(entry4);
            file.AddEntry(entry6);

            file.Save();

            string actualOutput = resource.ToString();

            Assert.AreEqual(Resources.ComplexHostsFile_Expected, actualOutput);
        }
示例#2
0
        public void IsDirty_LineSwapped_SwapsLineNumbers()
        {
            HostEntry entryA = new HostEntry(5, "original-line", " ", false, "hostname", "address", "comment");
            HostEntry entryB = new HostEntry(10, "original-line", " ", false, "hostname", "address", "comment");

            entryA.SwapLine(entryB);

            Assert.AreEqual(10, entryA.Line);
            Assert.AreEqual(5, entryB.Line);
        }
示例#3
0
        public void IsDirty_LineSwapped_ReturnsTrue()
        {
            HostEntry entryA = new HostEntry(5, "original-line", " ", false, "hostname", "address", "comment");
            HostEntry entryB = new HostEntry(10, "original-line", " ", false, "hostname", "address", "comment");

            entryA.SwapLine(entryB);

            Assert.IsTrue(entryA.IsDirty);
            Assert.IsTrue(entryB.IsDirty);
        }
示例#4
0
        public void IsDirty_LineSwapped_SwapsNewStatus()
        {
            HostEntry entryA = new HostEntry(-1, "original-line", " ", false, "hostname", "address", "comment");
            HostEntry entryB = new HostEntry(10, "original-line", " ", false, "hostname", "address", "comment");

            entryA.SwapLine(entryB);

            Assert.IsFalse(entryA.IsNew);
            Assert.IsTrue(entryB.IsNew);
        }