Esempio n. 1
0
        public void ShouldBeAbleToGetTheContentOfAResource()
        {
            var client = new HttpPlasmaClient(TestFixture.Application);

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

            Assert.That(httpPlasmaResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
        }
Esempio n. 2
0
        public void ShouldFollow302RedirectsWhenNavigatingToAGivenUrl()
        {
            var request = new HttpPlasmaClient(TestFixture.Application);

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

            Assert.That(httpPlasmaResponse.StatusCode, Is.EqualTo(HttpStatusCode.OK));
            Assert.That(httpPlasmaResponse.VirtualPath, Is.EqualTo("/GotoPage"));
        }
Esempio n. 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"));
        }
Esempio n. 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);
        }
Esempio n. 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));
        }
Esempio n. 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);
        }
Esempio n. 7
0
 public WebBrowser(AspNetApplication aspNetApplication)
 {
     httpClient = new HttpPlasmaClient(aspNetApplication);
 }