Home avatar

Thoughts and code

log4net Configurable Custom Properties

log4net is a great facility to create logs. When it comes to extending it, it’s good as well. To add a custom property to a custom appender that can be configured from configuration XML file is so simple, that it even looks suspicious.

Custom appender class has to define a read/write property publicly exposed. That’s it. Let’s say that property name is “ApplicationVersion”. To configuration looks like this:

Code Coverage

We are a TDD shop, or BDD to be more accurate. Normally we leverage Hudson Test Result Trend to see how things are doing. The project is a Windows NT Service. This is how Test trend looks like:

image
image

I wanted to take the current project and to run code coverage on it, to see if our approach is still holding and how things look like. It was around 90%, and with a few missing specs results were quite good:

Regex With Comments

While working on a specific task that required a lot of parsing, I came to conclusion that comments for Regex expressions are quite useful. The way I usually write code allows to look at specifications and determine what each component can do. But with Regex it’s not quite transparent, as you might use expressions to achieve the goal, but not necessarily expose the usage through specs.

Just to make it a bit more self-evident, here’s a Regex pattern without and with comments.

Mock Implementing Multiple Interfaces

One of the recent tests I had, I had to deal with the fact that a dependency object injected into system under test object will be casted to some other interface (known to be implemented) and used. Moq has some documentation on it, but it was a bit misleading. QuickStart wiki showed an example below:

image
image
From example it is a bit difficult to see that once foo is marked As, it can be casted in production code to IDisposable. This is a very helpful feature in Moq.

Troubleshooting SSL Connectivity

While integrating two clients and working on two way authentication, I had to troubleshoot SSL connectivity. Configuration file was my best tool I could use. There are a couple of things I used, and probably there’s a lot more I am not aware of.

ServicePointManager helps especially when validating server certificate, by allowing to review what are the errors and make a decision either to proceed or not. This is achieved through ServerCertificateValidationCallback event.

Syntactic Sugar

clip_image002
clip_image002

Well, I wish there was a way of getting away from SyntaticSugar static class initial point, and be able just to do plain code

StructureMap & Mocking

I really like working with StructureMap. Today I had to write a quick Factory that would leverage StructureMap to create returned instances. The Factory would look like this:

ILMerge as NAnt Task

I needed to merge a few a few assemblies into one, and tried pretty much what the author of this blog did. I also wanted to be able to “hide” the namespaces merged into main assembly, so that in case there are 2 identical classes in final assembly, only the class from the primarily assembly would be showed by Visual Studio. In my case, it was custom Logger vs. log4net Logger, which I wanted to “hide”.