How should I go about mocking calls to XSD data access?
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?
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.
- Partial Classes and Methods (MSDN)
... 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
{
}
}
精彩评论