views:

13

answers:

1

Hey guys

I'm trying to introduce Unit testing and TDD into my code (working as one of a team within a large pre-existing project).

The project I'm working on uses XSDs to do a lot of the data access (often with no abstraction, i.e. database calls from the .aspx.cs pages, which is another issue I wish to address at some point).

My question is: how can I mock database access using XSDs within my unit tests?

as they're strongly typed it's not as simple as just adding an interface with Update() or Insert() methods, as each XSD DataTableAdapter has different arguments for its various methods.

Does anyone have any suggestions?

+1  A: 

If you are refering to Strong Typed DataSets and Adapters you could use a partial class to bind an interface to your objects. Then you could mock these data access objects just like any other object with your favorite mocking framework.

... Assume that PersonTable has two columns {Name,String}, {Age, Int32} ...

//Add other interfaces as needed
public interface IPerson
{
    string Name { get; set; }
    int Age { get; set; }
}

public partial class DataSet1
{
    partial class PersonTableDataTable
    {
    }
    partial class PersonTableRow : IPerson
    {
    }
}
Matthew Whited
any chance of a short code example?
Ed Woodcock
If you dig through your code and the `[DataSet].Designer` file you will be able to find what classes you need to work with the partial classes on. You can also right click on your table on the design pane and then click on `View Code`. This should create the partial class files for you.
Matthew Whited