How do I convert a Web Site to a Web Application

by Donovan Brown 31. January 2013 01:41

Problem:

We created our application using the Web Site project template and would like to change to a Web Application.

Solution:

http://msdn.microsoft.com/en-us/library/aa983476(v=vs.100).aspx

Explanation:

Just don't use Web Sites! Why would I want my source code (all of my IP) on a server that could be compromised? They also do not play nice with source control systrems or automated build.

Tags: , ,

Work

I can't connect to my load test repository.

by Donovan Brown 7. December 2012 02:56

Problem:

When I try to Open and Manage Results from my load test I get an error:

Solution:

Make sure your controller is configured with the full name to the database server instead of . or .\sqlexpress.  Change to mySqlServer or mySqlServer\sqlExpress.

Tags: , , , ,

Work

My web test data source is not loading all the columns from my csv file.

by Donovan Brown 5. December 2012 20:06

Problem:

I have a data driven web test that calls other web test. The called web tests are also data bound to data loaded by the parent data source.  When I run my test I was getting the following error:

Request failed: Context parameter 'FluidManagement.FluidManagement_json#csv.spacer2' not found in test context

Solution:

Expand the Data Sources node of your web test until you can select the desired table.  From the Properties window change the Select Columns from “Only select bound columns” to “Select all columns”.

Explanation:

The default behavior is to only select the columns that are bound the web test that defines the data source.  This is a reasonable assumption as long as the test does not call any other data bound web test.  If the test you call rely on columns that are not bound in the caller you must change the Select Columns setting.

Tags: , , , ,

Work

How do I reset my Visual Studio Settings

by Donovan Brown 4. December 2012 23:12

Problem:

I selected the wrong language when I started Visual Studio for the first time.

Solution:

From the Tools menu select Import and Export Settings.... From the Import and Export Settings Wizard select Reset all settings.  Complete the wizard to reset your settings.

Tags: ,

Work

Custom Action causes install to fail

by Donovan Brown 27. December 2011 03:25

Problem:

I get “Could not find file *.InstallState” when using a custom action in Windows Setup Project.

Solution:

Override Install, Commit, Rollback, and Uninstall methods.

Explanation:

You will get this method if you don’t implement Install action. In my case I only implemented the Commit method.  Once I implemented the other methods my error went away.

Tags: , ,

Work

How to mole System.dll

by Donovan Brown 15. December 2011 14:07

Problem:

I get “no suitable method found to override” errors when I mole system.dll.

Solution:

Modify the System.moles file in your project and exclude everything except the types you are trying to mole.

Explanation:

I was trying to mole the SerialPort class in System.IO.Ports. After adding the mole for System.dll I began to get “no suitable method found to override” errors.  To resolve this issue I simply double clicked the System.moles file to open it in my IDE.  Then I modified the file so that moles were created only for the types under System.IO.  Change System.moles from this:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
  <Assembly Name="System" />
</Moles>

to this:

<Moles xmlns="http://schemas.microsoft.com/moles/2010/">
   <Assembly Name="System" />
   <StubGeneration>
      <Types>
         <Clear />
         <Add Namespace="System.IO!" />
      </Types>
   </StubGeneration>
</Moles>

Tags: , , ,

Work

Installing VSTS 2010 Beta 2 Test Controller in Workgroup

by Donovan Brown 24. November 2009 01:57

Problem:

I need to install VSTS 2010 Test Controller on my Dev machine in a Workgroup but my configuration fails.

Solution:

Be sure an install the Test Controller on your TFS server first and make sure the account you plan to use is in the groups mentioned here:

http://msdn.microsoft.com/en-us/library/dd648127(VS.100).aspx

Code:

N/A

Explanation:

After setting up TFS 2010 Beta2 I wanted to run the Test Controller on my physical Dev machine.  I am running workgroup edition and kept getting the following error when I tried to configure the Test Controller on my machine:

Failed to grant permission to controller service account on Tfs http://MyTfs:8080/tfs/DefaultCollection. Microsoft.VisualStudio.TestTools.ConfigCore.ConfigToolException: User account i7307\Donovan L Brown not found

Failed to update TFS Team Project Collection http://MyTfs:8080/tfs/DefaultCollection as the test controller service account could not be granted required permission. To fix this error, run this tool with an account that has "Project Collection Administrator" rights and try again.

Well the account I was using had the "Project Collection Administrator" rights.   I searched MSDN and found the following article that got me close but not the entire way. http://msdn.microsoft.com/en-us/library/dd648127(VS.100).aspx What that article did for me was have me start checking for the existence of the two groups mentioned in step 3 under Requirements for Workgroups.  When I return to my TFS server to check they were missing because I did not install the Test Controller there.  Once I installed the controller on my TFS server and made sure the user account I planned to use as in all the correct groups I was able to complete the configuration on my Dev machine.

Tags: ,

Work

Writing Custom Conditional Rule for Visual Studio 2010

by Donovan Brown 7. November 2009 13:39

Problem:

I have a portion of a web test I only want to run if a specific condition is true.

Solution:

Use the new Visual Studio 2010 Conditional Rule Feature.  However, the condition I wanted to test for was unable to be tested using the out of the box conditions. So in this posting I am going to show you how to write your own custom Condition Rule for Visual Studio 2010.

Code:

using System;
using System.ComponentModel;
using System.Text.RegularExpressions; 

namespace DLB
{
   [DisplayName("Find Text")]
   [Description("Searches the last response for the existence of the specified text.")]
   public class FindTextConditionalRule : Microsoft.VisualStudio.TestTools.WebTesting.ConditionalRule
   {
      [DisplayName("Find Text")]
      [Description("The text to search for in the last response of the web test.")]
      public string Value { get; set; } 

      [DisplayName("Ignore Case")]
      [Description("If true case is ignored while seaching for the string in the response.")]
      [DefaultValue(true)]
      public bool IgnoreCase { get; set; } 

      [DisplayName("Use Regular Expression")]
      [Description("Use a regular expression during search.")]
      public bool UseRegularExpression { get; set; } 

      [DisplayName("Pass If Text Found")]
      [Description("Condition passes if the text is found when this property is set true, or when the text is not found and this property is set false.")]
      [DefaultValue(true)]
      public bool PassIfNotFound { get; set; } 

      /// <summary>
      /// Determines whether the condition was met or not.
      /// </summary>
      /// <param name="sender">The sender of the event.</param>
      /// <param name="e">The Microsoft.VisualStudio.TestTools.WebTesting.ConditionalEventArgs that contains the event data.</param>
      public override void CheckCondition(object sender, Microsoft.VisualStudio.TestTools.WebTesting.ConditionalEventArgs e)
      {
         if(UseRegularExpression)
         {
            Match result = Regex.Match(e.WebTest.LastResponse.BodyString, Value, IgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None);
            e.IsMet = result.Success;
         }
         else
         {
            int index = e.WebTest.LastResponse.BodyString.IndexOf(Value, IgnoreCase ? StringComparison.CurrentCultureIgnoreCase : StringComparison.CurrentCulture);
            e.IsMet = index == -1 ? false : true;
         } 

         if(PassIfNotFound)
            e.IsMet = !e.IsMet;
      }
   }
}

Explanation:

 

To create a custom Conditional Rule simply create a public class that derives from Microsoft.VisualStudio.TestTools.WebTesting.ConditionalRule and override CheckCondition. This class can be added directly to your test project or a separate class library referenced by your test project.

From within the CheckCondition method set e.IsMet to true or false depending on if the condition was met. If e.IsMet is set to true all the request under this condition will be executed, otherwise, they will be skipped.

Once your test project has a reference to the conditional rule class it will be shown in the Add Conditional Rule and Items to Condition dialog.

 

Once the condition is added to your web test you will see the If statement with the selected requested nested underneath.

 

The sample code is modeled after the Find Text Validation rule and exposes many of the same properties. The purpose of this condition is to search the last response of the web test for the existence or nonexistence of the specified text. If the condition is met the requests under this condition will execute, otherwise the requests will be skipped.

You can download the sample file from here.

FindTextConditionalRule.cs (2.11 kb)

Tags: , , ,

Work

Add validation rule to every request.

by Donovan Brown 20. July 2009 06:02

Problem:

I need to apply the same validation rule to every request of my web test to test for forbidden text.

Solution:

Create a web test plug-in to insert the validation rule before each request.

Code:

using System;
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.WebTesting;
using Microsoft.VisualStudio.TestTools.WebTesting.Rules;

namespace DLBRacingTest.Custom
{   
  
[DisplayNameAttribute("Forbidden Text")]
   
  
[Description("Adds a validation rule on every request looking for forbidden text.")]
   
  
public class ForbiddenText : WebTestPlugin
   
  
{
       
     
/// <summary>
       
     
/// Optional , delimited list of forbidden text. If left blank 'Page Error' is the only
       
     
/// forbidden text.
       
     
/// </summary>
       
     
public string Values { get; set; }
         
     
public override void PreRequest(object sender, PreRequestEventArgs e)
        
     
{
      
        
base.PreRequest(sender, e);

         if (string.IsNullOrEmpty(Values))                
           
Values = "Page Error";
             

         foreach
(string value in Values.Split(",".ToCharArray()))
            
        
{
                
           
ValidationRuleFindText pageErrorRule = new ValidationRuleFindText();
                
           
pageErrorRule.FindText = value;
                
           
pageErrorRule.IgnoreCase = true;
                
           
pageErrorRule.UseRegularExpression = false;
                
           
pageErrorRule.PassIfTextFound = false;
                
           
e.Request.ValidateResponse += new EventHandler<ValidationEventArgs>(pageErrorRule.Validate);
            
        
}
        
      
}
   
  
}
} 

Explanation:

While running test on my web site I noticed a test passed although one of the pages had a Page Error on it. The reason the test passed was because there were no required extraction rules, no validation rules and the paged it failed on was the intended page. However, this test obviously should have failed. The existence of the word “Error” on any of my sites pages is a failed test. Something has gone wrong and I need to be alerted.  By this point I have hundreds of web test each with many request. The thought of having to add a validation rule to every request of every test was very discouraging.

I just knew there had to be an easy way to add this validation rule to every request without doing it explicitly.  A web test plug-in actually has callback that is called before every request of your test called PreRequest.  So I simply add the validation rule when this callback is called.  Now I only have to add a single web test plug-in and every request of that test now has a validation rule that will fail if any forbidden text is found.

I added an optional parameter to the web test plug-in called Values. If you leave it blank a single validation rule is added that searches for the text “Page Error” and fails if it is found.  If you have other forbidden words you would like to search for simply set Values to a comma delimited list of values (i.e. “Page Error,Invalid”).

To use this web test plug-in you can either create a separate class library and reference it in your test project, or simply add this class to your test project. Once you do and build the code you can right click on the root of your web test and select Add Web Test Plug-in… from the context menu.  Select “Forbidden Text” from the list and click OK.

Tags: , , ,

Work

Neptune (personal SMTP testing server)

by Donovan Brown 20. October 2008 21:01

While working on a current project I found myself faced with testing code that sends email.  In the past I would end up with an inbox full of test messages or unhappy customers that wonder why they just received a flood of emails from my site.  I was also frustrated that there was no way to easily automate this testing.

Enter Neptune. Neptune is a SMTP Development Server targeted for use in automated testing. I simply asked the question, “what if I had a SMTP server that did not relay the message and allowed me to query for messages and their content”. I would be able to use a server of this type to act as my SMTP server during testing and write custom plug-ins, validation and extraction rules to communicate with the server.

The goals of Neptune were to facilitate automated testing and be easy to use. I did not want to have to install a service or understand everything there is to know about running a SMTP server. I simply want to start Neptune and run my test.

Full documentation on how to use Neptune is provided in the msi you can download here. NeptuneSetup.msi (1.27 mb)

If you find Neptune usefull feel free to Donate for future development.

 

Tags: , , , ,

Work

About the author

My name is Donovan Brown and I am a process consultant for Imaginet with a background in application development.  I also run one of the Nation’s fastest growing online registration sites for motorsports events DLBRacing.com.  When I am not writing software I race cars for fun.  DLBRacing.com has given me the opportunity to combine my two passions writing software and racing cars.

AdSense

Month List

AdSense