Exemplo n.º 1
0
        public virtual void TestHostsFileReader()
        {
            FileWriter efw = new FileWriter(excludesFile);
            FileWriter ifw = new FileWriter(includesFile);

            efw.Write("#DFS-Hosts-excluded\n");
            efw.Write("somehost1\n");
            efw.Write("#This-is-comment\n");
            efw.Write("somehost2\n");
            efw.Write("somehost3 # host3\n");
            efw.Write("somehost4\n");
            efw.Write("somehost4 somehost5\n");
            efw.Close();
            ifw.Write("#Hosts-in-DFS\n");
            ifw.Write("somehost1\n");
            ifw.Write("somehost2\n");
            ifw.Write("somehost3\n");
            ifw.Write("#This-is-comment\n");
            ifw.Write("somehost4 # host4\n");
            ifw.Write("somehost4 somehost5\n");
            ifw.Close();
            HostsFileReader hfp         = new HostsFileReader(includesFile, excludesFile);
            int             includesLen = hfp.GetHosts().Count;
            int             excludesLen = hfp.GetExcludedHosts().Count;

            Assert.Equal(5, includesLen);
            Assert.Equal(5, excludesLen);
            Assert.True(hfp.GetHosts().Contains("somehost5"));
            NUnit.Framework.Assert.IsFalse(hfp.GetHosts().Contains("host3"));
            Assert.True(hfp.GetExcludedHosts().Contains("somehost5"));
            NUnit.Framework.Assert.IsFalse(hfp.GetExcludedHosts().Contains("host4"));
        }
Exemplo n.º 2
0
        public virtual void TestHostFileReaderWithTabs()
        {
            FileWriter efw = new FileWriter(excludesFile);
            FileWriter ifw = new FileWriter(includesFile);

            efw.Write("#DFS-Hosts-excluded\n");
            efw.Write("     \n");
            efw.Write("   somehost \t somehost2 \n somehost4");
            efw.Write("   somehost3 \t # somehost5");
            efw.Close();
            ifw.Write("#Hosts-in-DFS\n");
            ifw.Write("     \n");
            ifw.Write("   somehost \t  somehost2 \n somehost4");
            ifw.Write("   somehost3 \t # somehost5");
            ifw.Close();
            HostsFileReader hfp         = new HostsFileReader(includesFile, excludesFile);
            int             includesLen = hfp.GetHosts().Count;
            int             excludesLen = hfp.GetExcludedHosts().Count;

            Assert.Equal(4, includesLen);
            Assert.Equal(4, excludesLen);
            Assert.True(hfp.GetHosts().Contains("somehost2"));
            NUnit.Framework.Assert.IsFalse(hfp.GetHosts().Contains("somehost5"));
            Assert.True(hfp.GetExcludedHosts().Contains("somehost2"));
            NUnit.Framework.Assert.IsFalse(hfp.GetExcludedHosts().Contains("somehost5"));
        }
Exemplo n.º 3
0
        public virtual void TestHostFileReaderWithNull()
        {
            FileWriter efw = new FileWriter(excludesFile);
            FileWriter ifw = new FileWriter(includesFile);

            efw.Close();
            ifw.Close();
            HostsFileReader hfp         = new HostsFileReader(includesFile, excludesFile);
            int             includesLen = hfp.GetHosts().Count;
            int             excludesLen = hfp.GetExcludedHosts().Count;

            // TestCase1: Check if lines beginning with # are ignored
            Assert.Equal(0, includesLen);
            Assert.Equal(0, excludesLen);
            // TestCase2: Check if given host names are reported by getHosts and
            // getExcludedHosts
            NUnit.Framework.Assert.IsFalse(hfp.GetHosts().Contains("somehost5"));
            NUnit.Framework.Assert.IsFalse(hfp.GetExcludedHosts().Contains("somehost5"));
        }
Exemplo n.º 4
0
        public virtual void TestRefreshHostFileReaderWithNonexistentFile()
        {
            FileWriter efw = new FileWriter(excludesFile);
            FileWriter ifw = new FileWriter(includesFile);

            efw.Close();
            ifw.Close();
            HostsFileReader hfp = new HostsFileReader(includesFile, excludesFile);

            Assert.True(IncludesFile.Delete());
            try
            {
                hfp.Refresh();
                NUnit.Framework.Assert.Fail("Should throw FileNotFoundException");
            }
            catch (FileNotFoundException)
            {
            }
        }