Пример #1
0
        public void RemoteApplication_ByPass()
        {
            PathMap map =
                PathMap.CreateFromFile(
                    @"MappingTest\Mapping.xml");

            RemoteApplication.Initialize(map);

            HttpContext context = HttpContextHelper.CreateHttpContext("GET", "/zmrres/images/somepicture.png",
                                                                      "name1=value1");

            RemoteApplication remoteApplication = RemoteApplication.GetRemoteApplication(context.Request);
            TrafficLogger     logger            = new TrafficLogger(remoteApplication.RemoteApplicationProxyPath, "UnitTest", new TraceScope(null), context.Request.Url);
            string            rightSideUrl      = remoteApplication.GetRightSideUrl(context.Request);

            Assert.AreEqual("https://portal.bmi.gv.at/images/somepicture.png?name1=value1", rightSideUrl,
                            "RightSideUrl");
            Assert.IsTrue(remoteApplication.ByPass(context.Request.Url.AbsolutePath));

            using (Stream inputBuffer = CopyFilter.GetInputStream(context.Request))
            {
                HttpWebRequest request = remoteApplication.CreateRightSideRequest(context.Request, inputBuffer, logger);
                Assert.IsNotNull(request, "Request is null.");
                Assert.AreEqual("GET", request.Method);
            }
        }
Пример #2
0
        public void RemoteApplication_PostRequest()
        {
            PathMap map =
                PathMap.CreateFromFile(
                    @"MappingTest\Mapping.xml");

            RemoteApplication.Initialize(map);

            HttpContext context         = HttpContextHelper.CreateHttpContext("POST", "/localtest1/", null);
            HttpRequest leftSideRequest = context.Request;

            RemoteApplication remoteApplication = RemoteApplication.GetRemoteApplication(context.Request);
            TrafficLogger     logger            = new TrafficLogger(remoteApplication.RemoteApplicationProxyPath, "UnitTest", new TraceScope(null), context.Request.Url);
            string            rightSideUrl      = remoteApplication.GetRightSideUrl(context.Request);

            Assert.AreEqual("http://egoratest/PvpTestApplication/1/", rightSideUrl, "RightSideUrl");

            using (Stream inputBuffer = CopyFilter.GetInputStream(context.Request))
            {
                HttpWebRequest rightSideRequest = remoteApplication.CreateRightSideRequest(context.Request, inputBuffer, logger);
                Assert.IsNotNull(rightSideRequest, "Request is null.");
                Assert.AreEqual("POST", rightSideRequest.Method);
                // currently empty collection
                foreach (HttpHeader header in leftSideRequest.Headers)
                {
                    Assert.IsNotNull(rightSideRequest.Headers[header.Name], "header");
                    Assert.AreEqual(header.Value, rightSideRequest.Headers[header.Name]);
                }
            }
        }
        // methods and properties

        protected override void SetUpContext()
        {
            base.SetUpContext();

            _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            HttpContextHelper.SetCurrent(_currentHttpContext);
        }
Пример #4
0
        [Ignore] // test no longer works since Framwork 3.0 installed
        public void RightSideHeader_FromCustomLeftSideHeader()
        {
            PathMap map =
                PathMap.CreateFromFile(
                    @"MappingTest\Mapping.xml");

            RemoteApplication.Initialize(map);

            HttpContext context =
                HttpContextHelper.CreateHttpContext("GET", "/localtest1/TestPage.aspx/someinfo", "name1=value1");


            RemoteApplication remoteApplication = RemoteApplication.GetRemoteApplication(context.Request);

            Assert.IsNotNull(remoteApplication, "remoteApplication");

            TrafficLogger       logger  = new TrafficLogger(remoteApplication.RemoteApplicationProxyPath, "UnitTest", new TraceScope(null), context.Request.Url);
            NameValueCollection headers = new NameValueCollection();

            headers.Add("X-Custom", "CustomValue");
            headers.Add("Range", "messages=1-20,25-30");
            HttpRequestHelper.AddHeaders(context.Request, headers);
            using (Stream inputBuffer = CopyFilter.GetInputStream(context.Request))
            {
                HttpWebRequest webRequest = remoteApplication.CreateRightSideRequest(context.Request, inputBuffer, logger);
                Assert.IsNotNull(webRequest, "Request is null.");
                Assert.AreEqual("GET", webRequest.Method);
                Assert.IsNotNull(webRequest.Headers["X-Custom"], "CustomHeader");
                Assert.AreEqual("CustomValue", webRequest.Headers["X-Custom"]);
                Assert.IsNotNull(webRequest.Headers["Range"], "Range");
                Assert.AreEqual("messages=1-20,25-30", webRequest.Headers["Range"]);
            }
        }
 public void HasSessionAndGetCurrent()
 {
     HttpContextHelper.SetCurrent(HttpContextHelper.CreateHttpContext("get", "default.aspx", string.Empty));
     Assert.That(WxeFunctionStateManager.HasSession, Is.False);
     Assert.That(WxeFunctionStateManager.Current, Is.Not.Null);
     Assert.That(WxeFunctionStateManager.HasSession, Is.True);
 }
Пример #6
0
        public void RemoteApplication_GetRequest()
        {
            PathMap map =
                PathMap.CreateFromFile(
                    @"MappingTest\Mapping.xml");

            RemoteApplication.Initialize(map);

            HttpContext context = HttpContextHelper.CreateHttpContext("GET", "/localtest1/TestPage.aspx/someinfo", "name1=value1");

            using (new TraceScope(context))
            {
                RemoteApplication remoteApplication = RemoteApplication.GetRemoteApplication(context.Request);
                TrafficLogger     logger            = new TrafficLogger(remoteApplication.RemoteApplicationProxyPath, "UnitTest", new TraceScope(null), context.Request.Url);
                string            rightSideUrl      = remoteApplication.GetRightSideUrl(context.Request);
                Assert.AreEqual("http://egoratest/PvpTestApplication/1/TestPage.aspx/someinfo?name1=value1", rightSideUrl,
                                "RightSideUrl");

                using (Stream inputBuffer = CopyFilter.GetInputStream(context.Request))
                {
                    HttpWebRequest request = remoteApplication.CreateRightSideRequest(context.Request, inputBuffer, logger);
                    Assert.IsNotNull(request, "Request is null.");
                    Assert.AreEqual("GET", request.Method);
                }
            }
        }
Пример #7
0
        protected void SetupHttpContext()
        {
            var httpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);

            httpContext.Response.ContentEncoding = Encoding.UTF8;
            HttpContextHelper.SetCurrent(httpContext);
        }
Пример #8
0
        protected override void SetUpContext()
        {
            base.SetUpContext();

            _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            _currentHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContextHelper.SetCurrent(_currentHttpContext);
        }
Пример #9
0
        public virtual void SetUp()
        {
            _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            HttpContextHelper.SetCurrent(_currentHttpContext);

            _currentWxeContext = new WxeContextMock(_currentHttpContext);
            WxeContext.SetCurrent(_currentWxeContext);
        }
Пример #10
0
        public static HttpContext CreateHttpContext(NameValueCollection queryString)
        {
            HttpContext context = HttpContextHelper.CreateHttpContext("GET", "Other.wxe", null);

            context.Response.ContentEncoding = Encoding.UTF8;
            HttpContextHelper.SetQueryString(context, queryString);
            HttpContextHelper.SetCurrent(context);
            return(context);
        }
Пример #11
0
        public void RetrieveMissingFunctionStateWithTypeFromMapping()
        {
            HttpContext context = HttpContextHelper.CreateHttpContext("GET", "Test.wxe", null);

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(_functionType, "~/Test.wxe"));

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(_functionType));
        }
Пример #12
0
        public void RetrieveMissingFunctionStateWithTypeFromQueryStringAndPostRequest()
        {
            HttpContext         context     = HttpContextHelper.CreateHttpContext("POST", "Test.wxe", null);
            NameValueCollection queryString = new NameValueCollection();

            queryString.Add(WxeHandler.Parameters.WxeFunctionType, _functionTypeName);
            HttpContextHelper.SetQueryString(context, queryString);

            Remotion.Web.ExecutionEngine.UrlMapping.UrlMappingConfiguration.SetCurrent(null);

            _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);
        }
Пример #13
0
        public void RetrieveMissingFunctionStateWithTypeFromMappingAndPostRequest()
        {
            HttpContext         context = HttpContextHelper.CreateHttpContext("POST", "Test.wxe", null);
            NameValueCollection form    = new NameValueCollection();

            form.Add(WxeHandler.Parameters.WxeFunctionToken, c_functionTokenForMissingFunctionState);
            HttpContextHelper.SetForm(context, form);

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(typeof(TestFunction), "~/Test.wxe"));

            _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);
        }
Пример #14
0
        public void RetrieveMissingFunctionStateWithTypeFromMappingAndGetRequestWithPostBackAction()
        {
            HttpContext         context     = HttpContextHelper.CreateHttpContext("GET", "Test.wxe", null);
            NameValueCollection queryString = new NameValueCollection();

            queryString.Add(WxeHandler.Parameters.WxeAction, WxeHandler.Actions.Refresh);
            HttpContextHelper.SetQueryString(context, queryString);

            UrlMappingConfiguration.Current.Mappings.Add(new UrlMappingEntry(typeof(TestFunction), "~/Test.wxe"));

            _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);
        }
Пример #15
0
        public void SetUp()
        {
            _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            HttpContextHelper.SetCurrent(_currentHttpContext);

            _page = new PageMock();
            _page.SetRequestValueCollection(new NameValueCollection());
            _currentHttpContext.Handler = _page;

            _parent            = new PlaceHolder();
            _parent.ID         = "Parent";
            _parent.Init      += new EventHandler(Control_Init);
            _parent.Load      += new EventHandler(Control_Load);
            _parent.PreRender += new EventHandler(Control_PreRender);
            _page.Controls.Add(_parent);

            _child            = new Literal();
            _child.ID         = "Child";
            _child.Init      += new EventHandler(Control_Init);
            _child.Load      += new EventHandler(Control_Load);
            _child.PreRender += new EventHandler(Control_PreRender);

            _parent.Controls.Add(_child);

            _invoker = new ControlInvoker(_parent);


            _pageAfterPostBack = new PageMock();
            _pageAfterPostBack.SetRequestValueCollection(new NameValueCollection());
            _currentHttpContext.Handler = _pageAfterPostBack;

            _parentAfterPostBack            = new PlaceHolder();
            _parentAfterPostBack.ID         = "Parent";
            _parentAfterPostBack.Init      += new EventHandler(Control_Init);
            _parentAfterPostBack.Load      += new EventHandler(Control_Load);
            _parentAfterPostBack.PreRender += new EventHandler(Control_PreRender);
            _pageAfterPostBack.Controls.Add(_parentAfterPostBack);

            _childAfterPostBack            = new Literal();
            _childAfterPostBack.ID         = "Child";
            _childAfterPostBack.Init      += new EventHandler(Control_Init);
            _childAfterPostBack.Load      += new EventHandler(Control_Load);
            _childAfterPostBack.PreRender += new EventHandler(Control_PreRender);

            _parentAfterPostBack.Controls.Add(_childAfterPostBack);

            _invokerAfterPostBack = new ControlInvoker(_parentAfterPostBack);

            _events = string.Empty;
        }
Пример #16
0
        // construction and disposing

        public CommandTestHelper()
        {
            _httpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            _httpContext.Response.ContentEncoding = Encoding.UTF8;

            _functionType     = typeof(TestFunction);
            _functionTypeName = TypeUtility.GetPartialAssemblyQualifiedName(_functionType);

            _mocks = new MockRepository();
            _mockWebSecurityAdapter = _mocks.StrictMock <IWebSecurityAdapter>();
            _mockWxeSecurityAdapter = _mocks.StrictMock <IWxeSecurityAdapter>();
            _mockSecurableObject    = _mocks.StrictMock <ISecurableObject>();

            _htmlWriter = new HtmlTextWriterSingleTagMock();
        }
Пример #17
0
        public void RetrieveMissingFunctionStateWithTypeFromQueryString()
        {
            HttpContext         context     = HttpContextHelper.CreateHttpContext("GET", "Test.wxe", null);
            NameValueCollection queryString = new NameValueCollection();

            queryString.Add(WxeHandler.Parameters.WxeFunctionType, _functionTypeName);
            HttpContextHelper.SetQueryString(context, queryString);

            Remotion.Web.ExecutionEngine.UrlMapping.UrlMappingConfiguration.SetCurrent(null);

            WxeFunctionState functionState = _wxeHandler.ResumeExistingFunctionState(context, c_functionTokenForMissingFunctionState);

            Assert.That(functionState, Is.Not.Null);
            Assert.That(functionState.Function.GetType(), Is.EqualTo(typeof(TestFunction)));
        }
Пример #18
0
        /// <summary>
        /// Update Media
        /// </summary>
        /// <param name="id">Media Id</param>
        public void Update(int id, int actualSize)
        {
            // httpContext is null when optimization on upload
            // https://our.umbraco.org/projects/backoffice-extensions/tinifier/bugs/90472-error-systemargumentnullexception-value-cannot-be-null
            if (HttpContext.Current == null)
            {
                HttpContext.Current = HttpContextHelper.CreateHttpContext
                                          (new HttpRequest("", "http://localhost/", ""), new HttpResponse(new StringWriter()));
            }

            var mediaItem = _mediaService.GetById(id) as Media;

            if (mediaItem != null)
            {
                mediaItem.SetValue("umbracoBytes", actualSize);
                mediaItem.UpdateDate = DateTime.UtcNow;
                // raiseEvents: false - #2827
                _mediaService.Save(mediaItem, raiseEvents: false);
            }
        }
Пример #19
0
        public void RemoteApplication_GetRemoteApplication()
        {
            PathMap map =
                PathMap.CreateFromFile(
                    @"MappingTest\Mapping.xml");

            RemoteApplication.Initialize(map);

            HttpContext context1 = HttpContextHelper.CreateHttpContext("GET", "/localtest/TestPage.aspx/someinfo",
                                                                       "name1=value1");

            RemoteApplication app1 = RemoteApplication.GetRemoteApplication(context1.Request);

            Assert.IsNotNull(app1, "RemoteApplication");

            HttpContext context2 = HttpContextHelper.CreateHttpContext("GET", "/somepath/TestPage.aspx/someinfo",
                                                                       "name1=value1");
            RemoteApplication app2 = RemoteApplication.GetRemoteApplication(context2.Request);

            Assert.IsNotNull(app2);
            Assert.AreEqual("https://someserver/", app2.RootUrl);
        }
        public virtual void SetUp()
        {
            _currentHttpContext = HttpContextHelper.CreateHttpContext("GET", "default.html", null);
            _currentHttpContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
            HttpContextHelper.SetCurrent(_currentHttpContext);

            _functionType               = typeof(TestFunction);
            _functionTypeName           = TypeUtility.GetPartialAssemblyQualifiedName(_functionType);
            _wxeFunctionParameter1Value = "Value1";
            _wxeFunctionParameters      = "\"Value1\"";

            _toolTip       = "This is a Tool Tip.";
            _href          = "test.html?Param1={0}&Param2={1}";
            _target        = "_blank";
            _postBackEvent = "__doPostBack (\"Target\", \"Args\");";
            _onClick       = "return false;";

            _hrefCommand                    = new NavigationCommand();
            _hrefCommand.Type               = CommandType.Href;
            _hrefCommand.ToolTip            = _toolTip;
            _hrefCommand.HrefCommand.Href   = _href;
            _hrefCommand.HrefCommand.Target = _target;

            _eventCommand         = new NavigationCommand();
            _eventCommand.Type    = CommandType.Event;
            _eventCommand.ToolTip = _toolTip;

            _wxeFunctionCommand         = new NavigationCommand();
            _wxeFunctionCommand.Type    = CommandType.WxeFunction;
            _wxeFunctionCommand.ToolTip = _toolTip;
            _wxeFunctionCommand.WxeFunctionCommand.TypeName   = _functionTypeName;
            _wxeFunctionCommand.WxeFunctionCommand.Parameters = _wxeFunctionParameters;
            _wxeFunctionCommand.WxeFunctionCommand.Target     = _target;

            _noneCommand      = new NavigationCommand();
            _noneCommand.Type = CommandType.None;

            _writer = new HtmlTextWriterSingleTagMock();
        }
Пример #21
0
        public virtual void SetUp()
        {
            _wcagHelperMock = new WcagHelperMock();
            WcagHelper.SetInstance(_wcagHelperMock);

            _page = new Page();

            _namingContainer    = new NamingContainerMock();
            _namingContainer.ID = "NamingContainer";
            _page.Controls.Add(_namingContainer);

            _invoker = new ControlInvoker(_namingContainer);

            var context = HttpContextHelper.CreateHttpContext("GET", "/", "");

            HttpContextHelper.SetCurrent(context);
            HttpBrowserCapabilities browser = new HttpBrowserCapabilities();

            browser.Capabilities = new Hashtable();
            browser.Capabilities.Add("browser", "IE");
            browser.Capabilities.Add("majorversion", "7");
            context.Request.Browser = browser;
        }
Пример #22
0
 public void SetUp()
 {
     _testContext        = HttpContextHelper.CreateHttpContext("x", "y", "z");
     HttpContext.Current = _testContext;
     _provider           = new HttpContextStorageProvider();
 }
 public void GetCurrent_SameInstanceTwice()
 {
     HttpContextHelper.SetCurrent(HttpContextHelper.CreateHttpContext("get", "default.aspx", string.Empty));
     Assert.That(WxeFunctionStateManager.Current, Is.SameAs(WxeFunctionStateManager.Current));
 }
Пример #24
0
 public void ProcessRequest()
 {
     ProcessRequest(HttpContextHelper.CreateHttpContext("POST", "page.aspx", ""));
 }