Exemple #1
0
        public void TestHostFileSectionUpdater_hostsInput_hostsOutput()
        {
            /*
             *  The following assignments is made to trigger the constructor of PrimeDNS class. It won't work without that.
             */
            var primeDns = new PrimeDns();

            var config          = new TestAppConfig();
            var hostFileUpdater = new HostFile.HostFileUpdater();

            var filePath       = config.PrimeDnsTestsFiles + "test";
            var inputFilePath  = config.PrimeDnsTestsFiles + "hostsInput";
            var outputFilePath = config.PrimeDnsTestsFiles + "hostsOutput";

            const string data = "127.0.0.1\twww.dhamma.org\n127.0.0.1\twww.bing.com\n127.0.0.1\twww.goodreads.com";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            File.Copy(inputFilePath, filePath);
            hostFileUpdater.RemoveOldPrimeDnsSectionEntries(filePath);
            hostFileUpdater.FindPrimeDnsSectionBegin(filePath);
            Helper.FileHelper.InsertIntoFile(filePath, data, hostFileUpdater.PrimeDnsBeginLine + 1);

            Assert.IsTrue(Test_Helper.FileComparisonHelper.FilesAreEqual(filePath, outputFilePath));
        }
        public void TestRemoveLineFromFile_removeLineInput_removeLineOutput()
        {
            /*
             *  The following assignments are made to trigger the constructor of the respective classes. It won't work without that.
             */
            var primeDns        = new PrimeDns();
            var config          = new TestAppConfig();
            var hostFileUpdater = new HostFile.HostFileUpdater();

            var filePath       = config.PrimeDnsTestsFiles + "test";
            var inputFilePath  = config.PrimeDnsTestsFiles + "removeLineInput";
            var outputFilePath = config.PrimeDnsTestsFiles + "removeLineOutput";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            File.Copy(inputFilePath, filePath);
            FileHelper.RemoveLineFromFile(filePath, "###---LINE-TO-REMOVE");

            Assert.IsTrue(FileComparisonHelper.FilesAreEqual(filePath, outputFilePath));
        }
        public void TestDnsResolveServFail()
        {
            /*
             *  The following assignments is made to trigger the constructor of PrimeDNS class. It won't work without that.
             */
            var primeDns = new PrimeDns();

            var mapRow = new PrimeDnsMapRow("www.dev5-bing-int1.com");
            var result = Tuple.Create(mapRow, false);

            var source = new CancellationTokenSource();
            var token  = source.Token;

            try
            {
                result = DnsResolver.DnsResolve(mapRow, token).Result;
            }
            catch (Exception e)
            {
                throw new AssertFailedException(e.Message);
            }

            Assert.IsFalse(result.Item2);
        }