I am writing a new application that access a large, complex, badly structured legacy database. I'm reusing as many components from existing projects as possible. One is a Entity Framework (6) DbContext with about 350 tables. This project only accesses about 15. I have a new repository class for this project that's limited in scope to my particular needs. I typically write fake repositories for testing by just coding up some new objects and returning them. For example:
Real Repository method:
public FPS_Transaction GetTransaction(int payorReferenceNum)
{
return Context.FPS_Transaction
.Where(t => t.PayorReferenceNum = payorReferenceNum).SingleOrDefault();
}
Fake Repository method:
public FPS_Transaction GetTransaction(int payorReferenceNum)
{
return new FPS_Transaction
{
TransactionId = new Guid("029888b9-5fbb-4a92-a49a-92aa86c2906a"),
PayorReferenceNum = payorReferenceNum
};
// The property list is UUUUGGGEEE!
}
There are a number of these entities to code up by hand, and some are quite large unfortunately.
I want to make it clear I'm not trying to test my repository or query logic, but the program that calls it. Those entities provide lots to knobs and switches that branches through complex logic in the application, so I'll be tweaking some the mocked up data by hand to ensure coverage of the different scenarios.
Does anyone know of a utility that will read a database table and spit out a row or two as c# code that recreates the populated object? It would be fine I suppose if it serialized to disk and read it back in...
Aucun commentaire:
Enregistrer un commentaire