Example #1
0
        public void Should_be_implemented()
        {
            var request = new FakeHttpRequest();

            Assert.That(request.ApplicationPath, Is.Null);
            Assert.That(request.AcceptTypes, Is.EquivalentTo(new string[] { }));
        }
Example #2
0
        public void Can_access_form_values_by_default_indexer()
        {
            var request = new FakeHttpRequest();

            request.Form.Add("color", "blue");

            Assert.That(request["color"], Is.EqualTo("blue"));
        }
Example #3
0
        public void Can_specify_request()
        {
            var request = new FakeHttpRequest();

            var context = new FakeHttpContext(request);

            Assert.That(context.Request, Is.SameAs(request));
        }
Example #4
0
        public void Can_add_and_read_from_server_variables()
        {
            var request = new FakeHttpRequest();

            request.ServerVariables.Add("REMOTE_ADDR", "127.0.0.1");

            Assert.That(request.ServerVariables["REMOTE_ADDR"], Is.EqualTo("127.0.0.1"));
        }
Example #5
0
        public void Can_set_authenticated_status()
        {
            var request = new FakeHttpRequest();

            Assert.That(request, Has.Property("IsAuthenticated").False);
            request.Set(req => req.IsAuthenticated, true);
            Assert.That(request, Has.Property("IsAuthenticated").True);
        }
Example #6
0
        public void Can_add_to_form_collection()
        {
            var request = new FakeHttpRequest();

            request.Form.Add("color", "blue");

            Assert.That(request.Form["color"], Is.EqualTo("blue"));
        }
Example #7
0
        public void Should_add_to_query_string()
        {
            var request = new FakeHttpRequest();

            request.QueryString.Add("id", "3");

            Assert.That(request.QueryString["id"], Is.EqualTo("3"));
        }
Example #8
0
        public void Can_access_query_string_values_by_default_indexer()
        {
            var request = new FakeHttpRequest();

            request.QueryString.Add("id", "3");

            Assert.That(request["id"], Is.EqualTo("3"));
        }
Example #9
0
        public void Url_query_string_should_add_to_query_string_collection()
        {
            var url = new Uri("http://google.com?q=awesome&p=1");

            var request = new FakeHttpRequest(url);

            Assert.That(request.QueryString["q"], Is.EqualTo("awesome"));
            Assert.That(request.QueryString["p"], Is.EqualTo("1"));
        }
        public void FakeHttpRequest_CurrentExecutionFilePath_Default_ReturnsCorrectPath()
        {
            var request = new FakeHttpRequest(new Uri("http://127.0.0.1/app/folder/file.aspx/extra?var=val"), "GET");
            request.SetApplicationPath("/app");

            var result = request.CurrentExecutionFilePath;

            Assert.That(result, Is.EqualTo("/app/folder/file.aspx"));
        }
        public void FakeHttpRequest_PathInfo_Default_ReturnsPathInfo()
        {
            var request = new FakeHttpRequest(new Uri("http://127.0.0.1/app/folder/file.aspx/extra?var=val"), "GET");
            request.SetApplicationPath("/app");

            var result = request.PathInfo;

            Assert.That(result, Is.EqualTo("/extra"));
        }
Example #12
0
        public void Should_replace_query_string_when_url_is_changed()
        {
            var original = new Uri("http://google.com?q=original");

            var changed = new Uri("http://google.com?q=changed");

            var request = new FakeHttpRequest(original).SetUrl(changed);

            Assert.That(request.QueryString["q"], Is.EqualTo("changed"));
        }
Example #13
0
        public void Can_set_and_RetrieveInputStream()
        {
            var request = new FakeHttpRequest();
            var requestBodyText = "This is the raw request body.";
            var bytes = Encoding.UTF8.GetBytes(requestBodyText);
            var stream = new MemoryStream(bytes, false);
            request.SetInputStream(stream);

            var gotStream = request.InputStream;
            var rdr = new StreamReader(gotStream, Encoding.UTF8);
            Assert.That(rdr.ReadToEnd(), Is.EqualTo(requestBodyText));
        }
Example #14
0
        public void Can_add_and_read_from_files()
        {
            var request = new FakeHttpRequest();
            var files = new FakeHttpFileCollection();

            var bytes = Encoding.UTF8.GetBytes("These are file contents");
            var fileContents = new MemoryStream();
            fileContents.Write(bytes, 0, bytes.Length);
            fileContents.Flush();
            fileContents.Position = 0;

            var file = new FakeHttpPostedFile("SomeFile.txt", "text/plain", fileContents);
            files.Add("FileFormFieldValue", file);
            request.SetFiles(files);

            Assert.That(request.Files.Count, Is.EqualTo(1));
            Assert.That(request.Files[0].FileName, Is.EqualTo("SomeFile.txt"));
            Assert.That(request.Files[0].ContentType, Is.EqualTo("text/plain"));
            Assert.That(request.Files[0].ContentLength, Is.EqualTo(fileContents.Length));
        }
Example #15
0
 public void Should_set_value()
 {
     var request = new FakeHttpRequest();
     var uri = new Uri("http://localhost/");
     request.Set(req => req.UrlReferrer, uri);
     Assert.That(request, Has.Property("UrlReferrer").EqualTo(uri));
 }
Example #16
0
        public void Url_can_be_set()
        {
            var request = new FakeHttpRequest(new Uri("http://google.com/"));

            Assert.That(request.Url.AbsoluteUri, Is.EqualTo("http://google.com/"));
        }
Example #17
0
 public FakeHttpContext(string url)
 {
     _request = new FakeHttpRequest(url);
 }