Today, I’ve been writing few methods for my DAL classes, of course, I decided to have one or few integration unit tests that hits database and see actual SQLs with NHibernate Profiler.
So in couple of minetes I’ve got unit tests that had following line in the beggining of each:
if you don’t know, this line attaches your execution code with NHibernate Profiler, so I’m able to see SQLs NHibernate generates.
When I run bunch of unit tests in my testing file, I’ve got strange picture with duplicating of queries for each test with arithmetic progression. And N+1 problem, but hold on, I’m sure that I did everything through joins.
Reason is that profiler appends to my code on each new test run and that is why it start thinking that I have multiple selects to get list of something.
Solution, which I would recommend as pattern for writing Unit Tests with NHibernate Profiler is following:
Quick & cheap way to rename colum in table:
I’ve upgraded my system to Windows 7 couple of months ago, but I haven’t used web development.
Few days ago, I created empty web application, added new page and added <p>bla-bla<p>, then I hit Ctrl+F5 and my default browser opened, but nothing happened. I was thinking that it is because of my browser, so I switched over 3 browsers and nothing helped, I also thought that it VS2010 broke something causing asp.net development server issues, so uninstalled it and installed back, but nothing helped.
I even had a thought to reinstall system, but decided to search over the internet more deeper and found that:
Reason is that when system uses IPv6 browsers could have issues with resolving localhost.
Disabling IPv6 is solution for this problem.
You can disable IP 6 in your system by ensuring that you have this in your registry:
HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServicesTcpip6ParametersDisabledComponents set to 0xffffffff
Firefox settings change
Also when searching I found for myself that we can change settings of Firefox with writing about:config in address bar.
What do you see to be wrong with this code?
At first I did not see any issues with it so I copied it and changed a bit for my another query. But current method is wrong. I discovered this with UTs.
First, Projections.RowCount() generates COUNT(*) in select statement.
This is query, which I got from my new Unit Tests: RuleExists_HitsDatabase_ThereIsNoRule.
Result of this query is number of rows like on picture below:
So, verification return result.Count > 0; is absolutely incorrect.
I’ve chagned it to return (int)result > 0;
Do not be lazy to write Unit Tests both for success and failure sceneries.
To add “order by” to your criteria you need this statement.
To add “top 10” to your criteria you need this statement
So code about which I’m talking could look like:
SetResultTransformer or “Why did I get 5 results instead of 10?”
So you expect to have top 10 priority Customers with status Created.
In scope of my current task it was needed to add priority to this query, so I decided to unit test it of course.
In Debug I found that there are actually 5 results in resulting collection.
That is because generated SQL generates result which contains duplicated CUSTOMER_IDs, that is because I have join-s there. But then why did not I get 10 duplicated Customers? Because query has ResultTransformer which is applied after SQL has been ran. (That is 100% since I took a look at generated SQL via NHibernateProfiler).
So .SetResultTransformer(new DistinctRootEntityResultTransformer()) is removing of all duplicated entries of my root entity (Customer).
Good explanation to this you can find here.
Do you want to see your button to be in pressed or unpressed state when you hit it once?
Did you catch that this behavior is not really button’s behavior – it is more checkBox’s behavior.
So to accomplish your goal you need move checkBox to your form and set appearance from “Normal” to “Button”. Like here:
Kick me if you don’t want to see such posts on my blog. :)