markrendle / Simple.Data

A light-weight, dynamic data access component for C# 4.0
MIT License
1.33k stars 303 forks source link

all this internal stuff is making me cry #7

Closed NotMyself closed 13 years ago

NotMyself commented 13 years ago

is there a simple way to fake a database and validate the sql generated? Similar to what you do in the Database Behavoir tests?

markrendle commented 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.

markrendle commented 13 years ago

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.

NotMyself commented 13 years ago

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.

markrendle commented 13 years ago

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.

markrendle commented 13 years ago

Also, don't forget that you can download the source code and do whatever you want with it. :)

NotMyself commented 13 years ago

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?

markrendle commented 13 years ago

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.