Ejemplo n.º 1
0
        public void Set_MakesContextAvailableInsideScope()
        {
            Assert.That(HttpContext.Current, Is.Null, "we are outside a web application");

            using (HttpContextReseter.Set(new HttpContextBuilder()))
            {
                Assert.That(HttpContext.Current, Is.Not.Null, "as if we were inside a limited web application");
            }

            Assert.That(HttpContext.Current, Is.Null, "outside again :-(");
        }
Ejemplo n.º 2
0
        public void HttpContextBuilder_CanBeUsedToTest_ControlsThatUseTheContext()
        {
            StringBuilder  sb      = new StringBuilder();
            HtmlTextWriter writer  = new HtmlTextWriter(new StringWriter(sb));
            var            subject = new DisplayNameLiteral();

            using (HttpContextReseter.Set(new HttpContextBuilder()
                                          .AddToSession("name", "Daniel")
                                          .AddToSession("surname", "Gonzalez")))
            {
                ControlLifecycle.Fake(subject, c => c.PreRender += null, EventArgs.Empty);

                subject.RenderControl(writer);

                Assert.That(sb.ToString(), Is.EqualTo("Gonzalez, Daniel"));
            }
        }