public SetFormVariable ( string name, string value ) : |
||
name | string | |
value | string | |
return |
public void TestFormVariable() { const string FormVariable = "Username"; var configurationSection = new MaskedValuesConfigurationSection(); configurationSection.RemoveAspxAuth = false; configurationSection.ReplacementText = "OBSCURED"; configurationSection.FormVariables.Add(new MaskedItemElement(FormVariable)); using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\")) { simulator.SetFormVariable(FormVariable, "Admin").SimulateRequest(new Uri("http://localhost/")); var error = new Error(new HttpRequestValidationException(), HttpContext.Current); Assert.IsNotNull(HttpContext.Current.Request.Form[FormVariable]); ErrorHelper.Obscure(error, configurationSection); Assert.AreEqual(configurationSection.ReplacementText, error.Form[FormVariable]); } }
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."); } }
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"]); } }