Raymond is wondering what people think of CodeBetter.com. Let me tell you what I think.
The real problem with group blogs is the number of people who post breaking news – like “Microsoft is going to release IE7!”. Oh, wait – that’s not a problem on CodeBetter.com.
It’s good to see the CB’ers function as a group. Instead of sounding like a scratched CD, they feed off each other to build better content. It’s collaborative and interesting. CodeBetter.com is what a group blog should be. I like Darrell’s agile news, Brendan’s forays into the .NET framework, Geoff’s quirkiness, and then there is Sahil. Let me tell you about Sahil. Sahil came to the Columbia user group meeting last month to give a talk on serialization. During the talk he serialized DataSet objects, customer objects, and Star Trek characters with two different versions of .NET. I thought I was going to leave the building as a blob of 1,568 bytes on Sahil’s hard drive.
Keep up the great work CB’ers, and Raymond – keep the OOP articles coming. These articles are well written and I know many people will benefit.
P.S. I know many people don’t like the amount off “off-topic” material on other group blogs. Me? I like to know what people are feeding their cat every now and then. For example, you never know what you’ll see or hear on the John Elliot and Bill Ryan blogs, but I find their blogs delightfully entertaining. Perhaps they are never boring because John cuts code 20 hours a day and Bill is a philosophy major and insomniac. I say this even though John calls me names and Bill leaves me hanging in San Francisco. Thanks, guys.
This week I’m going to tie up some lose strings from my VSLive! presentation…
One can programmatically interact with Reporting Services across the network by sending requests via an URL, via a web service request (SOAP), and via Windows Management Instrumentation (WMI). Of these three – I spend no time covering WMI because it’s typically not an interface used to deliver features to end users. I’ll provide some more information here.
In general, WMI exposes classes to configure and mange both hardware and software on computers throughout the network. Reporting Services provides WMI classes that let us query and make changes to report server configurations.
WMI is one of those pieces of software that requires a reference manual nearby unless you work with it everyday, but there is a very easy way to get started: Scriptomatic 2.0. Just pick a WMI class and the tool will code-gen a runnable sample script in VBScript, Jscript, Python, or Perl. Scriptomatic itself is an interesting application written as a single HTA file and run in IE.
Here is a script from Scriptomatic showing the properties of the MSReportServer_ConfigurationSetting class from the root\Microsoft\SqlServer\ReportingServices\v8 namespace:
On Error Resume Next
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
arrComputers = Array("REPORTING")
For Each strComputer In arrComputers
WScript.Echo
WScript.Echo "=========================================="
WScript.Echo "Computer: " & strComputer
WScript.Echo "=========================================="
Set objWMIService = GetObject("winmgmts:\\" & strComputer & _
"\root\Microsoft\SqlServer\ReportingServices\v8")
Set colItems = objWMIService.ExecQuery _
("SELECT * FROM MSReportServer_ConfigurationSetting", "WQL", _
wbemFlagReturnImmediately + wbemFlagForwardOnly)
For Each objItem In colItems
WScript.Echo "DatabaseIntegratedSecurity: " & _
objItem.DatabaseIntegratedSecurity
WScript.Echo "DatabaseLogonName: " & objItem.DatabaseLogonName
WScript.Echo "DatabaseLogonPassword: " & objItem.DatabaseLogonPassword
WScript.Echo "DatabaseLogonTimeout: " & objItem.DatabaseLogonTimeout
WScript.Echo "DatabaseName: " & objItem.DatabaseName
WScript.Echo "DatabaseQueryTimeout: " & objItem.DatabaseQueryTimeout
WScript.Echo "DatabaseServerName: " & objItem.DatabaseServerName
WScript.Echo "Impersonate: " & objItem.Impersonate
WScript.Echo "ImpersonateDomain: " & objItem.ImpersonateDomain
WScript.Echo "ImpersonatePassword: " & objItem.ImpersonatePassword
WScript.Echo "ImpersonateUserName: " & objItem.ImpersonateUserName
WScript.Echo "InstallationID: " & objItem.InstallationID
WScript.Echo "InstanceName: " & objItem.InstanceName
WScript.Echo "PathName: " & objItem.PathName
WScript.Echo "UnattendedExecutionLogonDomain: " & _
objItem.UnattendedExecutionLogonDomain
WScript.Echo "UnattendedExecutionLogonName: " & _
objItem.UnattendedExecutionLogonName
WScript.Echo "UnattendedExecutionLogonPassword: " & _
objItem.UnattendedExecutionLogonPassword
WScript.Echo "VirtualRoot: " & objItem.VirtualRoot
WScript.Echo
Next
Next
If you’d rather have the code in .NET, then the System.Management namespace contains all the WMI goo. WMI is probably underutilized due to the quirky mixture of SQL like syntax with a namespace traversed like a file system. It seems powerful, and it’s something I need to keep in mind next time I need a configuration script.
When we write unit tests, we write a piece of test code to verify a piece of production code. The trouble is, production code has the nasty habit of relying on dependencies that are hard to control. Dependencies may be infrastructure dependencies like SMTP servers and databases, or may be software dependencies that are non-trivial to setup and get into the correct state for testing.
Mock objects remove these dependencies and simplify unit test code. A mock object is a stand-in replacement for a real-world domain object. For more details about mock objects, see “Mock Objects to the Rescue!”.
When I first began reading about mock objects, I did not like what I was reading. In fact, I disliked the idea so much, I entered ….
I found my eyes leaping over any pages containing the four letter m word. I felt confident in my gut reaction that m*ck objects were a fad –
- the same gut feeling I had when I heard of a new language by the name of C#.
As time passed, I realized the m*ck object talk was still picking up steam, and I entered ….
I decided ‘object mockery’ was no longer a fad, but a placebo in source code form. Software development teams relying on mock objects would develop overconfidence in the quality of their product. These teams could watch their house of mock playing cards crumble in the cruel hands of the real world.
“Fools!”, my inner voice would yell in a Gandalf like tone. My inner voice always sounds like Gandalf or Ed Norton Jr. when I’m agitated.
As time went on, I began to write unit tests, and watch others write unit tests. Slowly … gradually … I entered ….
Some methods cry out for a unit test. Perhaps the method has logic to react to an SMTP error message, or perhaps the method has an exception handler to recuperate from a network error. These error conditions are difficult to trigger at just the right time, but I have to know exactly how the code will react. Unit tests are addictive that way. I found myself thinking about writing mock objects just to force these error conditions.
Suddenly, I was an object mocker.
The days grew long, and grey. One rainy night while sitting in my car - I hit bottom. I found myself tuning the radio to a country music station, and singing along to an old George Jones tune. I had officially entered …
I thought about the burden faced by the universe of software development. Any object I can think of will need to be mocked somewhere, in some program. Forget databases and mail servers. We will mock water fountains and pizza ovens. We will mock robot arms and booster engines. We will mock the stars and the sun. Yes, even the moon. The moon must be mocked.
Mock me, will you?
I’ll mock you, too….
I thought about starting a web site (Mock The World) and selling t-shirts, but I figured only lunatics and government agents would be interested and I didn’t follow through. It took some time to work out of my funk, but eventually, I reached …
I accept mock objects for what they are – a technique to simplify the creation of effective unit tests. I’m always worried, however, about assumptions. Production code contains assumptions about how other objects will behave. Mock objects have a high probability of encoding those same assumptions, and we end up testing tautologies.
Assert.IsTrue( mockWeather.RainTommorow || !mockWeather.RainTommorow).
In software development, we always find a better way to build a mousetrap…
So, anyone using Mock Objects or NMock?
Let me start by pointing to Tom Hollander, who is looking for feedback and input to build the next version of Enterprise Library.
I now return you to my irregularly scheduled ramblings...
Unit testing is here to stay. The only questions about unit testing revolve around the details. Do we test non-public types and methods? Do we use mock objects? I’m always interested in seeing real unit testing code from other projects to understand what decisions others have made. (For an intro to unit testing, see: “Improve the Design and Flexibility of Your Project with Extreme Programming Techniques”).
Enterprise Library uses the NUnit testing framework. It will be interesting to see how easily this will port to the VS 2005 unit testing framework (or even if the tests are ported to 2005, considering the unit testing framework may only be included with the Team System version of Visual Studio 2005). I know I’m chiming in late, but I hope we see unit testing in all versions of Visual Studio.
Enterprise Library includes unit tests in the same assembly as the classes being tested. Tests are surrounded with an #ifdef, presumably to keep them out of production builds and also to allow the library to compile on systems without NUnit.
The unit tests do access members with internal scope.
Unit testing code in EntLib is not in short supply. Here is a snippet from ConnectionStringFixture.cs:
44 [Test]
45 public void CanGetCredentialsFromRealSqlDataClass()
46 {
47 string initialConnectionString =
48 String.Format("server=localhost; database=JoeRandom; uid={0}; pwd={1}; ;",
49 userName, password);
50 this.connectionString = new ConnectionString(initialConnectionString, userIdTokens, passwordTokens);
51 Assert.AreEqual(userName, this.connectionString.UserName);
52 Assert.AreEqual(password, this.connectionString.Password);
53 }
The ConnectionStringFixture class has 10 tests in all:
InvalidOperationExceptionThrownWhenConnectionStringIsNull() EmptyCredentialsReturnedForEmptyConnectionString() CanGetCredentialsFromRealSqlDataClass() CreateNewConnectionStringTest() CreateNewConnectionStringTest() CanAddCredentialsToConnectionStringThatDoesNotHaveThem() CanSetUserIdAndPasswordInConnectionStringThatAlreadyHasOne() RemovingCredentialsFromConnectionStringWithoutThemIsOk() WillRemoveCredentialsFromConnectionString() NullTests()
The overall style and naming conventions stick to accepted practices for writing unit tests. One issue up for debate is the testing of internal methods. I like the approach. Internal members are good candidates for testing since they often form the surface area of an API one layer beneath the public façade. After a short conversation with Rocky this week - I realize there is at least one person who doesn’t agree.
What do you think? (Regarding ‘what to test that is’ – I know some of you think about a lot of things).
Coming soon: Mock classes - and why they make me uncomfortable.
The word excessive is a relative term. What might seem excessive to you could be normal to me, and vice versa. Walt mentioned last week that he has a client who insists on shipping everything in a single assembly – which sounded excessively restrictive to us. On the other end of the scale, someone in the newsgroups posted about the slow startup time of an ASP.NET application composed of 300 assemblies. 300! Certainly 300 is an excessive number, right?
Loading a DLL isn’t a hugely expensive operation - but it doesn’t come free either. Years ago we used to use tools like Rebase to minimize load times. (For the curious, Visual Studio 2003 appears to use 0x11000000 as the preferred load address for a DLL, you can see this under Project -> Properties -> Configuration Properties –> Advanced -> Base Address).
The real problem with having 300 assemblies on hand isn’t the load time, but the time it takes to manage the dependencies and versioning among all the units. I favor starting with rather coarse grained units of deployment. As time progress one can always factor out pieces to be put in separate assemblies to reuse or deploy in distributed fashion.
As William Blake once wrote: Excessive sorrow laughs. Excessive Joy Weeps.
I didn’t get a chance to blog about the morning keynote by Eric Rudder, but plenty of others have, including Sam, Rocky, and Richard.
I went to hear the Don Box and Steve Schwartz breakout session on Indigo. Don wrote some Indigo code with VB.NET – I have pictures to prove it. Indigo is looking exciting – but during the presentation I became a bit distracted. I realized in a few hours I’d be giving my presentation in the same building as these people - felt a bit humbled - wondered what I had gotten myself into - and went off to do some rehearsing at the hotel.
I think my presentation went well – I had a few good comments afterwards. I guess I’ll know more when the evaluations are tallied. One tip I can heartily recommend is to have the first 5 minutes of a presentation down cold. I rehearsed my first 5 minutes endless times. I could have spoken for the first 5 minutes even if a herd of zebras ridden by scantily clad dancing girls had broken into the room and paraded around. The 5 minutes I spent operating in “automatic mode” gave me time to get used to the microphone, the lights, the audience, and got me through the sometimes awkward introductory phase. After 5 minutes I'm into the meatier part of a presentation and can just start talking about what I know.
At this point I could prepare for tomorrow’s flight by packing, or I can go join the evenings festivities.
Easy choice, this one.
I’m sitting in the keynote at VSLive! by Soma Somasegar (VP, Developer Division, Microsoft).
Interesting statistic: In February of 2002 there were 300 “.NET developer wanted” ads on monster.com, today there are over 10,000. Also interesting: in 2002 many of these ads wanted developers with 3+ years of .NET development experience. Gotta love the people that come up with those types of ads.
The Enterprise Library was plugged during the keynote, but the general thrust of the speech was to promote smart clients. I believe the success of Microsoft’s smart client push hinges entirely on ClickOnce. In my experience it’s often difficult to sell the CTOs and CIOs of the world on applications that requires IT to touch an end user’s machine. Many hold a religious like belief that browser applications are the solution to every problem, or they’ve been burned by deployment scenarios in the past. Microsoft will need to promote ClickOnce success stories to the execs more than the developers.
Yesterday was a travel day and was a little rough. Delayed flights - and I had nothing to eat the entire day. When I hit downtown San Fran I sank an entire fleet of small wooden sushi-carrying ships at restaurant called “Sushi Boat”. Yum.