CSLA: an interesting behaviour with Unit testing

I have been working on a CSLA project for the last few months. We are working on refining our unit testing now that we have implemented our authorization rules. All good. We are working VS2005. Honestly, I like CSLA in many ways, but there are few gotchas we've seen along the way. This post outlines one of them.

However, we noticed something today. We establish our starting conditions in our ClassIinitalize in the TestClass. When we have only one TestMethod in the class, this works fine. We recently included several CRUD tests in one TestClass for a particular class. We established our CSLAPrincipal in the ClassInitalize as we have done in all our others. Suddenly, several of our tests started failing, where before they worked. The failures were all related to an error message indicating that our authorization rules were doing their job; somehow our authorization was going awry.

I checked the CSLAPrincipal on the start of the first test, and it was fine; we were in role. However, each subsequent test, we were NOT in role! The CSLAPrincipal role had been changed to a generic CSLAPrincal, not the one we set. This seemed odd, so I changed the test to place the CSLAPrincipal initialization in the TestInitialize. This works fine.

We realized that the test thread must end once the first test is set, and the CSLAPrincipal is cleared out. Since we set this only once previously, we never set it again. We also realized that the VSTS unit tests run the ClassInitialize for all the TestClasses in a run before the first test is initialized, or that it seems so anyway.

So, after much cussing and debugging of our tests, we figured it out: be sure to set your CSLAPrincipal in your TestInitialize instead of ClassInitialize.

Where's Waldo...err, Theo?

I'm still here. Still in Dallas Mon-Thurs, working 10 hour days on the client project. I just noticed it's been 2 weeks since I last posted, and thought I should. I am only a couple of weeks away from Platinum status with American Airlines. This is actually a good thing, even though American isn't what you might call a "great" airline. I am starting to be recognized by the people in the airport. Mostly due to my tats, but it's still depressing to fly that much.

I found a cool binary watch that I want. Sheri thinks I am geeky as heck to want one. I suspect my buddy would think it cool, too

I've recently become a member of the Friends of Red Gate which is giving me the chance to review many of their tools and become familiar with them. I am currently reviewing the SQL Prompt, SQL Refactor, and SQL Doc tools. More on these as I get more exposure to them. I've been using some of the tools in the last couple of days, but want to play with them a bit more before I post anything. I did notice one feature I wish existed in the SQL Refactor tool: I would love a tool that would allow me to add a column to a table, and have every reference to that table add the new field (for example in a large SQL file that contains table definition and stored procs). Just a thought. More on that later....

«May»
SunMonTueWedThuFriSat
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789