Example #1
0
        private static HttpContextBase FakeHttpContext(string url, HttpVerbs?httpMethod, HttpVerbs?formMethod)
        {
            NameValueCollection form = null;

            if (formMethod.HasValue)
            {
                form = new NameValueCollection {
                    { "_method", formMethod.Value.ToString().ToUpper() }
                }
            }
            ;

            if (!httpMethod.HasValue)
            {
                httpMethod = HttpVerbs.Get;
            }

            var request = MockRepository.GenerateStub <HttpRequestBase>();

            request.Stub(x => x.AppRelativeCurrentExecutionFilePath).Return(url).Repeat.Any();
            request.Stub(x => x.PathInfo).Return(string.Empty).Repeat.Any();
            request.Stub(x => x.Form).Return(form).Repeat.Any();
            request.Stub(x => x.HttpMethod).Return(httpMethod.Value.ToString().ToUpper()).Repeat.Any();

            var context = new FakeHttpContext(url);

            context.SetRequest(request);

            return(context);
        }
        private static HttpContextBase FakeHttpContext(string url, HttpVerbs?httpMethod, HttpVerbs?formMethod)
        {
            NameValueCollection form = null;

            if (formMethod.HasValue)
            {
                form = new NameValueCollection {
                    { "_method", formMethod.Value.ToString().ToUpper() }
                }
            }
            ;

            if (!httpMethod.HasValue)
            {
                httpMethod = HttpVerbs.Get;
            }

            var mockFactory = new FirstAvailableMockFactory();
            var request     = mockFactory.DynamicMock <HttpRequestBase>();

            request.ReturnFor(x => x.AppRelativeCurrentExecutionFilePath, url);
            request.ReturnFor(x => x.PathInfo, string.Empty);
            request.ReturnFor(x => x.Form, form);
            request.ReturnFor(x => x.HttpMethod, httpMethod.Value.ToString().ToUpper());

            var context = new FakeHttpContext(url);

            context.SetRequest(request.Object);

            return(context);
        }
        private RewriteUrlAttribute CreateRewriteUrlAttribute(
            Store store,
            string requestUrl,
            CanonicalHostNameRule rule,
            out AuthorizationContext filterContext)
        {
            filterContext = null;

            var attr = new RewriteUrlAttribute(SslRequirement.Yes)
            {
                SeoSettings = new Lazy <SeoSettings>(() => new SeoSettings
                {
                    CanonicalHostNameRule = rule
                }),
                SecuritySettings = new Lazy <SecuritySettings>(() => new SecuritySettings
                {
                    UseSslOnLocalhost = true
                })
            };

            var storeContext = MockRepository.GenerateMock <IStoreContext>();

            storeContext.Expect(x => x.CurrentStore).Return(store);
            attr.StoreContext = new Lazy <IStoreContext>(() => storeContext);

            var workContext = MockRepository.GenerateMock <IWorkContext>();

            attr.WorkContext = new Lazy <IWorkContext>(() => workContext);

            var httpContext = new FakeHttpContext("~/", "GET");
            var httpRequest = new FakeHttpRequest("~/", new Uri(requestUrl), null);

            httpContext.SetRequest(httpRequest);

            var    isHttps      = httpRequest.IsSecureConnection;
            string secureUrl    = isHttps ? requestUrl : requestUrl.Replace("http:", "https:");
            string nonSecureUrl = isHttps ? requestUrl.Replace("https:", "http:") : requestUrl;

            var webHelper = MockRepository.GenerateMock <IWebHelper>();

            webHelper.Expect(x => x.IsCurrentConnectionSecured()).Return(isHttps);
            webHelper.Expect(x => x.GetThisPageUrl(true, true)).Return(secureUrl);
            webHelper.Expect(x => x.GetThisPageUrl(true, false)).Return(nonSecureUrl);
            attr.WebHelper = new Lazy <IWebHelper>(() => webHelper);

            filterContext = new AuthorizationContext
            {
                HttpContext = httpContext
            };

            return(attr);
        }
Example #4
0
        public static FakeHttpContext FakeHttpContext()
        {
            var cookieColletion = new HttpCookieCollection();

            var fakeContext = new FakeHttpContext("/");
            var fakeRequest = new FakeHttpRequest("/", "get", new Uri("http://localhost"), new Uri("http://localhost"),
                                                  new NameValueCollection(), new NameValueCollection(), cookieColletion);

            var fakeResponse = new FakeHttpResponseForCookieHandeling();


            fakeContext.SetRequest(fakeRequest);
            fakeContext.SetResponse(fakeResponse);

            return(fakeContext);
        }
        private static HttpContextBase FakeHttpContext(string url, HttpVerbs?httpMethod, HttpVerbs?formMethod)
        {
            NameValueCollection form = null;

            if (formMethod.HasValue)
            {
                form = new NameValueCollection {
                    { "_method", formMethod.Value.ToString().ToUpper() }
                }
            }
            ;

            if (!httpMethod.HasValue)
            {
                httpMethod = HttpVerbs.Get;
            }

            var mockFactory = new FirstAvailableMockFactory();
            var request     = mockFactory.DynamicMock <HttpRequestBase>();

            request.ReturnFor(x => x.AppRelativeCurrentExecutionFilePath, url);
            request.ReturnFor(x => x.PathInfo, string.Empty);
            request.ReturnFor(x => x.Form, form);
            request.ReturnFor(x => x.HttpMethod, httpMethod.Value.ToString().ToUpper());

            if (url.StartsWith("/"))
            {
                url = url.Insert(0, "http://www.google.com");
            }
            else if (url.StartsWith("~"))
            {
                url = url.Substring(1, url.Length - 1);
                url = url.Insert(0, "http://www.google.com");
            }

            var uri        = new System.Uri(url);
            var parameters = HttpUtility.ParseQueryString(uri.Query);

            request.ReturnFor(x => x.Params, parameters);
            request.ReturnFor(x => x.Path, uri.AbsolutePath);

            var context = new FakeHttpContext(url);

            context.SetRequest(request.Object);

            return(context);
        }
Example #6
0
        private FakeHttpContext CreateJONCookieInFakeHttpContextWith10ItemsInside()
        {
            var cookie = new HttpCookie("JON");

            cookie["wishlistitems"] = String.Join(",", fixture.CreateMany <int>(10));

            var cookieColletion = new HttpCookieCollection();

            cookieColletion.Add(cookie);


            var fakeContext = new FakeHttpContext("/");
            var fakeRequest = new FakeHttpRequest("/", "get", new Uri("http://localhost"), new Uri("http://localhost"),
                                                  new NameValueCollection(), new NameValueCollection(), cookieColletion);

            var fakeResponse = new FakeHttpResponseForCookieHandeling();

            fakeContext.SetResponse(fakeResponse);
            fakeContext.SetRequest(fakeRequest);
            return(fakeContext);
        }