Skip to main content

Posts

Showing posts with the label C#

Enabling Unit Test Harnesses Against Internal Methods

Being a purist, I like to lock down my classes and methods with private and internal so as not to expose functionality unnecessarily as public. This presents a problem with unit testing. The test harness cannot see internal methods...even on a public class. I had been editing the code to mark the method public, executing tests in debug mode, and then re-editing the method back to internal. Hokey...at best. As a far more optimal and usable alternative, add an InternalsVisibleTo directive to your AssemblyInfo.cs file. It opens the door to test harnesses to internal methods. [assembly: System.Runtime.CompilerServices.InternalsVisibleTo("[Namespace of test harness here without brackets]")]

January CONDG Meeting

Hit the Central Ohio .Net Developers Meeting last night. You'll find me there almost every month but last night was especially cool. Mike Wood presented on .Net Workflow (WF) as a rules engine. This is Mike's fourth time in recent weeks delivering this presentation around the Heartland (Microspeak for Ohio, Ky, Michigan, Tenn) District and it showed. The talk communicated the ins and outs of a complicated but feature-rich product with clarity and passion. It was one of the best I can remember in recent months...although I tend to get really geeked out about WF and BPM. I must admit an "ah, ha" moment in approaching .Net WF as a rules engine. (It seems fundamental and a no-brainer that the heart of WF is a rules engine but...) I had always just thought of it as a mostly-graphical (drag/drop) method to lay out a business process...like a mortgage application approval process. Did someone from Credit approve it? Yes, then "route" to Accounting, etc. But WF is ...

Good C# Learning and Interviewing Links

C# Learning http://www.codeproject.com/csharp/quickcsharp.asp http://msdn2.microsoft.com/en-us/vcsharp/aa336766.aspx http://msdn2.microsoft.com/en-us/vcsharp/aa336809.aspx http://www.oreilly.com/catalog/learncsharp2/ C# Interviewing http://rileyperry.blogspot.com/2005/05/c-interview-questions.html http://blogs.crsw.com/mark/articles/252.aspx http://www.hanselman.com/blog/WhatGreatNETDevelopersOughtToKnowMoreNETInterviewQuestions.aspx http://spellcoder.com/blogs/bashmohandes/archive/2007/02/26/5991.aspx http://www.geekinterview.com/Interview-Questions/Microsoft-NET

Favorite C#.Net Interview Question: Numeric Conversions

I like to ask a wide variety of technical questions targeted to the candidate's seniority during interviews. My favorite C# question focuses on converting an Int64 into an Int32. Hopefully, this isn't something you need to perform often (poor design) but occasionally we have to clean up after the other guy, right? ;-) (If you interview with me and are reading this post-consider it a gimme...and hopefully you learned something anyway.) Situation: We have an Int64 "b" I need to convert into an Int32 "a". How should we set a = b in the safest manner (i.e. no data loss)? Here are some options: Line 15 does not compile throwing a "Cannot implicitly convert type 'long' to 'int'. " exception. Line 17 properly raises an OverflowException. Line 19 does _not_ throw an exception. a's value incorrectly becomes 1569325055. Line 21 properly raises an OverflowException. In my opinion, the style in Line 17 is the best because it leverages th...