Click here to Skip to main content
15,884,298 members
Articles / Desktop Programming / WPF

Catel - Part 4 of n: Unit testing with Catel

Rate me:
Please Sign up or sign in to vote.
4.55/5 (10 votes)
28 Jan 2011CPOL11 min read 48.9K   572   11  
This article explains how to write unit tests for MVVM using Catel.
<ExampleWindows:PersonWindowIntermediate x:Class="Catel.Examples.Silverlight.UI.Windows.PersonWindow"
                                         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                                         xmlns:Windows="clr-namespace:Catel.Windows;assembly=Catel.Silverlight" 
                                         xmlns:Converters="clr-namespace:Catel.Examples.Silverlight.UI.Data.Converters"
                                         xmlns:Controls="clr-namespace:Catel.Windows.Controls;assembly=Catel.Silverlight"
                                         xmlns:ExampleWindows="clr-namespace:Catel.Examples.Silverlight.UI.Windows"
                                         Width="400" Height="300">

    <!-- Resources -->
    <Windows:DataWindow.Resources>
        <!-- Converters -->
        <Converters:GenderToIsSelectedConverter x:Key="GenderToIsSelectedConverter" />
    </Windows:DataWindow.Resources>

    <!-- Content -->
    <Controls:StackGrid>
        <!-- Row definitions -->
        <Controls:StackGrid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Controls:StackGrid.RowDefinitions>

        <!-- Column definitions -->
        <Controls:StackGrid.ColumnDefinitions>
            <ColumnDefinition Width="Auto" />
            <ColumnDefinition Width="*" />
        </Controls:StackGrid.ColumnDefinitions>

        <!-- Gender -->
        <TextBlock Text="Gender" />
        <StackPanel Orientation="Horizontal" x:Name="genderStackPanel">
            <RadioButton Content="Male" IsChecked="{Binding Gender, Mode=TwoWay, Converter={StaticResource GenderToIsSelectedConverter}, ConverterParameter=Male, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
            <RadioButton Content="Female" IsChecked="{Binding Gender, Mode=TwoWay, Converter={StaticResource GenderToIsSelectedConverter}, ConverterParameter=Female, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
        </StackPanel>

        <!-- First name -->
        <TextBlock Text="First name" />
        <TextBox Text="{Binding FirstName, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />

        <!-- Middle name -->
        <TextBlock Text="Middle name" />
        <TextBox Text="{Binding MiddleName, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />

        <!-- Last name -->
        <TextBlock Text="Last name" />
        <TextBox Text="{Binding LastName, Mode=TwoWay, ValidatesOnDataErrors=True, NotifyOnValidationError=True}" />
    </Controls:StackGrid>
</ExampleWindows:PersonWindowIntermediate>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Netherlands Netherlands
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions