public void CanGetLocalPathCorrectly(string url, string appPath, string expectedLocalPath) { HttpSimulator simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\AppPath\"); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Path); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Url.LocalPath); }
/// <summary> /// Set Post parameters /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void SetFormParameters(string key, string value) { if (simulator == null) simulator = new HttpSimulator("/", AppDomain.CurrentDomain.BaseDirectory).SimulateRequest(); simulator.SetFormVariable(key, value); }
public void TestCookie() { const string CookieName = "ASP.NET_SessionId"; var configurationSection = new MaskedValuesConfigurationSection(); configurationSection.RemoveAspxAuth = false; configurationSection.ReplacementText = "OBSCURED"; configurationSection.Cookies.Add(new MaskedItemElement(CookieName)); using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\")) { simulator.SetCookies(Cookies) .SimulateRequest(new Uri("http://localhost/")); var error = new Error(new HttpRequestValidationException(), HttpContext.Current); Assert.IsNotNull(HttpContext.Current.Request.Cookies[CookieName]); ErrorHelper.Obscure(error, configurationSection); Assert.AreEqual(configurationSection.ReplacementText, error.Cookies[CookieName]); Assert.AreNotEqual(configurationSection.ReplacementText, error.Cookies[MaskedValuesConfigurationSection.AspxAuthCookie]); } }
public void Setup() { var autoSubstitute = AutoSubstituteContainer.Create(); _context = autoSubstitute.Resolve<ControllerContext>(); _filterProvider = new FilterProvider(); DependencyResolver.SetResolver(new AutofacDependencyResolver(autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); }
public void Setup() { _autoSubstitute = AutoSubstituteContainer.Create(); _context = _autoSubstitute.Resolve<ControllerContext>(); DependencyResolver.SetResolver(new AutofacDependencyResolver(_autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); _form = _context.HttpContext.Request.Form; }
public void Setup() { _autoSubstitute = AutoSubstituteContainer.Create(); _context = _autoSubstitute.Resolve<ControllerContext>(); _lookup = _autoSubstitute.Resolve<ICurtinUserService>(); DependencyResolver.SetResolver(new AutofacDependencyResolver(_autoSubstitute.Container)); _httpSimulator = new HttpSimulator().SimulateRequest(); }
public void Notice_contains_Request() { AirbrakeNotice notice = null; const string url = "http://example.com/?Query.Key1=Query.Value1&Query.Key2=Query.Value2"; const string referer = "http://github.com/"; string physicalApplicationPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar; var httpSimulator = new HttpSimulator("/", physicalApplicationPath) .SetFormVariable("Form.Key1", "Form.Value1") .SetFormVariable("Form.Key2", "Form.Value2") .SetHeader("Header.Key1", "Header.Value1") .SetHeader("Header.Key2", "Header.Value2") .SetReferer(new Uri(referer)) .SimulateRequest(new Uri(url)); using (httpSimulator) { try { Thrower.Throw(new Exception("Halp!")); } catch (Exception exception) { AirbrakeError error = this.builder.ErrorFromException(exception); notice = this.builder.Notice(error); } } Console.WriteLine(CleanXmlSerializer.ToXml(notice)); Assert.That(notice, Is.Not.Null); Assert.That(notice.Error, Is.Not.Null); #if !NET35 // We have defined a NET35 constant in the Visual Studio 2008 project so the below code isn't executed, // since it requires HttpSimulator which in turn requires .NET 4.0, which in turn requires Visual Studio 2010. Assert.That(notice.Request, Is.Not.Null); Assert.That(notice.Request.Url, Is.EqualTo(url)); Assert.That(notice.Request.Component, Is.EqualTo(GetType().FullName)); Assert.That(notice.Request.Action, Is.EqualTo("Notice_contains_Request")); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Content-Type", "application/x-www-form-urlencoded"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key1", "Header.Value1"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key2", "Header.Value2"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Referer", referer))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("APPL_PHYSICAL_PATH", physicalApplicationPath))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("QUERY_STRING", "Query.Key1=Query.Value1&Query.Key2=Query.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key1", "Form.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key2", "Form.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key1", "Query.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key2", "Query.Value2"))); #endif }
public void SetUp() { HttpSimulator = new HttpSimulator().SimulateRequest(); Logger = DependencyResolver.Current.GetService<ILog>(); DaoFactory = DependencyResolver.Current.GetService<IDaoFactory>(); Session = DependencyResolver.Current.GetService<ISession>(); ManagerFactory = DependencyResolver.Current.GetService<IManagerFactory>(); }
public void CanDispose() { using (HttpSimulator simulator = new HttpSimulator()) { simulator.SimulateRequest(); Assert.IsNotNull(HttpContext.Current); } Assert.IsNull(HttpContext.Current); }
public void CanGetReferer() { HttpSimulator simulator = new HttpSimulator(); simulator.SetReferer(new Uri("http://example.com/Blah.aspx")).SimulateRequest(); Assert.AreEqual(new Uri("http://example.com/Blah.aspx"), HttpContext.Current.Request.UrlReferrer); simulator = new HttpSimulator(); simulator.SimulateRequest().SetReferer(new Uri("http://x.example.com/Blah.aspx")); Assert.AreEqual(new Uri("http://x.example.com/Blah.aspx"), HttpContext.Current.Request.UrlReferrer); }
public void NoticeContainsRequest() { AirbrakeNotice notice = null; const string url = "http://example.com/?Query.Key1=Query.Value1&Query.Key2=Query.Value2"; const string referer = "http://github.com/"; string physicalApplicationPath = Environment.CurrentDirectory + Path.DirectorySeparatorChar; var httpSimulator = new HttpSimulator("/", physicalApplicationPath) .SetFormVariable("Form.Key1", "Form.Value1") .SetFormVariable("Form.Key2", "Form.Value2") .SetHeader("Header.Key1", "Header.Value1") .SetHeader("Header.Key2", "Header.Value2") .SetReferer(new Uri(referer)) .SimulateRequest(new Uri(url)); using (httpSimulator) { try { Thrower.Throw(new Exception("Halp!")); } catch (Exception exception) { notice = _builder.BuildNotice(_builder.ErrorFromException(exception)); } } Console.WriteLine(CleanXmlSerializer.ToXml(notice)); Assert.IsNotNull(notice); Assert.IsNotNull(notice.Error); Assert.IsNotNull(notice.Request); Assert.AreEqual(notice.Request.Url, url); Assert.AreEqual(notice.Request.Component, (typeof(Thrower).FullName)); Assert.AreEqual(notice.Request.Action, "Throw"); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Content-Type", "application/x-www-form-urlencoded"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key1", "Header.Value1"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Header.Key2", "Header.Value2"))); Assert.That(notice.Request.CgiData, Contains.Item(new AirbrakeVar("Referer", referer))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("APPL_PHYSICAL_PATH", physicalApplicationPath))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("QUERY_STRING", "Query.Key1=Query.Value1&Query.Key2=Query.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key1", "Form.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Form.Key2", "Form.Value2"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key1", "Query.Value1"))); Assert.That(notice.Request.Params, Contains.Item(new AirbrakeVar("Query.Key2", "Query.Value2"))); }
public void TestFixtureSetUp() { using (var httpSimulator = new HttpSimulator().SimulateRequest()) { // Initialize AutoMapper and AutoFac. Streamus.InitializeApplication(); Logger = DependencyResolver.Current.GetService<ILog>(); DaoFactory = DependencyResolver.Current.GetService<IDaoFactory>(); Session = DependencyResolver.Current.GetService<ISession>(); ManagerFactory = DependencyResolver.Current.GetService<IManagerFactory>(); } Helpers = new Helpers(ManagerFactory); }
public void TestAspxAuth() { var configurationSection = new MaskedValuesConfigurationSection(); configurationSection.RemoveAspxAuth = true; configurationSection.ReplacementText = "OBSCURED"; using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\")) { simulator.SetCookies(Cookies) .SimulateRequest(new Uri("http://localhost/")); var error = new Error(new HttpRequestValidationException(), HttpContext.Current); ErrorHelper.Obscure(error, configurationSection); Assert.AreEqual(configurationSection.ReplacementText, error.Cookies[MaskedValuesConfigurationSection.AspxAuthCookie]); } }
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 CanGetQueryString() { HttpSimulator simulator = new HttpSimulator(); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=value1¶m2=value2¶m3=value3")); for (int i = 1; i <= 3; i++) Assert.AreEqual("value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param1=new-value1¶m2=new-value2¶m3=new-value3¶m4=new-value4")); for (int i = 1; i <= 4; i++) Assert.AreEqual("new-value" + i, HttpContext.Current.Request.QueryString["param" + i], "Could not find query string field 'param{0}'", i); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx")); Assert.AreEqual(string.Empty, HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(0, HttpContext.Current.Request.QueryString.Count); simulator.SimulateRequest(new Uri("http://localhost/Test.aspx?param-name")); Assert.AreEqual("param-name", HttpContext.Current.Request.QueryString.ToString()); Assert.AreEqual(1, HttpContext.Current.Request.QueryString.Count); Assert.IsNull(HttpContext.Current.Request.QueryString["param-name"]); }
public ConfigMapPath(HttpSimulator simulation) { _requestSimulation = simulation; }
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."); } }
/// <summary> /// Set the request Uri /// </summary> /// <param name="uri"></param> public void SetRequestUrl(string uri) { if (simulator == null) simulator = new HttpSimulator("/", AppDomain.CurrentDomain.BaseDirectory).SimulateRequest(new Uri(localUri + uri)); else simulator.SimulateRequest(new Uri(localUri + uri)); }
public void Users() { using (var httpSimulator = new HttpSimulator()) { httpSimulator.SimulateRequest(); AccountController controller = new AccountController(DependencyResolver.Current.GetService<IQueryBuilder>()); ViewResult result = controller.Users() as ViewResult; Assert.IsInstanceOfType(result.Model, typeof(IEnumerable<User>)); var users = result.Model as IEnumerable<User>; Assert.AreEqual(users.Count(), _users.Count()); Assert.AreEqual(users.First().Id, 1); Assert.AreEqual(users.Last().Id, 10); } }
/// <summary> /// Determines whether this instance [can set app physical path correctly] the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="appPath">The app path.</param> /// <param name="appPhysicalPath">The app physical path.</param> /// <param name="expectedPhysicalAppPath">The expected physical app path.</param> /// <param name="expectedPhysicalPath">The expected physical path.</param> public void CanSetAppPhysicalPathCorrectly(string url, string appPath, string appPhysicalPath, string expectedPhysicalAppPath, string expectedPhysicalPath) { var simulator = new HttpSimulator(appPath, appPhysicalPath); Assert.AreEqual(expectedPhysicalAppPath, simulator.PhysicalApplicationPath); simulator.SimulateRequest(new Uri(url), HttpVerb.GET); Assert.AreEqual(expectedPhysicalPath, simulator.PhysicalPath); Assert.AreEqual(expectedPhysicalAppPath, HttpRuntime.AppDomainAppPath); Assert.AreEqual(expectedPhysicalAppPath, HostingEnvironment.ApplicationPhysicalPath); Assert.AreEqual(expectedPhysicalPath, HttpContext.Current.Request.PhysicalPath); }
/// <summary> /// Determines whether this instance [can set application path correctly] the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="appPath">The app path.</param> /// <param name="expectedAppPath">The expected app path.</param> public void CanSetApplicationPathCorrectly(string url, string appPath, string expectedAppPath) { var simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\site1\test"); Assert.AreEqual(expectedAppPath, simulator.ApplicationPath); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedAppPath, HttpContext.Current.Request.ApplicationPath); Assert.AreEqual(expectedAppPath, HttpRuntime.AppDomainAppVirtualPath); Assert.AreEqual(expectedAppPath, HostingEnvironment.ApplicationVirtualPath); }
/// <summary> /// /// </summary> /// <param name="key"></param> /// <param name="value"></param> public void SetSessionParaemeter(string key, object value) { if (simulator == null) simulator = new HttpSimulator("/", AppDomain.CurrentDomain.BaseDirectory).SimulateRequest(); HttpContext.Current.Session[key] = value; }
/// <summary> /// Determines whether this instance [can map path] the specified virtual path. /// </summary> /// <param name="virtualPath">The virtual path.</param> /// <param name="appPath">The app path.</param> /// <param name="expectedMapPath">The expected map path.</param> public void CanMapPath(string virtualPath, string appPath, string expectedMapPath) { var url = new Uri("http://localhost/Test/Test.aspx"); var simulator = new HttpSimulator(appPath, @"c:\inetpub\wwwroot\"); simulator.SimulateRequest(url); //Create a virtual path object. var vpath = ReflectionHelper.Instantiate("System.Web.VirtualPath, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", new[] { typeof(string) }, virtualPath); Assert.IsNotNull(vpath); var environment = HttpSimulatorTester.CallGetEnvironment(); var vpathString = ReflectionHelper.InvokeProperty<string>(vpath, "VirtualPathString"); var appVirtPath = ReflectionHelper.GetPrivateInstanceFieldValue<object>("_appVirtualPath", environment); Assert.IsNotNull(appVirtPath); Console.WriteLine("VPATH: " + vpath); Console.WriteLine("App-VPATH: " + appVirtPath); Console.WriteLine("vpath.VirtualPathString == '{0}'", vpathString); var mapping = ReflectionHelper.InvokeNonPublicMethod<string>(typeof(HostingEnvironment), "GetVirtualPathToFileMapping", vpath); Console.WriteLine("GetVirtualPathToFileMapping: --->{0}<---", (mapping ?? "{NULL}")); var o = ReflectionHelper.GetPrivateInstanceFieldValue<object>("_configMapPath", environment); Console.WriteLine("_configMapPath: {0}", o ?? "{null}"); var mappedPath = ReflectionHelper.InvokeNonPublicMethod<string>(environment, "MapPathActual", vpath, false); Console.WriteLine("MAPPED: " + mappedPath); Assert.AreEqual(expectedMapPath, HttpContext.Current.Request.MapPath(virtualPath)); }
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"]); } }
/// <summary> /// /// </summary> public HttpEnvironment() { simulator = new HttpSimulator("/", AppDomain.CurrentDomain.BaseDirectory).SimulateRequest(); }
public void CanGetResponse() { var simulator = new HttpSimulator(); simulator.SimulateRequest(); HttpContext.Current.Response.Write("Hello World!"); HttpContext.Current.Response.Flush(); Assert.AreEqual("Hello World!", simulator.ResponseText); }
/// <summary> /// Determines whether this instance [can parse request URL] the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="appPath">The app path.</param> /// <param name="physicalPath">The physical path.</param> /// <param name="expectedHost">The expected host.</param> /// <param name="expectedPort">The expected port.</param> /// <param name="expectedAppPath">The expected app path.</param> /// <param name="expectedPage">The expected page.</param> /// <param name="expectedAppDomainAppPath">The expected app domain app path.</param> public void CanParseRequestUrl(string url, string appPath, string physicalPath, string expectedHost, int expectedPort, string expectedAppPath, string expectedPage, string expectedAppDomainAppPath) { var simulator = new HttpSimulator(appPath, physicalPath); Assert.AreEqual(expectedAppPath, simulator.ApplicationPath); Assert.AreEqual(expectedAppDomainAppPath, simulator.PhysicalApplicationPath); }
public void FormValueDoesNotExistTest() { const string FormValue = "RandomFormValue"; var configurationSection = new MaskedValuesConfigurationSection(); configurationSection.RemoveAspxAuth = false; configurationSection.ReplacementText = "OBSCURED"; configurationSection.FormVariables.Add(new MaskedItemElement(FormValue)); using (HttpSimulator simulator = new HttpSimulator("/", @"c:\inetpub\")) { simulator.SimulateRequest(new Uri("http://localhost/"), HttpVerb.GET); var error = new Error(new HttpRequestValidationException(), HttpContext.Current); Assert.IsNull(error.Form[FormValue]); } }
/// <summary> /// Determines whether this instance [can simulate request] the specified URL. /// </summary> /// <param name="url">The URL.</param> /// <param name="appPath">The app path.</param> /// <param name="physicalPath">The physical path.</param> /// <param name="expectedHost">The expected host.</param> /// <param name="expectedPort">The expected port.</param> /// <param name="expectedAppPath">The expected app path.</param> /// <param name="expectedLocalPath">The expected local path.</param> /// <param name="expectedPhysicalPath">The expected physical path.</param> public void CanSimulateRequest(string url, string appPath, string physicalPath, string expectedHost, int expectedPort, string expectedAppPath, string expectedLocalPath, string expectedPhysicalPath) { var simulator = new HttpSimulator(appPath, physicalPath); simulator.SimulateRequest(new Uri(url)); Assert.AreEqual(expectedHost, HttpContext.Current.Request.Url.Host); Assert.AreEqual(expectedPort, HttpContext.Current.Request.Url.Port); Assert.AreEqual(expectedAppPath, HttpContext.Current.Request.ApplicationPath); Assert.AreEqual(expectedPhysicalPath, HttpContext.Current.Request.PhysicalApplicationPath); Assert.AreEqual(expectedLocalPath, HttpContext.Current.Request.Url.LocalPath); }
public void ScenarioSetup() { _httpSimulator = new HttpSimulator().SimulateRequest(); Scope = new TransactionScope(TransactionScopeOption.RequiresNew); }