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.

"testprint-override"> TestMethod ()] Public Zero Start Report Service_Application StatusContainMayIndex () {// System does not have the HTPPBasebasebase. .Eststation should use real object version of application = new fake & lt; HttpApplication & gt; (); // The real object is not the property of the HttpApplicationStateBase type, so should the real use? // var applicationstatbase = new mask & lt; HTTPEpplication Statebase & gt; (); / / Get real hacker private constructor var ctor = typeof (HTTPPTC State) so that no real one is creable. GETConstructor (BindingFlags.Instance | BindingFlags.NonPublic, Zero, New Type [] {}, New ParameterMonifier [] {}); Var applicationState = (HTTPPCTCT) ctor.Invoke (new object [] {}); / / Here fails, httpPeople The application is not an overridive application. Setupprotect (X => X. Application, ApplicationState); Var plugin = HTType plugin Hpaproductionplugin instance; Plugin.Application_Start (application.Object, tap); ... evaluation of results ...}

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

Popular posts from this blog

c# - ListView onScroll event -

PHP - get image from byte array -

Linux Terminal Problem with Non-Canonical Terminal I/O app -