testing - How to test HttpApplication Object with HttpApplicationState -
I am trying to test a 'plugin' for an asp.net HTTP application that is Application_Start < / Code>.
The code is something like this:
Private HTTP application application; Public Zero Application_Start (Object Sender, EventArgs e) {this.application = HttpApplication as Sender; StartReportService (); } Private Zero StartReportService () {Handlersports = New Sort List & lt; String, string & gt; (); HandledReports.Add ("myindex", "myvalue"); } Public System Selection. Generic In short, & lt; String, string & gt; HandledReports {get {application.application.Lock (); Var handledReports = (sorted list & lt; string, string & gt;) application. Application ["Handled Reports"]; Application.Application.UnLock (); Returns handled; } Set {application.Application.Lock (); application. Application ["handoverports"] = value; Application.Application.UnLock (); }}
The problem is that I can not find a good way to test HttpApplicationState
mainly because the HttpApplication.Application
property It does not appear in the hyperbolic and HttpApplicationBase
class System.Web.Abstructions
. This will allow.
I have tried to make changes for my every time I have always been walking in a road block.
Can any light shed some light on me? This is the first test of more that will depend on the ability of HttpApplicationState to work.
With some careful thought and a little reflection :), Came for:
[TestMethod ()] Public Zero StartReportService_ApplicationStateShouldContainMyIndex () {HttpApplicationPlugin plugin = Zero; Http application app = null; HttpApplicationState applicationState = null; String tempDir = ""; Try # {#region} "Create HttpApplication and ApplicationState" // In an HttpApplicationBase system. Web.Abstructions, the actual object should use the application = new HttpApplication (); // Get the real one if not the creative hack personal constructor var ctor = typeof (HttpApplicationState). GETConstructor (BindingFlags.Instance | BindingFlags.NonPublic, null, new type [] {}, new parameter code [] {}); ApplicationState = (HTTPPTCTT) ctor.Invoke (new object [] {}); // State status hack, prop = typef (HTPAPication) for testing various state .Getfield ("_State", Binding Flex.Instance | BendingFlag Nonpolic); StateProp.SetValue (app, applicationstate); #endregion Plugin = HttpApplicationPlugin.HttpApplicationPluginInstance; Plugin.Application_Start (application.Object, tap); You can basically use a reflection to give a htmlPAPTiteration
object with a HTTPPTIFICATION
object, which can be used for testing code blocks That would be enough for those who believe it.
Comments
Post a Comment