Saturday, October 21

InternalsVisibleToAttribute and Unit Testing

When creating unit tests to be run with NUnit, I like to keep my tests in a separate assembly, which is not delivered when my project is deployed.

This can make it difficult to create unit tests for classes that should not be visible outside of that assembly. One of my classes uses one of 3 strategy classes that encapsulate a feature of the business logic. I would normally declare these with the intern access modifier, but to test each strategy works I've needed to make them publically available.

If, however, I add the [assembly: InternalsVisibleTo("UnitTests")] line to my AssemblyInfo.cs file, any objects declared with the intern access modifier can be seen by the UnitTests assembly.

Tuesday, October 10

Processes and Practices

Jared Richardson describes a process he wants his team to follow. Many others have attempted the same and have reached similar conclusions, and I can't disagree with any of Jared's thoughts.

However, I think he misses out the most important part of the process which should be to regularly think about your process and what you have done and how you could have done it better. All processes and practices should be adaptable. Different people have different strengths and new technologies mean we have to develop things in different ways.

A lot has been written about technical debt, where if not enough time is invested in developing high quality software, it becomes harder to maintain and costs of new developments increase over time. We should also think about process debt, where if not enough time is spent improving and adapting our processes, they become less efficient and costs of new developments also increase.

C# collection classes performance

I was looking for a table summarizing how different C# generic and non-generic collection classes performed, relative to one another, thought there would be hundreds available, but could not find one. So here one is for my future reference, and for anyone else who reads this.



O(1) = constant time
O(log n) = time proportional to the log of the number of elements in the collection
O(n) = time proportional to the number of elements in the collection

Some collections are better for smaller collections, but don't scale to larger ones. The List, LinkedList, SortedList, Queue and Stack classes are better for smaller collections than the Dictionary, Hashtable and SortedDictionary classes.

Wednesday, October 4

The type or namespace name 'Properties' could not be found

I was getting an error message when building my project that said "The type or namespace name 'Properties' could not be found".

This was because I had changed the default namespace in the properties for my project to make it "project.name" instead of "name". The class that did not build was already in the namespace "project.name".

The error message was on a line that said

"global::name.Properties.Resources...."

Changing this to

"global::project.name.Properties.Resources...."

seemed to fix the problem.