Closed NotMyself closed 13 years ago
Faking a database isn't simple :) But feel free to copy the Behaviour test code and make the changes you need, and ask over at http://groups.google.com/group/simpledata if you need any specific help with something.
This gave me an idea: would a Simple.Data equivalent of LINQpad be useful? So you enter the query using Simple.Data syntax, and it runs against an actual database and shows you the SQL.
actually I was trying to copy the behavior test code, but kept running into internal classes. You have internals visible to attributes to get around it, sadly I can't.
Right. Actually, one of the InternalsVisibleTo assemblies is Simple.Data.Mocking, which contains a MockHelper class with some static methods to let you force your own adapter in.
Try this:
var mockSchemaProvider = new MockSchemaProvider();
mockSchemaProvider.SetTables(new[] { "dbo", "Users", "BASE TABLE" });
mockSchemaProvider.SetColumns(new object[] { "dbo", "Users", "Id", true },
new[] { "dbo", "Users", "Name" },
new[] { "dbo", "Users", "Password" },
new[] { "dbo", "Users", "Age" });
mockSchemaProvider.SetPrimaryKeys(new object[] {"dbo", "Users", "Id", 0}); var mockDatabase = new MockDatabase();
MockHelper.UseMockAdapter(new AdoAdapter(new MockConnectionProvider(new MockDbConnection(mockDatabase), mockSchemaProvider)));
Database.Open(); // now returns a Database which uses that mock.
The thinking behind having this in a Mocking assembly is that it makes clear that it's not recommended for production, where the MEF composition should be used.
Also, don't forget that you can download the source code and do whatever you want with it. :)
AdoAdapter is internal. 8)
I can download the source and fix it myself for sure, but I am currently working on a spike and need to either get the spike done or "git reset --hard" and go back to NHibernate.
Using NHibernate in this spike seems so heavy, that's why I thought I would give your lib a try. I really do dig it and would love to contribute. But I gotta git my spike done 8)
I love how this lib feels so much like Ruby ActiveRecord. You are really on to something here.
Any thought on my mailing list question about doing a Max query?
OK, because I like you I've just pushed a change which adds a CreateMockAdoAdapter method to the MockHelper class. Hopefully that will get you up and running. You will have to pull the source and build it though; I can't justify a binary release for this change. But it'll be in all future releases.
I just replied to your mailing list question, too.
is there a simple way to fake a database and validate the sql generated? Similar to what you do in the Database Behavoir tests?