简体   繁体   中英

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, ie 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.

... 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
    {
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM