Nov
22
2011

Tool for working with .NET config file transforms

Check out this great tool for working with .NET config file transforms

http://www.hanselman.com/blog/SlowCheetahWebconfigTransformationSyntaxNowGeneralizedForAnyXMLConfigurationFile.aspx

Nov
22
2011

Multiple app.config files (just like web.config files)

Good article from stackoverflow

http://stackoverflow.com/questions/3004210/app-config-transformation-for-projects-which-are-not-web-projects-in-visual-stud

Great article from:

http://www.olegsych.com/2010/12/config-file-transformation/

----

 

Nov
2
2011

ASP.NET HttpModule Event Life cycle

MSDN Article: http://msdn.microsoft.com/en-us/library/ms178473(v=VS.80).aspx

 

In my recent quest to integrate support for SiteMinder into the ASP.NET Membership process I found myself looking into the details of ASP.NET Http Modules.  Once of the areas that I spent time on was understanding the exact order of events in the life cycle of a module.  Here is what I found.

The HttpApplication is usually un-heard of and it works quietly behind the scenes - well not really. If you have written a HttpHandler or HttpModule or any application with some sort of complexity before - you probably already know what its all about. The HttpApplication is the base class for all ASP.NET application objects, therefore, an HttpApplication class is created for each request. However, not to get too deep into the world of the HttpApplication, I want to focus this post on the sequence of events that are executed - its pipeline.

  1. BeginRequest
  2. AuthenticateRequest
  3. PostAuthenticateRequest
  4. AuthorizeRequest
  5. PostAuthorizeRequest
  6. ResolveRequestCache
  7. PostResolveRequestCache
  8. PostMapRequestHandler
  9. AcquireRequestState
  10. PostAcquireRequestState
  11. PreRequestHandlerExecute
  12. PostRequestHandlerExecute
  13. ReleaseRequestState
  14. PostReleaseRequestState
  15. UpdateRequestCache
  16. PostUpdateRequestCache
  17. EndRequest

Any HTTP module that subscribes to an HttpApplication event must implement the IHttpModule interface, also if you look at the list you will notice that each event has a corresponding post event. i.e AuthenticateRequest to PostAuthenticateRequest. These posts events are executed after its parent event has completed, therefore, PostAuthenticateRequest is raised after the AuthenticateRequest.

BeginRequest
This is the very first event that is raised when ASP.NET responds to a request and it is always raised. Listen to this event for new requests.

AuthenticateRequest
As the name implies, this event fires on authentication of the user. Therefore, if you would like to know who is accessing your site, the "Post" of this event would be ideal to set a listener. It simply states that the request has been authenticated or the identity of the user has been established.

AuthorizeRequest
Authorizing the request is the next step right after the request has been authenticated. Trap "Post" of this event to determine if the user is authorized to access the particular resource or not.

ResolveRequestCache
Ok, it gets tricky. This event occurs after the authorize event and data is requested from cache. If the cache exist, the event handler such as a page will be bypassed and the cached request will be served. You can do several things here. Blow your mind!

PostMapRequestHandler
A post event with no "Pre" - at least no access to it. This event get raised after the request has been mapped to a handler. So if you would like to know which handler will be executed, this is the place to be.

AcquireRequestState
This executes right after the handler has been mapped to the request and it grabs the current state such as session state. Trap the "Post" event if you need to mess around with the session.

PreRequestHandlerExecute
As the name implies, this event is raised just before the request handler that was mapped earlier on is executed such as a ".aspx" or ".asmx" page.

ReleaseRequestState
At this point in time all mapped handlers have been executed and state modules will start saving state data as required.

UpdateRequestCache
Completely opposite off the above, this event is raised to signal caching modules to save response data which may be used in future request during the ResolveRequestCache phase.

EndRequest
It has to end somewhere. The EndRequest is the last event raised.

I hope this post has helped you understand how the HttpApplication pipeline flows and also help you understand which events to trap to enable you to perform some tasks at the right time.

Apr
1
2011

How to test jQuery enabled Apps using JSON with Visual Studio

Note: This artcile is a repost of one written by Andreas Grabner -- all credit goes to him for his excellent artcile

Visual Studio Team System offers a nice Web- and Load-Testing Feature that allows you to easily create tests to verify your web application’s functionality as well as verifying how it performs under load. Web Applications that make use of AJAX Frameworks likejQuery execute additonal web requests to request information from the Web Server without causing the browser to reload the complete page. JSON is one of the formats that is used to exchange information between the Web Server and the AJAX Framework running in the browser.

Challenges with AJAX in Web- and Load-Testing

Asynchronous calls executed by AJAX frameworks can be very hard to deal with for web- and loadtesting tools? Why? Because those requests can most often not easily be correlated to a Page Request done by the browser and therefore its not easy to create a nice script that shows the sequential logic of all user interactions.
The next problem with AJAX requests is that its hard to verify if the simulated request produced the correct result and whether the result of one request needs to feed a subsequent request. An example for this would be a login call that returns a user id. This user id needs to be used for subsequent calls. If the testing tool doesn’t understand JSON and is not able to automatically detect the dependency between those calls its up to the test engineer to add parsing statements for the first call and use the parsed value in subsequent calls.

How to test JSON with Visual Studio?

I’ve downloaded the following ASP.NET MVC Sample App (KIGG) that uses jQuery and JSON. My task was to create a web script with Visual Studio that creates new user accounts. In order to do that a user needs to sign on to the page with username, password and email. The user account can then be activated by following an activation link that is sent via email.

Necessary steps for the Test Script

  • Execute the request to sign up a new user by providing username, password and email
  • Get the information about the activation link
  • Execute the request to activate the user account

The default procedure for the activation uses an email that is sent out. As I didn’t want to bother with email during my web testing I extended the JSON message that is returned when signing up a new account to include the information about the activation link. Having that information as part of the response allows me to finish all the steps.

How to deal with JSON messages?

Here is the JSON message that is responded by the user signup request:

{"isSuccessful":true,"userId":"9JU51KDxp0-3Llw1BU2h7w","errorMessage":null}

 

The userId is the value that I am interested in. This is the value I need to use to call the Activate page. Another interesting value is the isSuccessful property. This allows me to add additional logic to my web script. I can verify if the sign-up request was successful. In order to do all this I need to extend Visual Studio Web Testing by writing my own Extraction andValidation Rule. Visual Studio offers an interface to provide custom implementations for value parsing and validation. Here is my implementation for the ExtractorRule using a helper class that parses the JSon string:

 

public override void Extract(object sender, Microsoft.VisualStudio.TestTools.WebTesting.ExtractionEventArgs e) {
  NameValueCollection jsonProperties = JSonHelper.ParseJSonString(e.Response.BodyString);
  string propertyValue = jsonProperties.Get(JSonPropertyName);
  if (propertyValue != null) {
    e.WebTest.Context.Add(ContextParameterName, propertyValue);
    e.Success = true;
  } else
    e.Success = false;
}

 

In a similar way I implemented the ValidationRule. Using it all in my web test allows me to specify the Extractor and Validation Rule in my web test.


 

Conclusion

With Visual Studios extensibility mechanisms its easy to build support for those emerging technologies like jQuery and JSON. Let me know if you need the library that implements the two extension Rules.

 

Apr
1
2011

Randomizing Input Data for Visual Studio Load Tests

Note: This artcile is a repost of one written by Andreas Grabner -- all credit goes to him for his excellent artcile

While preparing for my presentation Load and Performance Testing: How to do Transactional Root-Cause Analysis with Visual Studio Team System for Testers that I gave at the Boston .NET User Group on May 13th I came across certain load-testing topics. One was: How to randomize Input Data.

If you go with Visual Studio you can code your web tests in any .NET Language giving you the freedom to create random data by using e.g.: System.Random. If you however want to use the “nicer” UI Driven Web Test Development (that’s how I call it) – you are limited in your options. You add web requests – you can parameterize input values by using Context Parameters with hard coded values, you can reuse values extracted from a previous request or you can use data from an external data source like a database, CSV or XML file.

Basic random numbers for VSTS Web Tests

One thing that I missed was the ability to use basic random values, e.g.: a random number from 1 to 5 that would be used for a quantity field of a web form or a random username with the pattern “testuserX” where X is in the range of my test user accounts.

In order to do that there only seems to be one way – implementing a WebTest or WebTestRequest Plugin that generates random data and makes it available as Context Parameter to the test.

Sample: Randomizing username and password

Lets get back to my username/password example. Following illustration shows my original Web Test:

 

 

Hard Coded values for Username and Password

I extracted the hard coded values from the recorded web request into a context parameter – but still using the hard coded values. One option that I would have here – as indicated in the first paragraph – would be to make this test data driven by binding the Context Parameters to an external data source. But this is not what I want in my example. I really want to randomize the input data so that every web request uses a new random value. I therefore created a WebTestRequestPlugin as shown in the following image:

 

 

 

 

Random Parameter WebTest Request Plugin

My plugin defines two properties that can be configured with a Parameter Name (or names) and a random value pattern. In the PreRequest override I use a random value generator that generates the random value based on the passed pattern and put the generated value in the Test Context.

Now I can use the plugin in my webtest as follows:

 

 

 

Randomize Context Parameters with Request Plugin

Now I can run my Web Test either “standalone” by defining the number of iterations or using it in a Load Test. Every time the WebRequest will be executed the WebTestRequestPlugin will create a new random value that will then be used by the request. This allows me to run this test over and over again – always using a different username and password.

Conclusion

Check out the option to create your own WebTestRequestPlugin or WebTestPlugin. This extension option gives you more flexibility when creating web tests for Visual Studio.

 

Feb
11
2011

Debugging and Error handling in SharePoint (or other complex ASP.NET applications)

http://sharepointexception.wordpress.com/

http://blogs.msdn.com/b/jannemattila/archive/2008/02/23/crm-4-0-sharepoint-and-asp-net-trace.aspx

http://blog.thekid.me.uk/archive/2007/07/25/debugging-tips-for-sharepoint-and-wss-exceptions.aspx

http://www.codeproject.com/KB/sharepoint/Handling_Error_Centrally.aspx

Jan
18
2011

Thoughts on performance improvements for JS and CSS files

I have been continuing some research on how to help improve our performance.  The first area I have been looking into have been around our CSS and JS libraries.  I thought I would share what looks to be the most promising options so far and start a conversation around them and other ideas.

 

Ideas/Tools

·         JavaScript

o   Compress existing JS files to reduce download

§  Yahoo seems to have the #1 tool out there and it is command line driven so it would be easy for us to automate it’s usage

·         http://developer.yahoo.com/yui/compressor/

o   Combine JS files into single file

§  We can use a feature built into ASP.NET to do this for us I think – it is a feature of the ScriptManager class

·         http://msdn.microsoft.com/en-us/library/cc488552.aspx

§  If this doesn’t work, here is a great JS compressor and combiner (also works with CSS)

·         http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki

·         CSS

o   Compress existing CSS files to reduce download time

§  Same Yahoo tool for JS will work on CSS

o   Combine CSS into single file

§  ASP.NET control for CSS that is just like the ScriptManager

·         http://gstylemanager.com/

§  Command line tools

·         http://cssmixer.codeplex.com/

·         http://csstidy.sourceforge.net/index.php

·         http://svn.offwhite.net/trac/SmallSharpTools.Packer/wiki

·         http://code.google.com/p/cssmerge/

 

Right now I like the ideas of the ScriptManager and StyleManager as these would require the least amount of work to implement and have the largest benefit (the compress and cache).  The main concern I have is that the ScriptManager may not play well with our JQuery code base – so we need to make sure we test carefully.  If it turns out these will not work, the Yahoo tool followed by the SmallSharpTools package looks to be our next best options based on what I have found so far.

Dec
23
2010

Looking for a great tool for Web UI Testing?

Check out http://seleniumhq.org/

 

Selenium is a suite of toolsto automate web app testing across many platforms.

Selenium...

Oct
25
2010

ASP.NET Page Life Cycle Diagram

Post from here
The following diagram shows some of the most important methods of theSystem.Web.UI.Page class that you can override in order to add code that executes at specific points in the page life cycle.  It also shows how these methods relate to page events and control events.
A preliminary version of the diagram was added to the ASP.NET 4 Beta 2 page life cycle documentation on MSDN. The updated diagram that is shown below will appear on that page when ASP.NET 4 is released.
 
Comments and suggestions about how to improve the diagram are welcome. It is shown here smaller than actual size in order to fit within the horizontal size limitations of this blog.
 -- Tom Dykstra
ASP.NET User Education
This posting is provided "AS IS" with no warranties, and confers no rights.
 
 
ASP.NET Page Life Cycle diagram
 
Oct
3
2010

ASP.NET Master Page Tips and Tricks

http://odetocode.com/Articles/450.aspx