Example #1
0
        public void CanSimulateFormPost()
        {
            using (var simulator = new HttpSimulator())
            {
                var form = new NameValueCollection();
                form.Add("Test1", "Value1");
                form.Add("Test2", "Value2");
                simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), form);

                Assert.AreEqual("Value1", simulator.Context.Request.Form["Test1"]);
                Assert.AreEqual("Value2", simulator.Context.Request.Form["Test2"]);
                Assert.AreEqual(new Uri("http://localhost/Test.aspx"), simulator.Context.Request.Url);
            }

            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Test1", "Value1")
                .SetFormVariable("Test2", "Value2")
                .SimulateRequest(new Uri("http://localhost/Test.aspx"));

                Assert.AreEqual("Value1", simulator.Context.Request.Form["Test1"]);
                Assert.AreEqual("Value2", simulator.Context.Request.Form["Test2"]);
                Assert.AreEqual(new Uri("http://localhost/Test.aspx"), simulator.Context.Request.Url);
            }
        }
        private static void SimulateHttpRequest(Action <SentryRequest> test)
        {
            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Form1", "Value1");
                simulator.SetHeader("UserAgent", "SharpRaven");
                simulator.SetCookie("Cookie", "Monster");

                using (simulator.SimulateRequest())
                {
                    var request = SentryRequest.GetRequest();
                    test.Invoke(request);
                }
            }
        }
    	////[Test]
        public void TestHttpHandlerWritesCorrectResponse()
        {
            using (var simulator = new HttpSimulator("/", @"c:\inetpub\"))
            {
                simulator.SetFormVariable("username", "phil")
                    .SetReferer(new Uri("http://example.com/1/"))
                    .SimulateRequest(new Uri("http://localhost/MyHandler.ashx?id=1234"));

                var handler = new TestHttpHandler();
                handler.ProcessRequest(HttpContext.Current);
                HttpContext.Current.Response.Flush();

                const string expected = @"c:\inetpub\MyHandler.ashx:phil:1234:http://example.com/1/";
                Assert.AreEqual(expected, simulator.ResponseText, "The Expected Response is all wrong.");
            } //HttpContext.Current is set to null again.
        }
Example #4
0
        private static void SimulateHttpRequest(Action <JsonPacket> test)
        {
            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Form1", "Value1")
                .SetCookie("Cookie1", "Value1")
                .SetHeader("Header1", "Value1")
                .SetReferer(new Uri("http://getsentry.com/"));

                using (simulator.SimulateRequest())
                {
                    var json = new JsonPacket(Guid.NewGuid().ToString("n"));
                    test.Invoke(json);
                }
            }
        }
Example #5
0
        public void TestHttpHandlerWritesCorrectResponse()
        {
            using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\"))
            {
                simulator.SetFormVariable("username", "phil")
                .SetReferer(new Uri("http://example.com/1/"))
                .SimulateRequest(new Uri("http://localhost/MyHandler.ashx?id=1234"));

                TestHttpHandler handler = new TestHttpHandler();
                handler.ProcessRequest(HttpContext.Current);
                HttpContext.Current.Response.Flush();

                string expected = @"c:\inetpub\MyHandler.ashx:phil:1234:http://example.com/1/";
                Assert.AreEqual(expected, simulator.ResponseText, "The Expected Response is all wrong.");
            } //HttpContext.Current is set to null again.
        }
        private static void SimulateHttpRequest(Action <JsonPacket> test, string username = null)
        {
            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Form1", "Value1")
                .SetCookie("Cookie1", "Value1")
                .SetHeader("Header1", "Value1")
                .SetReferer(new Uri("http://getsentry.com/"));

                using (simulator.SimulateRequest())
                {
                    if (username != null)
                    {
                        SetUsername(username);
                    }
                    var json = new JsonPacket(Guid.NewGuid().ToString("n"));
                    json.User    = userFactory.Create();
                    json.Request = requestFactory.Create();
                    test.Invoke(json);
                }
            }
        }
       // //[Test]
        public void CanSimulateFormPost()
        {
            using (var simulator = new HttpSimulator())
            {
                var form = new NameValueCollection {{"Test1", "Value1"}, {"Test2", "Value2"}};
                simulator.SimulateRequest(new Uri("http://localhost/Test.aspx"), form);

                Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]);
                Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]);
            }

            using (var simulator = new HttpSimulator())
            {
                simulator.SetFormVariable("Test1", "Value1")
                    .SetFormVariable("Test2", "Value2")
                    .SimulateRequest(new Uri("http://localhost/Test.aspx"));

                Assert.AreEqual("Value1", HttpContext.Current.Request.Form["Test1"]);
                Assert.AreEqual("Value2", HttpContext.Current.Request.Form["Test2"]);
            }
        }