Oh btw., if you’re thinking of going to Software Passion Summit 2012 in Göteborg, you should use the promotion code MOGENS when you register – you’ll get a 10% discount with this bad boy.
Category: void
I’ll be in Göteborg on my birthday
This is just to say that on the 19th of March (and the 20th as well), I’ll be in Göteborg at Software Passion Summit 2012.
On the 19th (my birthday), I’ll do my “Frictionless Persistence in .NET with MongoDB” talk, which is just awesome!
I love talking about these things, so it’s a real treat to get to do that in an exciting new conference.
2011 retrospective and 2012 resolutions
In the same vein as last year, I’ll spend a post summing up on what happened this year, and then try to come up with some goals for the next year.
2011 retrospective
What did I do in 2011? Well, I
- Wrote 27 blog posts (+ this one = 28).
- Gave my “Frictionless Persistence in .NET with MongoDB” talk at Goto Copenhagen. Great experience, and Microsoft even recorded it.
- Gave the talk again as a free geek night.
- Hosted an Aarhus .NET User Group code camp on MongoDB.
- Gave the Frictionless talk again, this time at an Odense .NET User Group meeting.
- Made tiny contributions to Castle Windsor and MassTransit.
- Started building an NServiceBus-like service bus: Rebus. It already has pub-sub messaging and sagas 🙂
- Attended Udi Dahan’s “Advanced Distributed Systems Design With SOA” course. Udi was no stranger to me as I have been following his work, but the course presented some extremely interesting ideas on how to build a service-oriented architecture.
- Spent most of my time monkeying around with code and architecture on the PowerHub project, which is getting more and more serious. Oh, did I mention that the system’s regulation parts have zero downtime? With a nifty master-slave setup with automatic failover, PowerHub can continue to optimize and control local units, even in the face of system and platform upgrades… 🙂
- Got a new job!!! Yes, that’s right: The 30th of December 2011 will be my last day as a Trifork Software Pilot! On January the 2nd in the new year, I’ll join d60 as a consultant. This fact deserved a dedicated blog post. 🙂
- Had my photo of a hard-wired hairdryer included in Mark Seemann’s book about DI in .NET (see page 8 in chapter 1). Needless to say, this photo went right into my slidedeck 🙂
If I compare that to my 2011 resolutions, I think I’m only missing a “real” pet project. The closest thing is PriorityQ, which I made as an example app for my MongoDB presentations – it’s a “question collector” that can be used during presentations.
2012 resolutions
This is what I’d like to do in 2012:
- Gain a footing in my new position, and help out with some of the company’s challenges.
- Attend a couple of conferences – in passive as well as in active mode.
- Contribute some more to some of the OSS projects I like – including my own.
- Put Rebus to (some serious ab)use.
and, most importantly – just like my 2011 resolutions – I’d like to continue to be inspired by communicating with smart people.
Lastly, I will express my feelings in the form of an animated GIF that reeks of 1996: Now, let’s see what 2012 brings…
New job!!
As I’m writing this, I have spent 4 years and 9 months working at Trifork. That means a majority of my professional experience comes from working there, and I must say that it has been a fantastic time!
Throughout the years, I have been allowed to work on interesting projects, attend conferences, speak, teach, and play, and thus continually be challenged – and almost be forced to grow.
When I read Chad Fowler’s “My Job Went To India” (which later became “The Passionate Programmer”), the “Be The Worst” chapter immediately made sense to me, because I think that pretty much describes me when I started working with Trifork. If you haven’t read it, please do yourself a favor and do it – it’s available online.
As Chad puts it: “The people around you affect your own performance. Choose your crowd wisely”.
So, if you’re looking for an inspiring environment and some extremely talented colleagues, Trifork is definitely a great place to be. Especially as a .NET developer, I think Trifork can offer a healthy exposure to Java, ObjectiveC, Riak, Erlang, Ruby, and more non-.NETty things, which I think has helped me become more wholistic in my views on technology.
After almost 5 years however, I feel it is time to seek new challenges.
So, on Januar 2nd 2012 I’ll join d60, which is a fast-growing Microsoft-based consultancy agency on the outskirts of central Aarhus. d60 is just about equally split between systems development and business intelligence, so hopefully I’ll gain some insight in BI, which I think will help me build better systems. At d60 I’ll continue working as a software development consulatant, and hopefully I’ll continue to communicate with smart people about software development and help building cool solutions to real world problems.
Mocking IEnumerable and IEnumerator with NMock2
Edit: This post is actually about a weird NMock error message. As Nigel Thorne so kindly pointed out, this way of testing an IEnumerable is kind of awkward and cumbersome, as I should have just done something like this:
1 2 3 |
Stub.On(someObjectContainingOccurrences) .Method("GetOccurrences") .Will(Return.Value(new DateTime?[]{ /* some values in here */ })); |
Please use this approach, unless your test subject is actually the implementation of the
foreach construct 😉
Original post:
A recent problem I had was when I attempted to mock a function returning an
IEnumerable<T>. I went about and punched in somthing that I expected to work – something like this:
1 2 3 4 5 6 7 8 9 10 11 |
var enumerator = mocks.NewMock<IEnumerator<DateTime?>>(); Stub.On(enumerator).Method("Dispose"); var enumerable = mocks.NewMock<IEnumerable<DateTime?>>(); Stub.On(enumerable) .Method("GetEnumerator") .Will(Return.Value(enumerator)); Expect.Once.On(someObjectContainingOccurrences) .Method("GetOccurrences") .Will(Return.Value(enumerable)); |
– and then I set some expectations on the usage:
1 2 3 4 |
Expect.Once.On(enumerator).Method("MoveNext"); Expect.Once.On(enumerator).GetProperty("Current").Will(Return.Value((DateTime?)new DateTime(2003, 11, 12))); Expect.Once.On(enumerator).Method("MoveNext"); // [...] stuff like that... |
– and the usage inside my class under test was something like this:
1 2 3 4 |
foreach(var occurrence in someObjectContainingOccurrences.GetOccurrences()) { // do stuff to the occurrence in here } |
– but then I ran the test, and I got this cryptic error message:
1 2 3 4 5 6 7 8 |
System.Runtime.Remoting.RemotingException: ByRef value type parameter cannot be null. at System.Runtime.Remoting.Proxies.RealProxy.ValidateReturnArg(Object arg, Type paramType) at System.Runtime.Remoting.Proxies.RealProxy.PropagateOutParameters(IMessage msg, Object[] outArgs, Object returnValue) at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(ref MessageData msgData, Int32 type) at System.Collections.IEnumerator.MoveNext() at System.Collections.IEnumerator.MoveNext() [...] |
This was really annoying! Especially due to the fact that the foreach prevented me from seeing what was actually going on. It took me a few minutes to realize that the error came from me being too sloppy to check out the IEnumerator interface I was mocking – the interface looks like this:
1 2 3 |
void Reset(); bool MoveNext(); object Current { get; } |
(where the generic IEnumerator<T> interface inherits from IEnumerator, narrowing the return type of the Current property down to objects of type T).
Can you spot the error?
The return type of MoveNext is bool!!!
When I am mocking a method call like this:
1 |
Expect.Once.On(enumerator).Method("MoveNext"); |
NMock will check the method signature – and if the signature has a return type other than void, NMock tries to be nice and – instead of emitting an error (which IMO would be appropriate) – returns null! And since null is a reference type, but the expected type was bool, I got the cryptic RemotingException.
The solution was obvious:
1 |
Expect.Once.On(enumerator).Method("MoveNext").Will(Return.Value(true)); |
PS: I am posting this to avoid having this problem again (for too long). I remember having had this error before, but it took me almost 30 minutes to realize what was wrong. Hopefully, next time I will remember 🙂
Yet another blog about coding
Greetings! Welcome to yet another coding blog!
There are so many coding blogs out there, so what is my justification for starting a new one? I believe that it is important that a blog has some kind of thematic, or else it will become this anonymous stream of nothingness that noone will read.
Having said that, I am sorry to admit that I have yet to come up with a theme for this blog. My plan is to post whatever comes into my mind, and then, hopefully, the blog will converge towards something meaningful. I do know, however, that I will be posting mostly C# code, perhaps mixed with a bit of Ruby.
So for now, it will serve a simple purpose as an outlet for my thoughts on coding… – though it would not hurt if someone besides me read it… 🙂