Example #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);
        }
Example #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);
        }
Example #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");
        }
Example #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);
        }