示例#1
0
        public void ShouldBeAbleToGetTheContentOfAResource()
        {
            var client = new HttpPlasmaClient(TestFixture.Application);

            var httpPlasmaResponse = client.Get("/GotoPage");

            Assert.That(httpPlasmaResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }
示例#2
0
        public void ShouldFollow301RedirectsWhenNavigatingToAGivenUrl()
        {
            var request = new HttpPlasmaClient(TestFixture.Application);

            var httpPlasmaResponse = request.Get("/GotoPage/ThreeOhOne");

            Assert.That(httpPlasmaResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(httpPlasmaResponse.VirtualPath, Is.EqualTo("/GotoPage"));
        }
示例#3
0
        public void ShouldAcceptCookiesSetByTheHost()
        {
            var client = new HttpPlasmaClient(TestFixture.Application);

            var response = client.Get("/Cookies/Set");

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(client.GetAllCookies().Any(x => x.Name == "Test"), Is.True);
            Assert.That(client.GetAllCookies().First(x => x.Name == "Test").Value, Is.StringContaining("Cookie Set By Host"));
        }
示例#4
0
        public void ShouldExpireCookiesThatAreSetByTheHostIntoThePast()
        {
            var value  = Guid.NewGuid().ToString();
            var client = new HttpPlasmaClient(TestFixture.Application);

            client.AddCookie(new Cookie("test", value));

            var response = client.Get("/Cookies/Expire");

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(client.GetAllCookies().Any(), Is.False);
        }
示例#5
0
        public void ShouldBeAbleToSendCookiesToHost()
        {
            var value  = Guid.NewGuid().ToString();
            var client = new HttpPlasmaClient(TestFixture.Application);

            client.AddCookie(new Cookie("test", value));

            var response = client.Get("/Cookies/Show");

            Assert.That(response.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(response.GetBody(), Is.StringContaining(value));
        }
示例#6
0
        public HttpPlasmaResponse GenerateFormPostRequest(HttpPlasmaClient client)
        {
            // path and query string
            var    headers = new WebHeaderCollection();
            string path;
            string query;

            var iQuery = _action.IndexOf('?');

            if (iQuery >= 0)
            {
                path  = _action.Substring(0, iQuery);
                query = _action.Substring(iQuery + 1);
            }
            else
            {
                path  = _action;
                query = null;
            }

            if (_fileControls.Count > 0)
            {
                var multipartFormBody = new MultipartFormBody(this, _fileControls);

                headers.Add(HttpRequestHeader.ContentLength, multipartFormBody.ContentLength);
                headers.Add(HttpRequestHeader.ContentType, multipartFormBody.ContentType);
                var body = multipartFormBody.FormBodyData();
                return(client.Post(path, query, body, headers));
            }

            var formData = GenerateFormDataAsString();

            if (string.Compare(_method, "GET", StringComparison.OrdinalIgnoreCase) == 0)
            {
                return(client.Get(path, formData));
            }

            var formBody = Encoding.UTF8.GetBytes(formData);

            headers.Add(HttpRequestHeader.ContentLength, formBody.Length.ToString());
            headers.Add(HttpRequestHeader.ContentType, "application/x-www-form-urlencoded");
            return(client.Post(path, query, formBody, headers));
        }
示例#7
0
 public void Get(string url)
 {
     response = httpClient.Get(url);
     ParseHtmlBody();
 }