Wednesday, 17 August 2011

Unit Testing C# Custom Attributes with NUnit Part 4

In Unit Testing C# Custom Attributes with NUnit Part 3 towards the end I showed the following code
Assert.That(MethodBase.GetCurrentMethod(), 
            Has.Attribute<FunkyAttribute>().Property("SettingOne").TypeOf<int>());
to test the type of a property on an attribute.  As it turns out this does not actually do that.  Instead it tests the type of the value returned from the property.  What's happening is that the object returned from Property() isn't some of meta-object representing a property but is the actual value of the property.

In the case above it amounts to the same thing.  As the property type is an int even if it has not been set the value will be 0 of which type is int.  However, if it's a reference type (quite likely a string) or a nullable type the value can be null.  E.g.

Assert.That(MethodBase.GetCurrentMethod(), 
     Has.Attribute<FunkyAttribute>().Property("FunkyName").TypeOf<string>());

 
Which causes the following when run:

AttrTestV3.FunkyTester.TestThatTheTypeOfFunkyNameWhenNotSetIs_string:
  Expected: attribute AttrTestDefs.FunkyAttribute property FunkyName <System.String>
  But was:  <AttrTestDefs.FunkyAttribute>

It seems that when there is no value Property() which tests for the presence of a the specified property name and implicitly returns the value of the property (if found) has nothing to return so for some reason the attribute type obtained from the call Has.Attribute() is returned.

Currently, there is no way with NUnit to handle this case.  I started a thread on the NUnit discussion group which discusses this issue and it seems like the authors of NUnit have some plans.

As an interim solution if the property is optional for a custom attribute then in the fixture make sure a value is assigned.  In the case above:

[Test]
[Funky(FunkyName = "dummy")]
public void TestThatTheTypeOfFunkyNameWhenNotSetIs2_string()
{
    Assert.That(MethodBase.GetCurrentMethod(),
         Has.Attribute<FunkyAttribute>().Property("FunkyName").TypeOf<string>());
}

I think that's the end again:-)  Here are the links to the previous parts: One, two & three.

Sunday, 14 August 2011

Spectating with Twitter: Twittating or Spectwiting

Today I went to watch (spectate) a small part of the London-Surrey Cycle Classic. Being a 160KM cycle race it wasn't possible to see a lot of it. Even though it featured one of Britain's most prominent and successful cyclists Mark Cavendish the BBC or I suppose any other TV companies chose not to broadcast it live, in fact there didn't seem to be any conventional mainstream live media coverage. Bummer!

However, Twitter to the rescue. There seemed to be several authoritative sources (@cyclingweekly@roadcyclinguk@antmccrossan and @CycleSurrey); presumably travelling with the race or being fed data from someone who was that were Tweeting throughout the race. Given the dearth of information, following these people or  the searches #CycleClassic and/or #testevent was the the only way to find out anything.

I suspect it's how most people were informed of the result; Mark Cavendish won! I was wondering if this was the first time for a major sporting event (unless you're from the BBC)  that the majority of spectators 'watched' via Twitter, i.e. Twittating or should that be Spectwiting! Now this doesn't differ too much from receiving text message updates to a sporting event or just checking the score except that this was largely unofficial and the only available channel.  In addition the community aspect of Twitter generated an almost a stadium like atmosphere albeit virtual.

The lack of live coverage also meant that in addition to no information there were no pictures either. However a lot of the tweets had accompanying pictures and some videos. Whilst not live TV it was something. Even more interesting given the nature of the event: a cycle road race, it meant that the stream of  Tweets was actually charting the progress of the race.

Thinking about this the natural extension is the possibility of broadcasting an event purely by the crowd on Twitter. If there are enough people to cover a course and whatever lag Twitter; and mobile Internet access has doesn't interfere too much then as the race passes the current status along with images could be Tweeted.

This stream could be consumed in real time by a special Twitter client that pulls it together chronologically and importantly will display pictures. These wouldn't be continuous motion (well they could be if the intervals between each Tweeter were short enought) but would give a visual sense of the event.  This is essentially newspaper reporting but in near real time as opposed to live TV which is real time.

One other thought on the basis that the highlights won't be available for a week is that it should be possible to write a program to consume the previously mentioned Twitter searches and pull these together along with the attached pictures and videos to create some sort of watch-able programme.

Thursday, 4 August 2011

A couple of computing jokes

The problem with a UDP joke is that you have no idea if people get it. (from @fearthecowboy)

A SQL query walks into a bar, goes up to a couple of tables and says, "Can I join you?".