Browsing All Posts filed under »Tech/Hacks«

Using Pex to test VB.NET code

December 2, 2008

1

In an ideal world one would write unit-tests before writing any new code following the tenants of TDD. In reality it is quite common to have to rely on a legacy library to do some heavy lifting. Pex is a great new tool available from Microsoft Research that can be used to generate unit-tests automatically.… [Read more…]

Mocking indexers with NMock

November 25, 2008

0

Indexers allow objects to behave like arrays. Dictionary class in .NET, for example, provides an indexer that allows the retrieval of the item from the dictionary that corresponds to a particular key. There are two ways you can go about mocking indexers defined on interfaces when using NMock. You can use the Get property to… [Read more…]

Automating windows forms UI testing

November 6, 2008

0

If you have been blessed with a windows-forms application that has business-logic invading the user-interface, I have something that’ll help you. The most practical approach in this situation is to rearchitect the business layer and switch the UI over in a piecemeal fashion. While you’re doing this, automated testing of the user-interface will make your… [Read more…]

Automatic properties with custom logic – part 2

October 29, 2008

5

Let’s say we have a class called ShoppingCartItem. We’re going to concern ourselves with two properties here namely TaxID and Taxable. The business logic dictates that an item is definitely non-taxable if it has a tax-id of zero, otherwise it may or may not be taxable which is decided by some code situated outside the… [Read more…]

Automatic properties with custom logic

October 24, 2008

2

There should be a compiler supported way in C# to declare a property with custom getter/setter logic without having to explicitly declare a backing field. In the absence of such a feature, if you want to have custom getter/setter logic you have to ditch automatic properties, declare a backing field explicitly and then there’s nothing stopping a… [Read more…]

“Add Service Reference” option not appearing in Visual Studio 2008

July 22, 2008

22

Had to do a bit of head-scratching on this one. New projects created in Visual Studio 2008 did show the “Add Service Reference” when right-clicking on a project in Solution Explorer while some existing ones didn’t. Using “Add Web Reference” instead of “Add Service Reference” has its own set of issues in that WCF services… [Read more…]

A simple RTF report generator

June 10, 2008

3

I was describing how a simple yet extensible report-generator could be implemented quickly to somebody. I’m posting it here as some of you might find it useful (and I can refer to this link in future conversations ). The concept: …is really simple. The idea is to look for a placeholder like @Fruit and replace… [Read more…]

ArrayList item comparison

June 6, 2008

2

What’ll be the output of the following piece of code (asked here)? One might expect… True True But what you’d actually get is… False False …because of boxing. a.Add(1) boxes the integer 1 into an object and stores it in a, while b.Add(1) boxes the integer 1 into a separate object and stores it in… [Read more…]

What you should do…

May 1, 2008

0

I am fortunate enough to work with a couple of great individuals. Recently I was able to hypnotize persuade them into discussing things which should and shouldn’t be done in a software project I am absolutely sure that the discussion will help me in the future (and them). However I thought the merged list is… [Read more…]

Two (useless but potentially) interesting tid-bits

April 29, 2008

0

Try-Catch-Finally A try-catch-finally is converted into IL by the C# compiler as a try-catch inside the try block of another try-finally. This allows for finally block to execute even when exceptions are raised in the catch block. Use ildasm and check it out yourself! throw football; Though you cannot throw an arbitrary managed object as… [Read more…]

Follow

Get every new post delivered to your Inbox.