<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Olsenius.com</title>
  <id>http://127.0.0.1</id>
  <updated>2011-01-20T00:00:00Z</updated>
  <author>
    <name>Andreas Lien Olsen</name>
  </author>
  <entry>
    <title>NUnit RuntimeBinderException when checking for null inside dynamic types</title>
    <link href="http://127.0.0.1/2011/02/13/nunit-runtimebinderexception-when-checking-for-null-inside-dynamic-types/" rel="alternate"/>
    <id>http://127.0.0.1/2011/02/13/nunit-runtimebinderexception-when-checking-for-null-inside-dynamic-types/</id>
    <published>2011-02-13T00:00:00Z</published>
    <updated>2011-02-13T00:00:00Z</updated>
    <author>
      <name>Andreas Lien Olsen</name>
    </author>
    <summary type="html">&lt;p&gt;This week I stumbled upon a weird error when merging some NUnit test classes. We have some mappers that need to handle several versions of messages we send and receive. The messages contain classes generated from .xsd files. Different versions have the same names and are almost identical, but live in different namespaces. For every message version there is a mapper to map to and from the internal object structure&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;This week I stumbled upon a weird error when merging some NUnit test classes. We have some mappers that need to handle several versions of messages we send and receive. The messages contain classes generated from .xsd files. Different versions have the same names and are almost identical, but live in different namespaces. For every message version there is a mapper to map to and from the internal object structure.&lt;/p&gt;

&lt;p&gt;The tests covering mapping of v1.Message and v2.Message to internal.Message are almost identical. Instead of having duplicate tests I moved the tests into an abstract test class with dynamic methods for creating the mapper and test data. Then I sub classed the base overriding the needed methods to generate objects in the different namespaces. This way we can write the tests only once, and duplicate only the abstract methods that need to reference the different namespaces.&lt;/p&gt;

&lt;p&gt;I did this without problems on several test classes, but then I stumbled upon an error I haven&amp;rsquo;t seen before when running the tests.&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;Microsoft.CSharp.RuntimeBinder.RuntimeBinderException : The call is ambiguous between the following methods or properties: &#8216;NUnit.Framework.Assert.That(NUnit.Framework.Constraints.ActualValueDelegate, NUnit.Framework.Constraints.IResolveConstraint)&#8217; and &#8216;NUnit.Framework.Assert.That(NUnit.Framework.TestDelegate, NUnit.Framework.Constraints.IResolveConstraint)&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;One test failed for every mapper it tested. The test was checking that a value was set to null. Below is a sample that will produce this error.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::cs
using System;
using NUnit.Framework;

namespace NUnit_dynamic_null_test
{
    [TestFixture]
    public class DynamicNullTest
    {
        private dynamic _someClass;

        private static dynamic CreateSomeClass()
        {
            return new SomeClass();
        }

        private class SomeClass
        {
            public string SomeThing { get; set; }
        }

        [SetUp]
        public void SetUp()
        {
            _someClass = CreateSomeClass();
        }

        [Test]
        public void Some_thing_Is_null()
        {
            Assert.That(_someClass.SomeThing, Is.Null);  //Microsoft.CSharp.RuntimeBinder.RuntimeBinderException
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The error message let us know that there are two possible overloads in NUnit, and the C# runtime fails because it does not know which one to use. The simplest way to get the test to pass is to rewrite it to use Assert.Null() instead of Assert.That().&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::cs
[Test]
public void Some_thing_Assert_null()
{
    Assert.Null(_someClass.SomeThing); //Ok
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The error message also hints to another possible fix. If we cast the value to a reference type the runtime knows what over load to use, and will not fail.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;:::cs
[Test]
public void Some_thing_casted_to_reference_type_Is_null()
{
    Assert.That((object)_someClass.SomeThing, Is.Null);  //Ok
    Assert.That((string)_someClass.SomeThing, Is.Null);  //Ok
    Assert.That((Exception)_someClass.SomeThing, Is.Null);  //Ok
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This last approach does not look as good as the Assert.Null() approach. It will also fail for non nullable value types. These cannot be casted, and will cause a compilation failure. I settled with the Assert.Null() approach in my test.&lt;/p&gt;

&lt;p&gt;A full example can be found at &lt;a href="https://github.com/Olsenius/NUnit-dynamic-null-test"&gt;github&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>2011-Year of the web</title>
    <link href="http://127.0.0.1/2011/01/22/2011-year-of-the-web/" rel="alternate"/>
    <id>http://127.0.0.1/2011/01/22/2011-year-of-the-web/</id>
    <published>2011-01-22T00:00:00Z</published>
    <updated>2011-01-22T00:00:00Z</updated>
    <author>
      <name>Andreas Lien Olsen</name>
    </author>
    <summary type="html">&lt;p&gt;This year I want to focus on web development. I believe that the web is a future that I want to be a part of. In my day job I develop desktop applications; therefore I don&#8217;t have much experience writing web applications&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;This year I want to focus on web development. I believe that the web is a future that I want to be a part of. In my day job I develop desktop applications; therefore I don&#8217;t have much experience writing web applications.&lt;/p&gt;

&lt;p&gt;All my previous encounters with web development have been on the &lt;a href="http://en.wikipedia.org/wiki/LAMP_(software_bundle)"&gt;LAMP&lt;/a&gt; stack. This has been out of convenience. As a student I did not want to pay for an expensive windows server when I could share a Linux box for almost nothing.&lt;/p&gt;

&lt;p&gt;This time I want to focus my energy on &lt;a href="http://www.asp.net/mvc"&gt;ASP.NET MVC&lt;/a&gt;. I will probably also play in Ruby, but MVC will be my main focus. I choose MVC because I think this is the de facto standard for new web projects in the .Net space these days. (I&#8217;ll leave the MVC vs. Web Forms discussion up to someone else than me.)&lt;/p&gt;

&lt;p&gt;I work best when I have a real project to play with. Sitting down just to learn something is not my strongest side. When I hear about something new I always think of how I can use this to fix some problem or do a specific job that needs to get done. I don&#8217;t have any real world projects on my mind now. Therefore I choose another way.&lt;/p&gt;

&lt;p&gt;Last year I started on a path to become a Microsoft Certified Professional Developer (MCPD), Enterprise Applications Developer 3.5. I bought the first book, and had my mind set to try to go the whole way (6 exams) in a couple of months. Unexpected things happened, and instead I used several months on the first book. As the new year approached the .Net 4.0 exams were starting to pop up.&lt;/p&gt;

&lt;p&gt;I switch my focus onto MCPD web developer 4. This is only &lt;a href="http://www.qa.com/media/919763/ms%20visual%20studio%202010%20and%20.net%204.pdf"&gt;4 exams&lt;/a&gt;, and I hope to take them all this year. I start with the &#8220;Web Applications Development with Microsoft .NET Framework 4&#8221; exam (70-515), and plan to learn enough Web Forms and MVC2 to take this exam before the summer. I have chosen to use the &lt;a href="http://www.cbtnuggets.com/series?id=630"&gt;training videos&lt;/a&gt; by cbtnuggets.com to help me prepare for the exam. I might have to buy the book too, time will show.&lt;/p&gt;

&lt;p&gt;In addition to the certification path I hope to find a fun &#8220;real&#8221; project to do. If you got any ideas feel free to give me some inspiration.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title>2010 in review</title>
    <link href="http://127.0.0.1/2011/01/20/2010-in-review/" rel="alternate"/>
    <id>http://127.0.0.1/2011/01/20/2010-in-review/</id>
    <published>2011-01-20T00:00:00Z</published>
    <updated>2011-01-20T00:00:00Z</updated>
    <author>
      <name>Andreas Lien Olsen</name>
    </author>
    <summary type="html">&lt;p&gt;I have been thinking about blogging for a while now. The start of a new year seemed like a perfect starting point. I wanted to start with a quick summary of 2010 and then write up some goals and plans I have for 2011&amp;hellip;&lt;/p&gt;
</summary>
    <content type="html">&lt;p&gt;I have been thinking about blogging for a while now. The start of a new year seemed like a perfect starting point. I wanted to start with a quick summary of 2010 and then write up some goals and plans I have for 2011.&lt;/p&gt;

&lt;p&gt;As I wrote the quick summary it got a bit bigger than anticipated. I don&amp;rsquo;t want to drown my plans for the next year at the bottom of a long post. Instead I&amp;rsquo;ll write them up in a new post.&lt;/p&gt;

&lt;h2&gt;2010&lt;/h2&gt;

&lt;p&gt;In the beginning of 2010 I was very into unit testing. I had heard much good about testing, and believed it would be good to introduce it at work. I read loads of articles/books and had many good discussions about testing with my co-workers, friends and others. Unfortunately I haven&amp;rsquo;t saved any of the articles I read, but I absolutely have to point out two books that helped me a lot.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The first book is &lt;a href="http://www.manning.com/osherove/"&gt;The Art of Unit Testing with Examples in .NET&lt;/a&gt; by Roy Osherove. I think this is a very good book to read when you first get started with unit testing in the .NET world. The books include many usable examples and explain in a good way the concepts of unit testing.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The second book is of course &lt;a href="http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052"&gt;Working Effectively with Legacy Code&lt;/a&gt; by Michael Feathers. This is like the bible for testing legacy code. Armed with this book you get several tricks under your belt to start unit testing seemingly untestable code.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;I left my old job in the middle of summer. I didn&amp;rsquo;t want to abandon my &amp;ldquo;testing child&amp;rdquo; at the old place, but when I got the opportunity to work with so many skilled and friendly people it was really nothing to think about!&lt;/p&gt;

&lt;h3&gt;Summer time&lt;/h3&gt;

&lt;p&gt;I spent most of my vacation in the new family vacation house at Goddo, B&#248;mlo. The place is new, and there is always something that needs to get done or some fish in the sea to catch.&lt;/p&gt;

&lt;p&gt;In the end of the summer I went on a kayak trip with my brother for a little week. It was a great trip, and it is what I remember best from the summer. It was really relaxing to spend some time away from everything. It was just me, my brother, two kayaks, a tent, food and drinks.&lt;/p&gt;

&lt;h3&gt;New job, new opportunities&lt;/h3&gt;

&lt;p&gt;After the summer I started as a consultant in &lt;a href="http://www.miles.no"&gt;Miles&lt;/a&gt;. Joining Miles must be the best decision I made last year. The people in Miles are very friendly, and skillful at what they are doing. I am looking forward to learn a lot from them (and hopefully give something back).&lt;/p&gt;

&lt;p&gt;The first weekend after I started all of us went on a 5 years anniversary trip to London. We stayed at &lt;a href="http://www.pennyhillpark.co.uk/EXCLUSIVE_HOTELS/the_hotel.aspx"&gt;Pennyhill Park Luxury Hotel &amp;amp; Spa&lt;/a&gt;, where I got the chance to get to know many of my new colleagues. I can really recommend a luxury hotel and spa for team building whenever a new guy joins;&amp;ndash;).&lt;/p&gt;

&lt;h3&gt;The bad&lt;/h3&gt;

&lt;p&gt;After a concert in September I was a victim of blind violence. A guy hit me unprovoked as I and a friend left the concert. It resulted in 3 scars around my eye, 17 stitches and a broken &lt;a href="http://en.wikipedia.org/wiki/Orbit_(anatomy)"&gt;Orbita&lt;/a&gt;. The muscles located below the eye fell down into the &lt;a href="http://en.wikipedia.org/wiki/Paranasal_sinuses"&gt;Paranasal sinuses&lt;/a&gt;. This resulted in double vision as the left and right eye didn&amp;rsquo;t move in unison.&lt;/p&gt;

&lt;p&gt;On my 25'Th birthday I had surgery. They placed a silicone plate where the broken bone should have been. Not the best birthday I can remember, but at least I seriously doubt ill forget my 25'Th birthday:&amp;ndash;/. The vision got much better, but was still not good.&lt;/p&gt;

&lt;p&gt;In December they had a new go at it with a metal reinforced silicone plate. The vision got even better, but still not perfect. It looks like I&amp;rsquo;ll have to live with double vision when looking down for the rest of my life&amp;hellip;&lt;/p&gt;

&lt;h2&gt;Smidig2010&lt;/h2&gt;

&lt;p&gt;In November I was at the &lt;a href="http://smidig2010.no/"&gt;Smidig 2010&lt;/a&gt; conference in Oslo. The conference is about &lt;a href="http://en.wikipedia.org/wiki/Agile_software_development"&gt;agile software development&lt;/a&gt; (smidig = agile in Norwegian). The conference is all about lightning talks and open spaces where you can discuss what interests you with other like-minded people.&lt;/p&gt;

&lt;p&gt;The lightning talk that got me thinking the most was &lt;a href="http://streaming.java.no/tcs/#page:recordingList&amp;amp;pageNumber:1&amp;amp;id:728922D9-1061-4973-804A-CA3CFA28CEF7"&gt;&amp;ldquo;Om det fungerar &amp;ndash; g&#246;r mer av det!&amp;rdquo;&lt;/a&gt; by Andreas Larsson. He talked about the effect of asking the right questions. Focusing on the good parts instead of asking what went wrong. I should have seen this video earlier!&lt;/p&gt;

&lt;p&gt;The 2011 post I mentioned earlier is about to follow soon. Just have to write it first.&lt;/p&gt;
</content>
  </entry>
</feed>
