public void testFindUrl_MultiSite1()
        {
            Dictionary <string, string> _config = new Dictionary <string, string>
            {
                { "proxyHost", "websenseproxy" },
                { "proxyPort", "8080" },
                { "printxml", "false" },
                { "merchantId", "101" },
                { "username", "DOTNET" },
                { "password", "TESTCASE" },

                { "multiSite", "true" },
                { "printMultiSiteDebug", "true" },
                { "url", legacyUrl },
                { "multiSiteUrl1", site1Url },
                { "multiSiteUrl2", site2Url },
                { "multiSiteErrorThreshold", "4" },
                { "maxHoursWithoutSwitch", "48" }
            };

            CommManager.reset();
            CommManager cmg = CommManager.instance(_config);

            Assert.IsNotNull(cmg);
            Assert.IsTrue(cmg.getMultiSite());
            RequestTarget rt = cmg.findUrl();

            Assert.AreEqual(cmg.getMultiSiteUrls()[cmg.getCurrentMultiSiteUrlIndex()], rt.getUrl());
            Assert.True(rt.getUrl().Equals(site1Url) || rt.getUrl().Equals(site2Url));
        }
        public void testFindUrl_MultiSiteMaxHours()
        {
            // test that url is switched when number of hours since last switch exceeds threshold
            Dictionary <string, string> _config = new Dictionary <string, string>
            {
                { "proxyHost", "websenseproxy" },
                { "proxyPort", "8080" },
                { "printxml", "false" },
                { "merchantId", "101" },
                { "username", "DOTNET" },
                { "password", "TESTCASE" },

                { "multiSite", "true" },
                { "printMultiSiteDebug", "true" },
                { "url", legacyUrl },
                { "multiSiteUrl1", site1Url },
                { "multiSiteUrl2", site2Url },
                { "multiSiteErrorThreshold", "3" },
                { "maxHoursWithoutSwitch", "4" }
            };

            CommManager.reset();
            CommManager cmg = CommManager.instance(_config);

            Assert.IsNotNull(cmg);
            Assert.IsTrue(cmg.getMultiSite());
            Assert.AreEqual(cmg.getMultiSiteThreshold(), 3);

            RequestTarget rt1 = cmg.findUrl();

            Assert.AreEqual(cmg.getMultiSiteUrls()[cmg.getCurrentMultiSiteUrlIndex()], rt1.getUrl());
            cmg.reportResult(rt1, CommManager.REQUEST_RESULT_RESPONSE_RECEIVED, 200);
            RequestTarget rt2 = cmg.findUrl();

            Assert.AreEqual(rt1.getUrl(), rt2.getUrl());
            cmg.reportResult(rt2, CommManager.REQUEST_RESULT_RESPONSE_RECEIVED, 200);

            // set last switch time to 6 hours earlier
            DateTime gc = new DateTime(cmg.getLastSiteSwitchTime() * 10000);

            gc = gc.Add(new System.TimeSpan(-6, 0, 0));
            cmg.setLastSiteSwitchTime((gc.Ticks / 10000));

            RequestTarget rt3 = cmg.findUrl();

            Assert.IsFalse(rt3.getUrl().Equals(rt1.getUrl()));
        }
        public void testFindUrl_MultiSite2()
        {
            // test that url is switched when errors reach threshold
            Dictionary <string, string> _config = new Dictionary <string, string>
            {
                { "proxyHost", "websenseproxy" },
                { "proxyPort", "8080" },
                { "printxml", "false" },
                { "merchantId", "101" },
                { "username", "DOTNET" },
                { "password", "TESTCASE" },

                { "multiSite", "true" },
                { "printMultiSiteDebug", "false" },
                { "url", legacyUrl },
                { "multiSiteUrl1", site1Url },
                { "multiSiteUrl2", site2Url },
                { "multiSiteErrorThreshold", "3" },
                { "maxHoursWithoutSwitch", "48" }
            };

            CommManager.reset();
            CommManager cmg = CommManager.instance(_config);

            Assert.IsNotNull(cmg);
            Assert.IsTrue(cmg.getMultiSite());
            Assert.AreEqual(cmg.getMultiSiteThreshold(), 3);

            RequestTarget rt1 = cmg.findUrl();

            Assert.AreEqual(cmg.getMultiSiteUrls()[cmg.getCurrentMultiSiteUrlIndex()], rt1.getUrl());
            cmg.reportResult(rt1, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0);
            RequestTarget rt2 = cmg.findUrl();

            Assert.AreEqual(rt1.getUrl(), rt2.getUrl());
            cmg.reportResult(rt2, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0);
            RequestTarget rt3 = cmg.findUrl();

            Assert.AreEqual(rt1.getUrl(), rt3.getUrl());
            cmg.reportResult(rt3, CommManager.REQUEST_RESULT_RESPONSE_TIMEOUT, 0);
            Assert.AreEqual(cmg.getErrorCount(), 3);

            RequestTarget rt4 = cmg.findUrl();

            Assert.IsFalse(rt4.getUrl().Equals(rt1.getUrl()));
        }
        public void testFindUrl_Legacy()
        {
            Dictionary <string, string> _config = new Dictionary <string, string>
            {
                { "proxyHost", "websenseproxy" },
                { "proxyPort", "8080" },
                { "multiSite", "false" },
                { "printxml", "false" },
                { "printMultiSiteDebug", "true" },
                { "merchantId", "101" },
                { "username", "DOTNET" },
                { "password", "TESTCASE" },
                { "url", legacyUrl }
            };

            CommManager.reset();
            CommManager cmg = CommManager.instance(_config);

            Assert.IsNotNull(cmg);
            Assert.IsFalse(cmg.getMultiSite());
            RequestTarget rt = cmg.findUrl();

            Assert.AreEqual(legacyUrl, rt.getUrl());
        }