Software Development

TalkTime Now Available!

TalkTimeI’m pleased to announce that my second Windows Phone app is now available in the Windows Phone Store! TalkTime is a free (ad-supported) countdown timer intended primarily for speakers to gauge their time during a presentation or rehearsal. It features:

  • A large digital style display for easy viewing from a distance
  • Color cues for read-free time approximation
  • 8 preset options
  • Custom time entry
  • English and Spanish (Thanks, Esther!)

Even if you’re not a speaker, download it and give it a shot. Use your imagination and let me know what you’re using it for.

Download TalkTime

Download TalkTime

Using LoopingSelector and ILoopingSelectorDataSource

Custom Time EntryThis week I finished and submitted my second Windows Phone app. On one of the pages I wanted to allow users to enter a custom TimeSpan in a manner similar to entering a date or time. Of course, the SDK doesn’t directly provide the controls to replicate that experience so I turned to the LoopingSelector in the Silverlight Toolkit for Windows Phone for help. Unfortunately, documentation is pretty sparse so I’m hoping this can help someone else out.

(more…)

Windows Phone Accent Color Cheat Sheet

I got tired of tracking down the Windows Phone accent color list so I put together this cheat sheet for future reference. This list includes the 10 basic colors from both the 7.0 and 7.1 releases as well as some of the OEM/Carrier specific colors.

The master listing can be found on the Theme Overview page in the Windows Phone Developer Center.

Color WP 7.0 WP 7.1 RGB Hex Example
blue X X 27, 161, 226 #FF1BA1E2
 
brown X X 160, 80, 0 #FFA05000
 
green X X 51, 153, 51 #FF339933
 
lime X   140, 191, 38 #FF8CBF26
 
lime   X 162, 193, 57 #FFA2C139
 
magenta X   255, 0, 151 #FFFF0097
 
magenta   X 216, 0, 115 #FFD80073
 
mango (orange) X X 240, 150, 9 #FFF09609
 
pink X X 230, 113, 184 #FFE671B8
 
purple X X 162, 0, 255 #FFA200FF
 
red X X 229, 20, 0 #FFE51400
 
teal X X 0, 171, 169 #FF00ABA9
 
Others (OEM/Carrier Specific)
nokia blue 16, 128, 221 #FF1080DD
 
orange uk 255, 102, 0 #FFFF6600
 
t-mobile 75, 75, 75 #FF4B4B4B
 

.NET Rocks! Visual Studio 2012 Launch Road Trip in Indianapolis!

.NET Rocks Visual Studio 2012 Launch Road Trip

The details are still a bit sparse on this one but here’s a note to mark your calendar.  On October 8 (Yes, the day after GiveCamp) IndyTechFest presents The .NET Rocks! Visual Studio 2012 Launch Road Trip in Indianapolis!

If you’re wondering what this is all about here you go:

Well, we’ve done it again! We went and rented a big 37′ RV and booked another United States (mostly) Road Trip for the launch of Visual Studio 2012. No charge for admission.

At each stop we will record a live .NET Rocks! show with a guest star, whom we will fly in for the occasion.

Following that, we (Richard Campbell and Carl Franklin) will each do a presentation around building modern applications on the Windows platform. Carl leans toward development and client-side technology and Richard leans toward DevOps and server-side technology.

There will be food, drink, geeking out, and hopefully some alert locals will know of a pub where we can adjourn after the event to continue the conversation.

If you’d like to attend be sure to register.  I’ll update this space with more details as they’re made available.  I hope to see you there!

10/8/2012 Update

I’m a little behind with this update since I was tied up with GiveCamp all weekend but the venue details are as follows:

IndyCoz
7960 Castleway Dr
Indianapolis, Indiana 46250
[Map]

String Calculator TDD Kata in F#

In a recent post I mentioned that I started learning F#.  Over the past few weeks I’ve really started falling in love with the language.  Coincidentally, my team has been incorporating more test-driven development (TDD) into our process and as part of that training Roy Osherov’s TDD Kata 1 was mentioned.  I immediately thought “Hey! Let me try doing that in F# and see how it goes!”  I’ve run through the kata more than a few times now and I’m ready to share my experience with the world. (more…)

[WPF] Formatting Content Controls

Over the past few years I haven’t done much UI work and what little I did was either with a proprietary Web framework or Windows Forms so I’m more than a little behind the curve with WPF. My most recent project has me learning WPF on the fly and although it’s a daunting task and I still have plenty to learn I’m finding it pretty straightforward. Every once in a while though something works completely different than I expect and throws me for a bit of a curve.

One such example just happened yesterday. I was trying to bind and format a value to a Button‘s Content property. I was trying to bind using the same syntax as binding to the Text property on a TextBox:

<Button Content="{Binding Percentage, StringFormat={}{0:P0}}" />

I was surprised though when the value bound properly but wasn’t formatted. After some investigation I learned that controls like Button that inherit from ContentControl can’t be formatted that way. Instead we need to use the ContentStringFormat to achieve the same effect:

<Button Content="{Binding Percentage}" ContentStringFormat="P0" />

With that change the value started showing up as the percentage just like I expected. Lesson learned.

NUnit With F#

Visual F#A few weeks ago I started learning F#. As I moved from the simple examples that were easily executable in F# Interactive or LINQPad though I found myself wanting to write formal unit tests to make sure I was understanding the concepts correctly. I decided to write my tests in F# for more practice and because its syntax makes it an attractive choice but in order to keep the learning curve under control a bit I thought it best to stick with a familiar test framework – NUnit. Using NUnit with F# is pretty trivial but being so new to the language I ran into a few small obstacles.

Importing Types

In order to use NUnit we need to import the types from the NUnit.Framework namespace. Importing the types is accomplished with the open keyword which looks and behaves much like the using directive in C#.

open NUnit.Framework

Don’t get too excited yet though because the compiler is probably yelling at you.

Most F# tutorials that I’ve seen provide examples that are easily run within F# Interactive (FSI), LINQPad, or a single F# Application (exe) project. They generally only include a few types and almost never span multiple files let alone multiple assemblies or languages. This is great for introducing concepts but as soon as you move to a more complex library project (like one for testing) the compiler will politely inform you of a problem depending on where you’ve placed the declaration:

Files in libraries or multiple-file applications must begin with a namespace or module declaration, e.g. ‘namespace SomeNamespace.SubNamespace’ or ‘module SomeNamespace.SomeModule’

If you’ve placed the directive at the beginning of the file before declaring a namespace or declaration you’ll see the above error. To fix this problem I like to take the namespace route because I’m just trying to group my testing types and it follows the organization pattern I’d be using were I writing the tests in C#.

namespace StringCalculatorKata.Logic.Tests

open NUnit.Framework

[]
type StringCalculatorTests() =
  []
  member x.Add_EmptyString_ReturnsZero() =
    // Test Code Omitted
  [<TestCase("1", Result=1)>]
  [<TestCase("2", Result=2)>]
  member x.Add_SingleNumber_ReturnsThatNumber calcString =
    // Test Code Omitted

Applying Attributes

With the types imported we can identify our fixtures and tests. The good news is that we accomplish this with attributes just like with other .NET languages. The bad news is that although it’s simple, it’s not immediately obvious. If you’re reading this you should already know that TestFixtureAttribute applies to the classes that hold your tests and that TestAttribute and TestCaseAttribute identify tests. But how does that translate to F#?

One answer is to define a type and decorate it with the appropriate attributes. You’ll want to make sure you’re applying the test attributes to member bindings rather than let bindings here because let bindings compile to internal members whereas member bindings compile to public members by default.

[]
type StringCalculatorTests() =
  []
  member x.Add_EmptyString_ReturnsZero() =
    // Test Code Omitted
  [<TestCase("1", Result=1)>]
  [<TestCase("2", Result=2)>]
  member x.Add_SingleNumber_ReturnsThatNumber calcString =
    // Test Code Omitted

Were you aware though that since .NET 2.0 you could apply TestFixtureAttribute to a static class as well? If you prefer this approach you can define your fixture as a module since modules compile down to static classes.

[]
module StringCalculatorTests =
  []
  let Add_EmptyString_ReturnsZero() =
    // Test Code Omitted
  [<TestCase("1", Result=1)>]
  [<TestCase("2", Result=2)>]
  let Add_SingleNumber_ReturnsThatNumber calcString =
    // Test Code Omitted

Aside from being a module definition, notice that the attributes are applied to let bindings in the module. Module level let bindings compile to public static members by default.

Assertions

So far I’ve been careful to avoid including assertions in the sample code. Not to worry, assertions in F# are the same as they’d be in any other language but you do need to be aware of a syntactic nuance that affects many of the assertion methods.

In short, the compiler’s overload resolution mechanism requires you call them using a syntactic tuple form (syntax that looks like a tuple but isn’t) rather than the curried form that’s so common in F#. This means that instead of separating the individual parameters with spaces you need to call the method like you would in C#:

type StringCalculatorTests() =
    []
    member x.Add_EmptyString_ReturnsZero() =
        let calc = new StringCalculator()
        let result = calc.Add ""
        Assert.That(0, Is.EqualTo 0)

Of course, if you’re using TestCaseAttribute with the optional Result parameter you’ll be able to eliminate the manual assertion altogether in many cases:

[]
type StringCalculatorTests() =
  [<TestCase("1", Result=1)>]
  [<TestCase("2", Result=2)>]
  member x.Add_SingleNumber_ReturnsThatNumber calcString =
    let calc = new StringCalculator()
    calc.Add calcString

Specifications, Expression Trees, and NHibernate

For my latest project we decided to follow a domain driven approach.  It wasn’t until after we had built out much of the domain model that we decided to change course and embrace CQRS and event sourcing.  By this point though we had already developed several specifications and wanted to adapt what we could on the query side.

(more…)

Moles vs Fakes: The Differences

If you’re a fan of the Microsoft Moles framework you’ve probably heard that it’s being included in Visual Studio 2012 as Microsoft Fakes.  As I was preparing my talk covering this isolation framework I noted some of the key differences between the two.  Rather than going back and updating my original post regarding Moles (much of which is still applicable even with terminology changes) I thought I’d list those differences here.  So without further ado:

  • Assembly generation is driven by a .fakes file rather than a .moles file
  • Isolation types are placed in a .Fakes assembly and .Fakes namespace
  • Shim types replace Mole types
  • Stub types are prefixed with “Stub”
  • Shim types are prefixed with “Shim”
  • ShimsContext replaces HostTypeAttribute for enabling profiling
  • Profiling occurs in the IntelliTrace profiler rather than the Moles profiler
  • Fakes allows shims for static constructors whereas Moles allowed erasing static constructors through an assembly attribute
  • Fakes does not provide any support for finalizers whereas Moles allowed erasing finalizers through an assembly attribute
  • Moles allowed controlling whether the profiler would run as a 32-bit or 64-bit process but this is now handled entirely by the IntelliTrace profiler
  • The “classes” filter attribute was removed.
  • Fakes supports isolating auto-implemented properties
  • Fakes play much nicer with testing frameworks other than MSTest when run through Visual Studio

Faking It Slides Available

Thanks to everyone that attended one of my Microsoft Fakes talks this week. I hope the sessions were beneficial. I just uploaded the slides to SlideShare for you to review at your leisure.

If you attended one of my sessions could do me a quick favor by taking a moment to rate the talk on SpeakerRate?

NUFW (6/12/2012)
IndyNDA (6/14/2012)

Thanks!