Stijn Volders

A custom helper class to build Uri’s

by Stijn Volders 22. January 2013 22:20

Yesterday we needed to build a Uri to invoke a service. One part is static, one part is dynamic. Since there’s a Path.Combine() method (System.IO), we looked for something in the BCL for Uri's but unfortunately couldn’t find anything decent. So I came up with my own helper class. Chances are high that there’s something available in the framework, but we missed it. Let me know in the comments if I reinvented the wheel :)

Anyway, here it is:

And the tests for it:

Tags:

.net

Versioning all projects in a solution

by Stijn Volders 31. December 2012 11:24

Introduction

A while ago, I had to extract a group of related projects into a separate solution. These related projects are the foundation of the client framework we use at work.

To keep a “loose” coupling between the framework and the applications using it, it’s important that we use some kind of versioning.  Since we’re planning to add the framework assemblies as a NuGet package, we’re going to use Semantic Versioning.

Semantic Versioning (SemVer)

In essence Semantic Versioning comes down to 3 parts in the version number: Major.Minor.Patch.

Major: breaking changes
Minor: New features but backwards compatible
Patch: backwards compatible bug fixes only

Additionally you can append a string to the patch number to indicate that it’s a pre-release version.

Versioning all projects in a solution

Instead of opening every project’s AssemblyInfo file and update the version manually, you can also use one AssemblyInfo for your whole solution:

  • Step 1: Pick one project where you’ll keep track of the version number and update its AssemblyInfo file (in the Properties folder of the project). I’ll refer to this as the “master” project.
  • Step 2: Delete the AssemblyInfo file of every other project in the solution.
  • Step 3: Add the AssemblyInfo file of the master project to every project. Be sure to add it as a link

    image
  • Step 4: Build the solution
  • Step 5: Verify that all output files contain the information from your master AssemblyInfo

    image

That’s it. If the framework version number needs to change, there’s only one file to modify instead. Small things that make me happy.

Tags:

Domain model testability

by Stijn Volders 13. December 2012 12:23

One of the important pillars of DDD is to protect the domain model. To achieve this, we use private setters on the properties of an entity and a constructor that protects the invariant. Jimmy Bogard wrote some great posts about this techniques.

However, one of the drawbacks I've experienced is the friction you get with testing. Loading data into an entity can be a PITA but it's something we have to do regularly. An example: at work we use NHibernate to persist entities in the database. To make sure everything works as expected we have tests that write an entity to the database and read it back. Of course this test only makes sense if the entity holds all relevant data.

Let's take a look at Order and ShipmentInfo entities below. Not entirely how I would do it in a real application but the private setters & invariant constructor is what counts here.

The model

Now that I have a model, I want to get an Order in a "fully loaded" state so I can write a test that asserts my persistence mechanism works correctly:

Getting the model in the correct state (take 1)

As you can see, I need to provide an instance of IOrderNumberGenerator to the Order constructor so I created a fake that is used to set the OrderNumber. Besides that, the Ship method also contains validation which is (for this test) not very relevant. While you can reach the desirable state this way, it quickly gets clumsy when working with real life models. Let's take a look at a different approach:

The state object & extension method

Part 1: The OrderTestContext class:
This class contains all the properties of the model. Only difference are the public setters.

Part 2: The extension method
The extension method makes it possible to publicly expose the internal method on the Order entity to other assemblies (cfr. the test project). The extension method should be in the same assembly as the model for this to work.

Part 3: The modified model
The model should contain a default constructor and a Hydrate method that accepts an OrderTestContext instance as a parameter. Both can be internal since it's only used by the extension method in the same assembly.

Let's take a look at the outcome:

Getting the model in the correct state (take 2)

Getting the Order entity in the correct state requires less effort and is easier to read. No hidden order number, no fakes, everything is right there. 

Summary

I'm aware that this approach won't feel wright for the purists under us. After all I implemented 2 methods on my domain entity I don't need and it's possible to get the entity in an invalid state because the logic that guards the entity is bypassed. However, since the OrderTestContext class & the extension method are in a different namespace, it's screaming in your face that it shouldn't be used for regular purposes. Outside the model assembly the methods are not even visible since they are internal.

Since tests are easily skipped when things get harder, I'm willing to put extra effort in the infrastructure the remove the friction in the tests.

I'm very curious to know what you think, please let me know!

 

Tags:

.net | DDD | TDD

Slides and code from my RavenDB introduction at Visug

by Stijn Volders 30. May 2012 23:44

I want to thank everybody who attended the session yesterday.

The demo code can be found at GitHub: https://github.com/ONE75/ScrumR or you can download it as a zip file

You can download the slides in pdf format here

Tags:

RavenDB | Speaking | Visug

Making things explicit and hitting RavenDB query limitations

by Stijn Volders 26. April 2012 00:36

One of the things I try to do in my code is making implicit things explicit.

Let's take the BacklogItem class of my ScrumR application as an example:

clip_image001

While talking about BacklogItems for our product, we often refer to "the important ones" and the "nice to haves". For us, important BacklogItem has a BusinessValue L or XL (I like to use t-shirt sizes).

So I extend my BacklogItem with a method IsImportant():

public bool IsImportant()
{
     return BusinessValue == BusinessValue.L || BusinessValue == BusinessValue.XL;
}

So I can issue this query to RavenDB:

var important = _session.Query<BacklogItem>().Where(bli=> bli.IsImportant()).ToList();

Unfortunately, if I try to query my BacklogItems with RavenDB, the RavenQueryProviderProcessor doesn't like that I’m trying to query a method and throws a NotSupportedException when building a Lucene query from my Linq query

Still thinking how I can make it work...

Tags:

.net | RavenDB

Password hashing with BCrypt in .net

by Stijn Volders 29. February 2012 18:38

A while ago, Davy Brion blogged about the problems when storing credentials in clear text. You can read in his post why this is a bad idea.

Luckily, you can do it right with almost no effort. Instead of saving the password (or an encrypted version), you generate a hash from the password and a unique salt value and store that hash value in your database.

To generate a hash, I used BCrypt. BCrypt is adaptive, meaning that you can configure the resources required to create/test a hash. It’s important that testing a hash is not too fast to prevent brute force cracking attempts.

Using BCrypt is very straightforward:

var salt = Core.BCrypt.GenerateSalt(11);
var hash = Core.BCrypt.HashPassword("My secret passphrase", salt);

You can download the source code here

Tags:

.net | Security

Saturday night programming: 'Shoot'

by Stijn Volders 23. January 2012 23:44

Last Saturday I had fun building a little tool for personal use.

Let me first explain what I needed:

The TomTom website (http://routes.tomtom.com) can calculate an itinerary with real time traffic info. Since I'm going to Austria in a few weeks, I want to know how long this trip will take me, average traffic delay at that time of the day included (4 pm). I know that I can specify a specific date and time, and one could assume that this is calculated against their historical data but that's not the case.

There are several options to get this information (manually open the site every day, parse the webpage at a given time automatically, take a screenshot automatically, ...), I went for the screenshot approach because this gives also visual info about the itinerary (the site can avoid parts with much delay).

'Shoot' is a WinForms application that loads the TomTom webpage of my interest (it accepts a command line argument '/url='), takes a screenshot of that page and saves it to the “Shoot” folder on the desktop. It's not the most beautiful design (no MVP or MVC here) nor the most recent technology, but it gets the job done.

To take the screenshot, I’ve used James Crowley’s code.

So, now I can schedule 'Shoot' with Task Scheduler to,take a screenshot every day and build an archive with traffic info for my itinerary:

image  image

A screenshot of the application:

image

The source code can be found on my GitHub account. The application can be downloaded here

Tags: ,

.net

Agile .net 2011– Retrospect

by Stijn Volders 27. October 2011 12:50

2 weeks ago I attended Agile .net 2011. A short summary of the sessions I’ve attended:

Keynote

Normally Jason Gorman was going to do the keynote. I don’t know the guy, but I’m glad he was replaced by Jon Jagger who did an agile A-Z session.

I love the ‘soft’ side of software development a lot. People, process, motivation,… are things that I find intriguing and guys like Jon can inspire me a lot… more on that later Glimlach

NuGet for the enterprise

Maarten and Xavier talked about NuGet, Microsoft’s package manager. It was nice to see some of the solutions that are available to tackle specific enterprise problems and I would seriously consider using NuGet on a new project.

Automated deployment is another use case for NuGet, one that I didn’t knew about. Octopus deploy looks very promising for this purpose!

Kanban 1’s game

You can find the instructions for the game on Jon’s site. The basic idea is to simulate a Kanban environment (4 queues) and do sprints of 2 weeks (10 days). During the game some of the rules change and velocity of the team is being measured. The insights I got out of it:

  • As soon as we had to check our user stories on bugs, large stories didn’t got out of the door.
  • When we tried to get the work done at the end of a sprint (let’s say day 8, 9 and 10) by putting extra resources on queue 4, we got a very low velocity in the next sprint

I hadn’t played agile games before, but after this one (and ‘Theory of Constraints’ on day 2) I’m convinced that these games can have a huge impact and value in software development.

Babysteps with node.js

Node.js is hot these days. Some great .net developers that I respect are blogging and tweeting about it but I couldn’t tell why it’s so cool and fancy. I hoped that this session would bring me the answer.

There is no heavy setup involved to get Node.js running and I managed to keep up with Jan’s code on the screen to get some of the demos running on my machine. While that impressed me (try to get a .net program running in less than 5 minutes on a machine without Visual Studio pre installed), I still miss the point I think. To me it’s still “writing Javascript in a very basic tool (I’ve used Sublime) and if something goes wrong you’re all on your own”.

I must say that the session before took a bit too long, so it’s possible that I’ve missed an important part of the introduction. So I still haven’t found what I’m looking for[s1] . If you, Dear Reader, know the answer, please let me know!

Executable specifications in action

Another hands-on session. Vagif Abilov showed us the basics of BDD (Behavior Driven Development). I had zero experience with BDD so for me it was important to understand what BDD is all about and get to know some of the tools and resources.

What I’ve learned:

  • BDD is based on TDD, but with much more emphasis on the expected behavior. This behavior is described using the Gherkin language (“Given”, “When”, “Then”), understandable to the business people.
  • SpecFlow is an open-source .net BDD tool. Vagif showed SpecFlow in action during the session. Certainly something I want to test on a pet project in the future!

If you want to take a look at BDD in action you can check Vagif’s example on his GitHub account.

Introduction to RavenDB

RavenDB is an open-source document database. The session was presented by Rob Ashton (also a contributor to RavenDB) in a very amusing and entertaining way.

Rob walked us through the basics to get RavenDB up and running, Raven DB Management Studio and the API and went into the details of raven queries and indices. Modeling and more advanced stuff was held for the afternoon session but unfortunately I couldn’t attend that one because of a conflict in my session schedule.

If anyone has some notes from that session to share, let me know!

Theory of constraints – bottleneck game

The afternoon of the second day started with the Theory Of Constraints bottleneck game. Just as in the “Kanban 1’s game” on day one I saw the great value of these games in software development and I can recommend everyone to try this at work if your co-workers are open minded.

Domain Driven Design from the trenches

I have been following Yves Reynhout on Twitter for a while now and he’s one of the few guys in the Belgian .net community that is doing Domain Driven Design on his day job (or at least that I’m aware of) so I was very interested in his ideas, opinions and remarks.

The session touched a little bit of everything, and there is a lot in DDD. Since I’m reading the blue book I could keep up fairly well, but there wasn’t a lot of time to go in depth. Fortunately Yves is a very kind person I had the opportunity to ask him (a lot) afterwards. I’ll try to write the most important stuff I learned in a future blog post.

The Agile Mindset

Yves Hanoulle closed this great conference with a great closing keynote. The same session was given at Lean & Kanban 2011 and is available online.

Conclusion

I didn’t have special expectations for this conference, except it wouldn’t be a typical .net conference but I couldn’t have dreamed that I would have so much fun, seriously!

I’ve spoken with interesting people. I’ve learned a ton, both technical and on the soft side and I got some new ideas for the future.

I hope to see you at Agile .net 2012!

Tags:

conference | learning | .net

I'm going to Agile.NET 2011

by Stijn Volders 5. October 2011 23:23

Next week, I'm going to Agile .NET 2011 (http://www.agileminds.be/event/5 ). One of the guys at Agileminds used to be my lector and brought this event to my attention.

Despite the name, there are not many session specific to .net development.

At the moment this is how my schedule looks:

Day 1

  • Slow & Dirty (Keynote)
  • Organize your chickens: NuGet for the enterprise (Workshop)
  • Kanban 1's game (Serious games)
  • Taking baby steps with node.js (Workshop)
  • The Refuctoring Challenge (Workshop)

Day 2

  • Introduction to RavenDB (Workshop)
  • Tackling Complexity Through Collaborative Play (Serious games)
  • Domain Driven Design - a perspective from the trenches (Workshop)
  • Cyber dojo: Deliberate Software Team Practice

If you're going too, let me know, it's always fun to meet people at a conference!

Tags:

conference | .net | learning

My Entity Framework Code First talk at CVO Antwerpen

by Stijn Volders 17. May 2011 11:14

Yesterday I presented my Entity Framework Code First session at CVO Antwerp. CVO Antwerp is a school for higher education in IT. The students of some of the programming classes attended the session, as well as some old students & teachers. It was fun to see some familiar faces (I graduated there) and I had fun presenting. I hope the attendees liked it too.

The slides and the demo projects can be downloaded here: http://bit.ly/m5ng6E

If you attended, please take a minute to let me know how I did at SpeakerRate. If you have another minute, write down what you liked or didn’t like! Thanks!

Tags:

Code First | Entity Framework | Speaking