public TableRow[] CreateExpectations(string testCase)
        {
            testCase = testCase ?? AllTests;
            _testControlGenerator = new TestControlGenerator(_testPage, new PostBackEventHandler());

            List <TableRow> rows = new List <TableRow>();

            rows.Add(Expect("open", UrlUtility.AddParameter(_testPage.ResolveClientUrl(_sutPage), SutGenerator.ServerDelayParameter, "500"), null));

            foreach (Control control in _testControlGenerator.GetTestControls(null))
            {
                rows.AddRange(ExpectControlAttributes(control));
            }

            foreach (Control initialControl in _testControlGenerator.GetTestControls(null))
            {
                if (testCase == AllTests || testCase == initialControl.ID)
                {
                    foreach (Control followUpControl in _testControlGenerator.GetTestControls(initialControl.ID))
                    {
                        rows.AddRange(ExpectPostbackForControl(initialControl, followUpControl));
                    }
                }
            }

            return(rows.ToArray());
        }
Exemplo n.º 2
0
        /// <summary>
        ///   Gets the permanent URL for the <see cref="WxeFunction"/> of the specified <paramref name="functionType"/>
        ///   and using the <paramref name="urlParameters"/>.
        /// </summary>
        /// <include file='..\doc\include\ExecutionEngine\WxeContext.xml' path='WxeContext/GetPermanentUrl/param[@name="functionType" or @name="urlParameters" or @name="useParentPermanentUrl"]' />
        public string GetPermanentUrl(Type functionType, NameValueCollection urlParameters, bool useParentPermanentUrl)
        {
            ArgumentUtility.CheckNotNull("urlParameters", urlParameters);

            string permanentUrl = WxeContext.GetPermanentUrl(_httpContext, functionType, urlParameters, true);

            if (useParentPermanentUrl)
            {
                if (urlParameters[WxeHandler.Parameters.ReturnUrl] != null)
                {
                    throw new ArgumentException("The 'urlParameters' collection must not contain a 'ReturnUrl' parameter when creating a parent permanent URL.", "urlParameters");
                }

                int maxLength = Configuration.WebConfiguration.Current.ExecutionEngine.MaximumUrlLength;

                string           currentFunctionUrl  = UrlUtility.AddParameters(_httpContext.Request.Url.AbsolutePath, _queryString, _httpContext.Response.ContentEncoding);
                StringCollection parentPermanentUrls = ExtractReturnUrls(currentFunctionUrl);

                int    count = GetMergeablePermanentUrlCount(permanentUrl, parentPermanentUrls, maxLength);
                string parentPermanentUrl = FormatParentPermanentUrl(parentPermanentUrls, count);

                if (!string.IsNullOrEmpty(parentPermanentUrl))
                {
                    permanentUrl = UrlUtility.AddParameter(permanentUrl, WxeHandler.Parameters.ReturnUrl, parentPermanentUrl, _httpContext.Response.ContentEncoding);
                }
            }
            return(permanentUrl);
        }
Exemplo n.º 3
0
        public void FormatUrlForSubMenuTab()
        {
            string url = "/AppDir/page.aspx";
            string expectedParameterValue = string.Format("{0},{1}", _subMenuTab22.Parent.ItemID, _subMenuTab22.ItemID);
            string expectedUrl            = UrlUtility.AddParameter(url, _tabbedMenu.SelectionID, expectedParameterValue);

            string value = _tabbedMenu.FormatUrl(url, _subMenuTab22);

            Assert.That(value, Is.Not.Null);
            Assert.That(value, Is.EqualTo(expectedUrl));
        }
Exemplo n.º 4
0
        public void FormatUrlForMainMenuTab()
        {
            string url = "/AppDir/page.aspx";
            string expectedParameterValue = _mainMenuTab2.ItemID;
            string expectedUrl            = UrlUtility.AddParameter(url, _tabbedMenu.SelectionID, expectedParameterValue);

            string value = _tabbedMenu.FormatUrl(url, _mainMenuTab2);

            Assert.That(value, Is.Not.Null);
            Assert.That(value, Is.EqualTo(expectedUrl));
        }
Exemplo n.º 5
0
        public void AddParameterToUrlWithQuestionmark()
        {
            string url       = "http://localhost/Default.html?";
            string parameter = "Parameter1";
            string value     = "Value1ä#";

            string expected = string.Format(
                "{0}{1}={2}",
                url,
                parameter,
                HttpUtility.UrlEncode(value, _currentEncoding));

            string actual = UrlUtility.AddParameter(url, parameter, value, _currentEncoding);

            Assert.That(actual, Is.EqualTo(expected));
        }
Exemplo n.º 6
0
        public void AddParameterToEmptyUrl()
        {
            string url       = string.Empty;
            string parameter = "Parameter1";
            string value     = "Value1ä#";

            string expected = string.Format(
                "{0}?{1}={2}",
                url,
                parameter,
                HttpUtility.UrlEncode(value, _currentEncoding));

            string actual = UrlUtility.AddParameter(url, parameter, value, _currentEncoding);

            Assert.That(actual, Is.EqualTo(expected));
        }
        public void Render_WithAccessGranted()
        {
            Command command = _testHelper.CreateHrefCommandAsPartialMock();

            string[] parameters = new string[] { "Value1", "Value2" };

            NameValueCollection additionalUrlParameters = new NameValueCollection();

            additionalUrlParameters.Add("Parameter3", "Value3");

            string expectedHref = command.HrefCommand.FormatHref(parameters);

            expectedHref = UrlUtility.AddParameter(expectedHref, additionalUrlParameters.GetKey(0), additionalUrlParameters.Get(0));
            string expectedOnClick = _testHelper.OnClick;

            _testHelper.ExpectOnceOnHasAccess(command, true);
            _testHelper.ReplayAll();

            command.RenderBegin(
                _testHelper.HtmlWriter,
                RenderingFeatures.Default,
                _testHelper.PostBackEvent,
                parameters,
                _testHelper.OnClick,
                _testHelper.SecurableObject,
                additionalUrlParameters,
                true,
                new Style());

            _testHelper.VerifyAll();

            Assert.IsNotNull(_testHelper.HtmlWriter.Tag, "Missing Tag");
            Assert.AreEqual(HtmlTextWriterTag.A, _testHelper.HtmlWriter.Tag, "Wrong Tag");

            Assert.IsNotNull(_testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Href], "Missing Href");
            Assert.AreEqual(expectedHref, _testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Href], "Wrong Href");

            Assert.IsNotNull(_testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Onclick], "Missing OnClick");
            Assert.AreEqual(expectedOnClick, _testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Onclick], "Wrong OnClick");

            Assert.IsNotNull(_testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Title], "Missing Title");
            Assert.AreEqual(_testHelper.ToolTip, _testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Title], "Wrong Title");

            Assert.IsNotNull(_testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Target], "Missing Target");
            Assert.AreEqual(_testHelper.Target, _testHelper.HtmlWriter.Attributes[HtmlTextWriterAttribute.Target], "Wrong Target");
        }
        public TableRow[] CreateTestCases(string prefix)
        {
            TestControlGenerator testControlGenerator = new TestControlGenerator(_testSuitePage, new PostBackEventHandler());
            List <TableRow>      rows = new List <TableRow>();

            foreach (Control initialControl in testControlGenerator.GetTestControls(null))
            {
                if (testControlGenerator.IsEnabled(initialControl))
                {
                    rows.Add(
                        CreateTest(
                            CreateID(prefix, initialControl.ID),
                            UrlUtility.AddParameter(_testSuitePage.ResolveUrl(_testPage), TestExpectationsGenerator.TestCaseParameter, initialControl.ID)));
                }
            }

            return(rows.ToArray());
        }
Exemplo n.º 9
0
        private int GetMergeablePermanentUrlCount(string baseUrl, StringCollection parentPermanentUrls, int maxLength)
        {
            int i = 0;

            for (; i < parentPermanentUrls.Count; i++)
            {
                string parentPermanentUrl = FormatParentPermanentUrl(parentPermanentUrls, i + 1);
                if (parentPermanentUrl.Length >= maxLength)
                {
                    break;
                }
                string url = UrlUtility.AddParameter(baseUrl, WxeHandler.Parameters.ReturnUrl, parentPermanentUrl, _httpContext.Response.ContentEncoding);
                if (url.Length > maxLength)
                {
                    break;
                }
            }
            return(i);
        }
Exemplo n.º 10
0
        private string FormatParentPermanentUrl(StringCollection parentPermanentUrls, int count)
        {
            if (count > parentPermanentUrls.Count)
            {
                throw new ArgumentOutOfRangeException("count");
            }

            string parentPermanentUrl = null;

            for (int i = count - 1; i >= 0; i--)
            {
                string temp = parentPermanentUrls[i];
                if (string.IsNullOrEmpty(parentPermanentUrl))
                {
                    parentPermanentUrl = temp;
                }
                else
                {
                    parentPermanentUrl = UrlUtility.AddParameter(temp, WxeHandler.Parameters.ReturnUrl, parentPermanentUrl, _httpContext.Response.ContentEncoding);
                }
            }
            return(parentPermanentUrl);
        }