Beispiel #1
0
 public SimulatedWorkerRequest(WorkerRequestSettings rqstSettings, TextWriter outputStream)
     : base(rqstSettings.Url, rqstSettings.queryString, outputStream)
 {
     this.cookies         = rqstSettings.cookies;
     this.httpVerbName    = rqstSettings.httpMethodName;
     this.formValues      = rqstSettings.formValues;
     this.headers         = rqstSettings.headers;
     this.clientIPAddress = rqstSettings.clientIpAddress;
 }
 public SimulatedWorkerRequest(WorkerRequestSettings rqstSettings, TextWriter outputStream)
     : base(rqstSettings.Url, rqstSettings.queryString, outputStream)
 {
     this.cookies = rqstSettings.cookies;
     this.httpVerbName = rqstSettings.httpMethodName;
     this.formValues = rqstSettings.formValues;
     this.headers = rqstSettings.headers;
     this.clientIPAddress = rqstSettings.clientIpAddress;
 }
        public void Index_GET()
        {
            appHost.Start(browsingSession =>
            {

                //Arrange
                string url = ""; //relative to web site root

                WorkerRequestSettings rqstSettings = new WorkerRequestSettings(url, WorkerRequestSettings.httpRequestMethods.GET);

                //Act
                RequestResult result = browsingSession.ProcessRequest(rqstSettings);
                var viewResult = (ViewResult)result.ActionExecutedContext.Result;

                //Assert
                Xunit.Assert.Equal("Index", viewResult.ViewName);
            });
        }
        public void Index_ModelLanguagesCount()
        {
            appHost.Start(browsingSession =>
            {

                //Arrange
                string url = ""; //relative to web site root

                WorkerRequestSettings rqstSettings = new WorkerRequestSettings(url, WorkerRequestSettings.httpRequestMethods.GET);
                rqstSettings.clientIpAddress = "192.168.30.130";

                //Act
                RequestResult result = browsingSession.ProcessRequest(rqstSettings);
                var viewResult = (ViewResult)result.ActionExecutedContext.Result;

                //Assert
                //Xunit.Assert.Equal(4, ((DialogueModel)viewResult.Model).languagesCount);
            });
        }
        //public RequestResult Get(string url)
        //{
        //    return ProcessRequest(url, HttpVerbs.Get, new NameValueCollection());
        //}
        ///// <summary>
        ///// Sends a post to your url. Url should NOT start with a /
        ///// </summary>
        ///// <param name="url"></param>
        ///// <param name="formData"></param>
        ///// <example>
        ///// <code>
        ///// var result = Post("registration/create", new
        ///// {
        /////     Form = new
        /////     {
        /////         InvoiceNumber = "10000",
        /////         AmountDue = "10.00",
        /////         Email = "*****@*****.**",
        /////         Password = "******",
        /////         ConfirmPassword = "******"
        /////     }
        ///// });
        ///// </code>
        ///// </example>
        //public RequestResult Post(string url, object formData)
        //{
        //    var formNameValueCollection = NameValueCollectionConversions.ConvertFromObject(formData);
        //    return ProcessRequest(url, HttpVerbs.Post, formNameValueCollection);
        //}
        public RequestResult ProcessRequest(WorkerRequestSettings rqstSettings)
        {
            string url = rqstSettings.Url;

            // Perform the request
            LastRequestData.Reset();
            var output = new StringWriter();
            string httpVerbName = rqstSettings.httpMethodName.ToLower();
            var workerRequest = new SimulatedWorkerRequest(rqstSettings, output);
            HttpRuntime.ProcessRequest(workerRequest);

            // Capture the output
            AddAnyNewCookiesToCookieCollection();
            Session = LastRequestData.HttpSessionState;
            return new RequestResult
            {
                ResponseText = output.ToString(),
                ActionExecutedContext = LastRequestData.ActionExecutedContext,
                ResultExecutedContext = LastRequestData.ResultExecutedContext,
                Response = LastRequestData.Response,
            };
        }
Beispiel #6
0
        //public RequestResult Get(string url)
        //{
        //    return ProcessRequest(url, HttpVerbs.Get, new NameValueCollection());
        //}

        ///// <summary>
        ///// Sends a post to your url. Url should NOT start with a /
        ///// </summary>
        ///// <param name="url"></param>
        ///// <param name="formData"></param>
        ///// <example>
        ///// <code>
        ///// var result = Post("registration/create", new
        ///// {
        /////     Form = new
        /////     {
        /////         InvoiceNumber = "10000",
        /////         AmountDue = "10.00",
        /////         Email = "*****@*****.**",
        /////         Password = "******",
        /////         ConfirmPassword = "******"
        /////     }
        ///// });
        ///// </code>
        ///// </example>
        //public RequestResult Post(string url, object formData)
        //{
        //    var formNameValueCollection = NameValueCollectionConversions.ConvertFromObject(formData);
        //    return ProcessRequest(url, HttpVerbs.Post, formNameValueCollection);
        //}

        public RequestResult ProcessRequest(WorkerRequestSettings rqstSettings)
        {
            string url = rqstSettings.Url;

            // Perform the request
            LastRequestData.Reset();
            var    output        = new StringWriter();
            string httpVerbName  = rqstSettings.httpMethodName.ToLower();
            var    workerRequest = new SimulatedWorkerRequest(rqstSettings, output);

            HttpRuntime.ProcessRequest(workerRequest);

            // Capture the output
            AddAnyNewCookiesToCookieCollection();
            Session = LastRequestData.HttpSessionState;
            return(new RequestResult
            {
                ResponseText = output.ToString(),
                ActionExecutedContext = LastRequestData.ActionExecutedContext,
                ResultExecutedContext = LastRequestData.ResultExecutedContext,
                Response = LastRequestData.Response,
            });
        }