示例#1
0
        public void ToString_IsNotDirty_HasOriginalString_ReturnsOriginalString()
        {
            HostEntry entry = new HostEntry(5, "original-line", " ", false, "hostname", "address", "comment");

            string actualValue = entry.ToString();

            Assert.AreEqual("original-line", actualValue);
        }
示例#2
0
        public void ToString_IsNotDirty_DoesNotHaveOriginalString_FormatsValues()
        {
            HostEntry entry = new HostEntry(5, null, "    ", false, "hostname", "address", "comment");

            string expectedValue = "# address    hostname # comment";
            string actualValue   = entry.ToString();

            Assert.AreEqual(expectedValue, actualValue);
        }
示例#3
0
        private HostEntry FindHostEntry(HostEntry entryToFind, IEnumerable <HostEntry> entries)
        {
            var entry = entries.FirstOrDefault(e => entryToFind.Line == e.Line);

            if (entry == null || entryToFind.ToString() != entry.ToString())
            {
                throw new HostsFileEditCollisionException();
            }

            foreach (HostEntry hostEntry in entries)
            {
                if (entryToFind.ToString() == hostEntry.ToString())
                {
                    return(hostEntry);
                }
            }

            throw new HostsFileServiceException("File has changed. Please reload");
        }
示例#4
0
        public void ToString_IsDirty_FormatsValues()
        {
            HostEntry entry = new HostEntry(5, "original-line", "    ", false, "hostname", "address", "comment");

            entry.Hostname = "hostname2";

            string expectedValue = "# address    hostname2 # comment";
            string actualValue   = entry.ToString();

            Assert.AreEqual(expectedValue, actualValue);
        }