8.3. Building a Custom Data Generator

While the default data generators are very useful, especially the regular expression one, there may be times when those data generators just don't do quite what you want them to. At that point, you will need to create a custom data generator. In this section, you walk step-by-step through creating a custom data generator for credit card numbers. This data generator will create Visa (number begins with a four) or MasterCard (number begins with a five) numbers, and will even add dashes between the numbers as an optional setting.

  1. To get started, create a new C# class library project in Visual Studio and name it CreditCardNumberdg.

  2. Rename the Class1 file to be CCNum.

  3. Next, add a reference to the Microsoft.VisualStudio.TeamSystem.Data.dll. This DLL is located at c:\Program Files\Microsoft Visual studio 8\DBPro. Once you have added that reference, add the following using statement to the top of your CCNum.cs file:

    using Microsoft.VisualStudio.TeamSystem.Data.DataGenerator;
  4. Add the Generator() attribute to the top of the CCNum class declaration:

    [Generator()]
    Public class CCNum
    {
    ...
    }
  5. Your class also needs to inherit from the Generator abstract class, so make the following change:

    [Generator()]
    Public class CCNum : Generator
    {
    ...
    }
  6. Right-click the Generator word, and select Implement Abstract Class, to stub out all the methods you must implement for this class. The only required method it creates is the GenerateNextValues() method.

  7. Next, you want to ...

Get Professional Team Foundation Server now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.