Esempio n. 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);
        }
Esempio n. 2
0
        public void DeleteEntry_NullEntry_ThrowsArgumentNullException()
        {
            StringResource resource = new StringResource();

            HostsFile file = new HostsFile(resource);

            file.DeleteEntry(null);
        }
Esempio n. 3
0
        public void DeleteEntry_DoesNotExist_DoesNotThrowException()
        {
            StringResource resource = new StringResource();

            HostsFile file = new HostsFile(resource);

            HostEntry entry = new HostEntry("host.localhost", "1.0.0.0", null);

            file.DeleteEntry(entry);
        }
Esempio n. 4
0
        public void IsDirty_ItemDeleted_ReturnsTrue()
        {
            string inputValue = "127.0.0.1    host1 # comment 1\n192.168.0.1    host2";

            StringResource resource = new StringResource(inputValue);

            HostsFile file = new HostsFile(resource);

            file.DeleteEntry(file.Entries.First());

            Assert.IsTrue(file.IsDirty);
        }
Esempio n. 5
0
        public void DeleteEntry_RemovesFromEntries()
        {
            StringResource resource = new StringResource("127.0.0.1    host1 # comment 1\n192.168.0.1    host2");

            HostsFile file = new HostsFile(resource);

            var entry = file.Entries.First();

            file.DeleteEntry(entry);

            Assert.IsFalse(file.Entries.Contains(entry));
        }
Esempio n. 6
0
        public void Save_AppliesDeletion()
        {
            StringResource resource = new StringResource(Resources.SampleHostsFile);

            HostsFile file = new HostsFile(resource);

            var entryA = file.Entries.Where(c => c.Hostname == "host1.localhost").First();

            file.DeleteEntry(entryA);

            file.Save();

            string actualOutput = resource.ToString();

            Assert.AreEqual(Resources.SampleHostsFile_Delete, actualOutput);
        }
Esempio n. 7
0
        protected override void ProcessRecord()
        {
            ICollection <HostEntry> hostEntries;

            if (!TryGetHostEntries(HostsFile, Name, Line, true, out hostEntries))
            {
                return;
            }

            foreach (var hostEntry in hostEntries)
            {
                if (ShouldProcess(String.Format("{0} ({1})", hostEntry.Name, hostEntry.Address), "Remove host entry"))
                {
                    HostsFile.DeleteEntry(hostEntry);
                }
            }
        }
Esempio n. 8
0
        public PropertyBag DeleteEntries(PropertyBag bag)
        {
            return(CatchCommonExceptions(() =>
            {
                DeleteEntriesRequest request = new DeleteEntriesRequest(bag);

                HostsFile hostsFile = GetHostsFile();

                IEnumerable <HostEntry> hostEntries = hostsFile.Entries;

                foreach (HostEntry remoteEntry in request.Entries)
                {
                    HostEntry localEntry = FindHostEntry(remoteEntry, hostEntries);

                    hostsFile.DeleteEntry(localEntry);
                }

                hostsFile.Save();

                return new DeleteEntriesResponse().ToPropertyBag();
            }));
        }