views:

65

answers:

1

Been a long time user of Subsonic 2.x and have used 3.x a bit, but I've recently started transitioning our use of SS from using repositories to ActiveRecord instead. I'm currently stumbling on some of our unit tests and I wonder if it's perhaps because I'm misunderstanding the intent of the Setup() method. Alas, the only documentation I can find is on Rob Conery's blog.

On my unit tests, I'm stuffing a collection of objects, let's say a List of Accounts. I then want to validate that some code is properly filtering against the repo by a property, let's say the email address. My (simplified) unit test setup is below.

The kicker is that when using the "Test" connection strings, it seems like any LINQ I write against the repo returns me all the records I stuffed into the Setup--which is making me wonder if I'm misunderstanding the intention of Setup(). It's as if it were behaving like a Mock setup, e.g. mymock.Setup(foo => foo.Email).Returns("[email protected]").


     List accounts = new List()
     {
        new Account() { FirstName = "Paul", LastName = "McCartney", Email = "[email protected]" },
        new Account() { FirstName = "John", LastName = "Lennon", Email = "[email protected]" },
        new Account() { FirstName = "Ringo", LastName = "Starr", Email = "[email protected]" },
        new Account() { FirstName = "George", LastName = "Harrison", Email = "[email protected]" },                
        new Account() { FirstName = "Taylor", LastName = "Swift", Email = "[email protected]" }
     };

     DB.Account.ResetTestRepo();
     DB.Account.Setup( accounts );

Elsewhere, the code I'm trying to unit test is basically performing a Find(). The real implementation has a semi complex set of conditions, but even simplified conditions don't appear to work.


  Account.Find(a => a.Email == "[email protected]").SingleOrDefault();

The above will bomb with an exception indicating that the lambda returned multiple elements. When I debug into the test, sure enough, the result of the Find() is all the objects I had stuffed into the mocked repo via the Setup() method.

Rob C laments that ActiveRecord can be tough to test--which is a bummer. But I can't imagine that the testing scenario is breaking on such a mundane sample--it's PEBKAC right?

Halp!?

Edit:
Josh Rivers asks what appears to be a similar question, though it doesn't appear to be resolved. Linking for completeness.

+1  A: 

Going to answer my own question for any future parties, not that there's a ground swell of activity rushing to this thread:

Turns out that the current implementation of test repositories (Subsonic 3.03) has a bug where it basically just returns the entire set of values inside the repository. The current fix (haven't tested myself, but has worked for others) is to pull the current main line of the source code and recompile.

See: Subsonic Issue 109

bakasan