﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Hendry Luk commented on Mocking NHibernate</title><description>Thanks Oren! The test does look very concise and clear. 
  
After reading that, I looked at my code again, and realize I really should clean up all my builders. 
  
The other major point I realize is that your test is written almost in acceptence test style, instead of striving for slicing the unit-test as thin/isolated as possible with a lot of nitty-gritty details (that make my tests bloated). Cleaner indeed.
  
That... I will steal ;)
</description><link>http://ayende.com/3957/mocking-nhibernate#comment15</link><guid>http://ayende.com/3957/mocking-nhibernate#comment15</guid><pubDate>Mon, 20 Apr 2009 09:29:08 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>Hendry,
  
I am sorry, nothing that is out in the open, no.
  
But take a look at the builder pattern, basically.
  
  
[Fact]
  
public void Will_not_buy_movie_from_user_if_user_rented_movied_and_reported_it_lost()
  
{
  
	Movie movie = new MovieBuilder("Lilies on the Vally");
  
	User user = new UserBuilder("ayende");
  
	var rental = user.Rent(movie);
  
	user.ReportLost(rental);
  
  
	AddToDatabase(user, movie, rental);
  
  
	// run actual test
  
  
	var controller = new BuyBackController();
  
	var result = controller.BuyBack("Lilies on the Vally") as ViewResult;
  
	Assert.Equal("CannotBuyBackRentedLostMovies", result.ViewName);
  
}
</description><link>http://ayende.com/3957/mocking-nhibernate#comment14</link><guid>http://ayende.com/3957/mocking-nhibernate#comment14</guid><pubDate>Mon, 20 Apr 2009 08:56:04 GMT</pubDate></item><item><title>Hendry Luk commented on Mocking NHibernate</title><description>Do you have any reference project that can slightly illusrate the idea? 
  
  
I've looked at Pipe/Filter in MVC Storefront, and I have to say that the unit-tests for its Controllers are quite tediously data-driven, and starts getting repetitive. It's still fine in the small app like ecommerce storefronts, but I believe it could have gotten much worse in complex applications. I'm curious about your view about it, and a better way to it.
  
Btw I 
[totally agree](http://hendryluk.wordpress.com/2009/03/23/extensible-query-with-specification-patterns/) about OCP problem with repository that you bring up in the next post, the exact reason I've been looking for an alternative to repository pattern.
  
But so far, mockability is really my biggest stumble block.
  
  
Great series of write up btw, as always!
</description><link>http://ayende.com/3957/mocking-nhibernate#comment13</link><guid>http://ayende.com/3957/mocking-nhibernate#comment13</guid><pubDate>Mon, 20 Apr 2009 08:47:35 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>Hendry,
  
Queries exists in the business layer.
  
I don't have a real data layer, since I leave that to NH in almost all cases.
  
  
As for testing, you find that this is very easy to handle once you setup the system. 
  
  
My controllers tend to be the place where I am only orchestrating things, real business logic is located elsewhere, so I don't really care that I test them using mini integration tests.
  
  
</description><link>http://ayende.com/3957/mocking-nhibernate#comment12</link><guid>http://ayende.com/3957/mocking-nhibernate#comment12</guid><pubDate>Mon, 20 Apr 2009 08:15:55 GMT</pubDate></item><item><title>Hendry Luk commented on Mocking NHibernate</title><description>Btw, IMHO, incorporating SQLite into domain-service test should be classified as integration test (as opposed to unit-test). 
  
And when treated as a _substitute_ for unit-tests, it seems to be an anti-pattern to me. Doesn't it bring too much baggage for the true purpose of unit-test and TDD?
</description><link>http://ayende.com/3957/mocking-nhibernate#comment11</link><guid>http://ayende.com/3957/mocking-nhibernate#comment11</guid><pubDate>Mon, 20 Apr 2009 05:00:57 GMT</pubDate></item><item><title>Hendry Luk commented on Mocking NHibernate</title><description>So do you not have any "unit-test" for the query object itself at all? I.e. you always test the query in conjunction with the business services using it (possibly repeatedly).
  
  
I hate doing in-memory test, because setting up stub data, taking care of all its associations and database constraints, and evaluating the results, they are very tedious. Particularly if they have to be repeated everytime your service class uses the same query over and over again.
  
  
Which is why I only do such test in data-access layer for each individual query method.
  
  
Then in business service, I just mock them out (good old repository) and concentrate at business rule itself, and without repeating tedious data-driven unit-tests. 
  
This also makes the business rule much easier to read at high level point of view, rather than being cluttered with long winded stub data (and DB related workarounds to take care of table associations and constraints) in the unit-tests of domain-layer or UI controllers.
  
  
I'm intrigued to see the unit-test of your services/controllers. In my imagination, it's something very bloated (with various concerns about stub data).
  
  
Out of curiousity, if querying is a business concern, which layer do you put them in the projects?
</description><link>http://ayende.com/3957/mocking-nhibernate#comment10</link><guid>http://ayende.com/3957/mocking-nhibernate#comment10</guid><pubDate>Mon, 20 Apr 2009 04:34:53 GMT</pubDate></item><item><title>Simone commented on Mocking NHibernate</title><description>Oh.. ok... I understood it was the 28th post in the queue :)
  
  
Yep, I agree... 10 posts a day is a bit "challenging", especially because your posts are really "intense".. not like the "announcement" kind of post of other blogs that have 10+ posts a day.
</description><link>http://ayende.com/3957/mocking-nhibernate#comment9</link><guid>http://ayende.com/3957/mocking-nhibernate#comment9</guid><pubDate>Sun, 19 Apr 2009 15:06:46 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>Simone,
  
You don't follow. It is already posted, but it is posted for the 28th.
  
I am _trying_ to put some distance between my posting, because an outpouring of 8 - 10 posts a day can be a bit.. challanging for the readers.
  
Right now I have posts all the way to beginning of May.
</description><link>http://ayende.com/3957/mocking-nhibernate#comment8</link><guid>http://ayende.com/3957/mocking-nhibernate#comment8</guid><pubDate>Sun, 19 Apr 2009 15:02:01 GMT</pubDate></item><item><title>Simone commented on Mocking NHibernate</title><description>At the pace Oren is posting lately, it will not be a long wait, A week at most :)
</description><link>http://ayende.com/3957/mocking-nhibernate#comment7</link><guid>http://ayende.com/3957/mocking-nhibernate#comment7</guid><pubDate>Sun, 19 Apr 2009 14:24:53 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>Kelly,
  
Yes.
</description><link>http://ayende.com/3957/mocking-nhibernate#comment6</link><guid>http://ayende.com/3957/mocking-nhibernate#comment6</guid><pubDate>Sat, 18 Apr 2009 23:53:51 GMT</pubDate></item><item><title>Kelly Bourg commented on Mocking NHibernate</title><description>I'm guessing you are talking about using SqlLite in memory DB?
</description><link>http://ayende.com/3957/mocking-nhibernate#comment5</link><guid>http://ayende.com/3957/mocking-nhibernate#comment5</guid><pubDate>Sat, 18 Apr 2009 20:13:30 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>It supported everything that I tried so far.
</description><link>http://ayende.com/3957/mocking-nhibernate#comment4</link><guid>http://ayende.com/3957/mocking-nhibernate#comment4</guid><pubDate>Sat, 18 Apr 2009 19:41:10 GMT</pubDate></item><item><title>Gokhan commented on Mocking NHibernate</title><description>Will the in memory dialect support all your mappings?
</description><link>http://ayende.com/3957/mocking-nhibernate#comment3</link><guid>http://ayende.com/3957/mocking-nhibernate#comment3</guid><pubDate>Sat, 18 Apr 2009 19:38:08 GMT</pubDate></item><item><title>Ayende Rahien commented on Mocking NHibernate</title><description>Vincent,
  
Because that is when it ended up in the queue.
</description><link>http://ayende.com/3957/mocking-nhibernate#comment2</link><guid>http://ayende.com/3957/mocking-nhibernate#comment2</guid><pubDate>Sat, 18 Apr 2009 19:24:02 GMT</pubDate></item><item><title>Vincent commented on Mocking NHibernate</title><description>Why the 28th?
</description><link>http://ayende.com/3957/mocking-nhibernate#comment1</link><guid>http://ayende.com/3957/mocking-nhibernate#comment1</guid><pubDate>Sat, 18 Apr 2009 15:37:08 GMT</pubDate></item></channel></rss>