When to put things in your calendar

When you put a date on something, it gets scheduled into your calendar. This is a hard reminder not a soft one, it is a ‘It must happen on this day/time, or not at all’ requirement. There should be no exceptions to this rule, your calendar is sacred. Take the dates off any items that don’t absolutely have to happen at that date and time. Instead, get those items into the appropriate next action context lists and just know that you will do them in due course and that they are safely tracked in the correct place.

Japanese update

I haven’t done any audio training as such but I did start doing some Japanese immersion, listening to Japanese radio and doing some talking with my wife and mum in law. I have definitely improved a little bit and will continue to keep on with immersion techniques rather than specific training. The simple idea of trying to communicate with my mum in law without dropping into English was brilliant and I definitely felt we communicated several times quite well – the idea behind this being, what would I do to communicate with someone Japanese if English didn’t exist, there would be no options of dropping into English and there would be no translating from Japanese into English, just translating from Japanese (and non verbal communication) into pure understanding. I’ll post again about my progress soon.

New project: Learn enough Japanese to be able to hold down conversations about topics I like with a native Japanese speaker within 6 months.

How am I going to achieve this? Not completely known at the moment – Michel Thomas method will get me started, also interested in trying to get some understanding of Japanese TV shows and films (suggestions welcome). Everytime I go to Japan, I can kind of get by, but I can’t chat to people and I want to be able to chat to people, so that’s exactly what I’ll be doing.

BDD for BizTalk Maps

There are a variety of ways to test BizTalk maps from xml strings, file comparisons, xpath queries, excel based tests etc but my preferred method is with typestrong c# classes, just like this:-

  • Use a prebuild event to run xsd.exe /classes against source and target schema xsd.
  • Turn on unit testing for Maps in the BizTalk visual studio project
  • Create a new source instance object
  • Serialise the instance to an input xml file on disk
  • Create a new instance of your map (TestableMapBase) and call TestMap() method
  • Take the serialised output file and deserialise into the target schema class
  • Assert the values of the target instance against the source values

It’s simple, it’s type strong, it lends itself well to TDDing and makes the whole mapping experience and testing your maps more robust (and fun).

This is a technique I have used before with Mike Stephenson and he details it very well here in this post: More on Map Testing

With this in mind, I found that while it is effective, there is a lot of Setup each time just to test a map and I wanted to create something reusable so that all I need to know is my Source and Target Type and map Type (when map inherits from TestableMapBase – ie enable unit testing in the assembly properties), then simply setup a source object, have map auto execute and then check the output, while keeping all the plumbing and noise (which is the same each time) hidden away. This then allows you much more flexibility to actually Test Drive your map rather than throw in a few tests or a full xml string to test the output once you’ve already made your map.

Using a BDD approach, I came up with a MapSpecification base class. The code below is the usage of this API to show how your end result tests look when using this base class effectively:-

(comments here are just to help explain it, obviously you’d never have comments in production code.)


using NUnit.Framework;

namespace IntegrationTests.Maps
{
    public abstract class In_to_Out_Specification
        : MapSpecification<In_to_Out_Map, InSchema, OutSchema>
    {
         // this is your marker class to indicate we are testing In_to_Out_Map
    }

    public abstract class WithBasicValues : In_to_Out_Specification
    {
        // this is the context class we'll use for a set of asserts
        protected override InSchema CreateSourceObject()
        {
            return new InSchema
            {
                firstName = this.firstName,
                middleName = this.middleName,
                lastName = this.lastName
            };
        }
    }

    [TestFixture]
    public class when_mapping_from_In_to_Out : WithBasicValues //inherit from this context
    {
        //one test fixture per context (or input value set)

        [Test]
        public void FirstName_should_map_directly()
        {
            Assert.That(the_output.FirstName, Is.EqualTo(the_input.FirstName));
        }

        // with several tests - one per field or attribute with a single assert in each

        [Test]
        public void MiddleName_should_map_directly()
        {
            Assert.That(the_output.MiddleName, Is.EqualTo(the_input.MiddleName));
        }

        [Test]
        public void LastName_should_map_directly()
        {
            Assert.That(the_output.LastName, Is.EqualTo(the_input.LastName));
        }

        [Test]
        public void FullName_should_be_firstname_space_middlename_space_lastname()
        {
            Assert.That(TheOutput.FullName, Is.EqualTo(
                 string.format("{0} {1} {2}", the_input.FirstName, the_input.MiddleName, the_input.LastName);
        }
    }
}

As you can see, the tests are very clean and it allows you to create a different context if you want to test the map with different values, eg edge cases and things like that – in my example I just had a context class of WithBasicValues which you inherit from in your test fixture. To have another scenario, you just create another abstract context class like this overriding CreateInput() and returning different values for the input message, then you have a test fixture that inherits from that context and perform your asserts as appropriate for that context.

MapSpecification base uses trickery of using the Setup method to actually do the plumbing and execute the map, it also has another advantage of allowing us to only run the Act (from Arrange Act Assert) once and then do multiple checks even though there is granularity that each test is a separate Test method – this keeps it performant while at the same time allowing us to see very quickly where a mapping error is if a test goes red.

Below is the code listing of the MapSpecification so you can try it for yourself. Note: you need to reference Xlang Basetypes dll as well as the TestTools dll and enable Unit testing on your map assembly. You also need a .net class for the source and target schema which can be created with xsd.exe sourceschema.xsd /classes and xsd targetschema.xsd /classes (I add this as a prebuild event so that it gets compiled and immediately available in the tests and can never get out of sync with your schemas.


using System;
using System.IO;
using System.Xml.Serialization;
using Microsoft.BizTalk.TestTools.Mapper;
using Microsoft.BizTalk.TestTools.Schema;
using NUnit.Framework;

namespace IntegrationTests.Maps
{
    public abstract class MapSpecification<TMap, TSourceSchema, TTargetSchema>
        where TMap : TestableMapBase, new()
        where TSourceSchema : class
        where TTargetSchema : class
    {
        private bool hasExecuted = false;
        private readonly string inputFilePath = "input_{0}.xml".FormatWith(Guid.NewGuid());
        private readonly string outputFilePath = "output_{0}.xml".FormatWith(Guid.NewGuid());

        private TMap the_map;
        protected TSourceSchema the_input { get; private set; }
        protected TTargetSchema the_output { get; private set; }

        [SetUp]
        public void Initialise()
        {
            if (!this.hasExecuted)
            {
                this.CleanupScenario();
                this.the_input = this.CreateSourceObject();
                this.the_map = this.CreateMap();
                this.the_output = this.ExecuteMap();
                this.hasExecuted = true;
            }
        }

        [TearDown]
        public void Cleanup()
        {
            this.CleanupScenario();
        }

        protected virtual TSourceSchema CreateSourceObject()
        {
            throw new Exception(
                "You must override CreateSourceObject in your context class which inherits from this base class.");
        }

        protected virtual void SerialiseInput()
        {
            var serializer = new XmlSerializer(typeof(TSourceSchema));
            using (var streamWriter = new StreamWriter(this.inputFilePath))
            {
                serializer.Serialize(streamWriter, this.theSourceSchema);
            }
        }

        protected virtual TTargetSchema DeserializeOutput()
        {
            var serializer = new XmlSerializer(typeof(TTargetSchema));
            using (var streamReader = new StreamReader(this.outputFilePath))
            {
                return serializer.Deserialize(streamReader) as TTargetSchema;
            }
        }

        private TTargetSchema ExecuteMap()
        {
            this.SerialiseInput();
            this.the_map.TestMap(this.inputFilePath, InputInstanceType.Xml,
                                         this.outputFilePath, OutputInstanceType.XML);
            return this.DeserializeOutput();
        }

        private TMap CreateMap()
        {
            return new TMap();
        }

        private void CleanupScenario()
        {
            if (File.Exists(this.inputFilePath))
                File.Delete(this.inputFilePath);
            if (File.Exists(this.outputFilePath))
                File.Delete(this.outputFilePath);
        }
    }
}

Enjoy

Bang Photo is on the app store

Ok it’s not revolutionary, but it serves a simple purpose – take a photo and it auto attaches to your saved email address. This might sound silly considering you can already do this on your phone, but time and again I find myself going through the 8 click process to take a photo,share,attach to email, address email and send when all I really wanted was the photo in my inbox.

This is v1 of the app and it’s free – get it here

Continuous testing with NCrunch

So – I’m back in .Net world and I’m TDDing / BDDing as usual, except this time I’m not running my tests regularly – they are getting run for me continuously. The experience is phenominal, it’s still red/green/refactor development except the tooling gets out of the way and allows you to just focus on writing your code. I have tried this approach both on my own and in pairing sessions now and I have to say that I feel this tool is just as ubiquitous as Resharper. I can’t remember my .net life before resharper and I’m starting to think that the same will apply for NCrunch, it’s an excellent product.

Setting it up is pretty easy – you install it via the installer and you find a new menu available in visual studio.

Ncrunch menu

Then you enable and you immediately start to see NCrunch running your tests and showing you the results in it’s Tests window – I have taken to leaving this window open on my second screen, separate to my main dev window in visual studio. It has the option to show/hide passing tests/assemblies and show/hide the failing ones – Initially I liked seeing the sea of green on the screen but now I like to see nothing and see red pop up when there are failures.

green

This is a dream for TDD because the very nature of TDD is that you start with writing the test and write only enough code in the test to make it fail, at this point you flick to the code and write only enough code to make it pass, you then refactor if you can allowing the test to stay green, you then go back to the test and do only enough more in the test to make it fail and then you go back and make it green. So this red/green just appearing and disappearing on the right hand screen in sync with your coding is a joy to work with.

But that’s not all, it actually puts black, red and green dots next to your lines of code as you type too so this window (that I leave on the right) just becomes really useful if your changes break things in other tests or maybe integration tests.

Here is a few screenshots of it in action…..

All that’s left to do now is refactor and make the code communicate more without letting test running get in the way.

The rapid feedback is just immense – great product, well done remco

Top Toast became Hot Toast !

Yesterday was a Top Toast day. It wasn’t planned… but suddenly Top Toast burst into life. I looked at the sales figures (as I do everyday) and suddenly Top Toast had boosted in sales – something must have caused this…. I check the app store and found Top Toast was Featured in the App Store as “What’s Hot” in the Lifestyle section…. here is hairy (our resident monkey) to tell us more…. Top Toast is Hot!

What's hot on the app store... Top Toast!

A brand new photo app

Today we started working on a brand new app. This time it’s a bit different, this is going to be a very simple photo tool app that bloggers will love. Today marks the day we start the app – we’re in starbucks, drinking coffee, chilling out and playing with our macs, already we have a really funky icon, some mockup screens using Balsamiq (which is awesome) – I’ll post the photo here soon of the mockups. So now it’s all hands on deck to get this from idea to app store.

This time, I’ll take a bit of time over the code, it’s a much simpler app so this is a chance to keep the code clean and throw in some good practices and bake in some quality from the start with a few tests.

Top Toast Free

A free version of Top Toast has been submitted to the app store to allow people to try it before choosing to buy it. Looking forward to this getting approved to allow people to try it out for free.

Slow carb and Kettlebell swings

I’ve been reading The 4 hour body by Tim Ferris recently and for the last 6 weeks, I’ve been doing the slow carb diet. This is amazing, you stick to the diet for 6 days a week and on the 7th day is a mandatory cheat day where you are allowed anything you want completely guilt free. This seems too good to be true, but so far I’ve lost over 11lbs doing this and I feel like I’ve eating better than ever.

One other thing (according to Tim) that has dramatic effects on both weight loss and muscle gain is Kettlebell swings.

Kettlebell swings are so easy and they are an amazing workout. I’ve started with a 20kg kettlebell bought from Amazon. Then used this instructional video to teach me the proper swing. Kettlebell swings Youtube video.

I’ve started quite conservatively doing 3 sets of 10, but after the workout I feel very good. Feels like I’ve done sit-ups, press-ups, a little run and some stretches. All from 1 exercise. I’ll definitely be introducing this maybe 2 sessions a week for the weeks to come. Today is #4hb cheat day, so exercise done, it’s time to binge eat and go have fun.

←Older