Click or drag to resize

Installation and Usage

The TestHelperExtensions are a set of extension methods helpful when building unit tests. Methods include functionality for creating random data of various types, converting data types, comparing date data, searching within string arrays, etc.

Installing the TestHelperExtensions from NuGet

Installing these extensions using the NuGet package manager is the simplest and easiest way to get started using these extensions. There are 2 options, either of which accomplishes the same thing:

  • Using the NuGet Package Manager GUI

    1. From the solution containing the test library, select Manage NuGet Packages for Solution.

    2. On the resulting NuGet UI, select the package source nuget.org and the filter All.

    3. Using the search box, search for TestHelperExtensions.

    4. Click on TestHelperExtensions on the left side of the screen to select that package.

    5. On the right side of the screen, be sure the test project in your solution that you want to use these helper methods with is checked and that production projects are not checked.

    6. Click Install to install the package.

  • Using the NuGet Package Manager Console

    1. From the tools menu in Visual Studio, select NuGet Package Manager -> Package Manager Console.

    2. In the drop-downs at the top of the resulting console window, select the package source nuget.org and be sure that the default project is set to the test project in your solution that you want to use these helper methods with. You do not want to install the extensions into production projects, just unit test projects.

    3. Type Install-Package TestHelperExtensions to install the package.

Building and Installing the TestHelperExtensions Yourself

The NuGet package methods shown above are the simplest and easiest way to get started using these extensions. If, however, you want to load and build the library yourself, you'll can follow the instructions below.

  1. Download the source code from the GitHub repository and open the TestHelperExtensions.sln solution file in Visual Studio. This solution was built using Visual Studio 2015 but was created in much earlier versions and should work fine in older versions of Visual Studio.

  2. Set the configuration to "Release" and build the CBI.TestHelperExtensions project

  3. Copy the CBI.TestHelperExtensions.dll and CBI.TestHelperExtensions.pdb files from the ..\bin\Release folder underneath the project, to the solution in which you want to use the functionality

  4. Set a reference in the unit test project(s) of your solution to the CBI.TestHelperExtensions.dll.

Notes:

  • To get the help documentation to compile, you will need to have the Sandcastle tools installed.

  • To get the NuGet package project to compile, you will need to have the NuGet Packager templates installed.

Using the TestHelperExtensions

However you install the extensions, they are very simple to use once installed.

  1. Add a Using TestHelperExtensions; declaration to the top of each module from which you want to reference these functions. This is necessary to bring the extension methods into the current scope.

  2. Reference the functions as if they were part of the objects they are supporting. For example, you can generate a random number between 10 and 100 using the statement var randomValue = 100.GetRandom(10);

For detailed information on the classes and methods available in this library, see TestHelperExtensions Namespace

See Also

Other Resources