コード例 #1
0
        private void OnItemClick(HostsProfile profile)
        {
            var path = ConfigurationManager.AppSettings["hostsFilePath"];
            var text = File.ReadAllText(path);

            text = profile.ApplyToText(text);
            File.WriteAllText(path, text);
        }
コード例 #2
0
        public void ApplyToText_IsCorrect()
        {
            var entries = new HostsProfile("name", new[]
            {
                HostEntry.FromString("127.1.1.1 google.com"),
                HostEntry.FromString("nothing localresource.me"),
                HostEntry.FromString("nothing anotherlocalresource.me"),
                HostEntry.FromString("127.1.1.3 newurl.ru"),
            }.Cast <HostEntry>().ToList());

            var expectedResult =
                @"127.1.1.1 google.com
		#128.0.0.1 yandex.ru
				#some random text
			
127.1.1.3 newurl.ru";

            Assert.AreEqual(expectedResult, entries.ApplyToText(_sampleText));
        }