Click here to Skip to main content
15,887,214 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 49K   572   11  
This article explains how to write unit tests for MVVM using Catel.
<Windows:DataWindow x:Class="Catel.Articles.Base.UI.Windows.ExamplesWindow"
    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.Windows" 
    xmlns:Controls="clr-namespace:Catel.Articles.Base.UI.Controls" 
    xmlns:ViewModels="clr-namespace:Catel.Articles.Base.UI.ViewModels" 
    xmlns:CatelControls="clr-namespace:Catel.Windows.Controls;assembly=Catel.Windows" 
    x:TypeArguments="ViewModels:ExamplesViewModel"
    SizeToContent="Manual" ResizeMode="CanResize" Width="800" Height="700"
    ShowInTaskbar="True" WindowStartupLocation="CenterScreen"
    Icon="/Catel.Articles.Base;component/Resources/Images/CatenaLogic.png">

    <!-- Resources -->

    <!-- Content -->
    <DockPanel>
        <!-- Explanation + theme picker --> 
        <Grid DockPanel.Dock="Top">
            <!-- Row definitions -->
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            
            <!-- Column definitions -->
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <!-- Explanation / description -->
            <Label Grid.Row="0" Grid.RowSpan="2" Grid.Column="0">
                <TextBlock TextWrapping="Wrap" Text="{Binding Description}" />
            </Label>

            <!-- Theme picker -->
            <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Right">
                <!-- Label -->
                <Label Content="Theme" />

                <!-- Combobox -->
                <ComboBox ItemsSource="{Binding ThemeCollection}" SelectedItem="{Binding SelectedTheme}" DisplayMemberPath="Name"
                          Width="175" />
            </StackPanel>
        </Grid>
        
        <!-- Trace output control -->
        <CatelControls:TraceOutputControl DockPanel.Dock="Bottom" Height="150" />

        <!-- List of examples -->
        <ListBox DockPanel.Dock="Left" SelectionMode="Single" MaxWidth="250"
                 ItemsSource="{Binding Examples}" SelectedItem="{Binding SelectedExample}"
                 ScrollViewer.HorizontalScrollBarVisibility="Disabled">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <!-- Row definitions -->
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="10" />
                        </Grid.RowDefinitions>

                        <!-- Column definitions -->
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="20" />
                            <ColumnDefinition Width="*" />
                        </Grid.ColumnDefinitions>

                        <!-- Title -->
                        <TextBlock Grid.Row="0" Grid.ColumnSpan="2" FontWeight="Bold" TextWrapping="Wrap" Text="{Binding Name}" />

                        <!-- Explanation -->
                        <TextBlock Grid.Row="1" Grid.Column="1" TextWrapping="Wrap" Text="{Binding ShortDescription}" />
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

        <!-- Example details -->
        <Controls:ExampleControl DataContext="{Binding SelectedExample}" />
    </DockPanel>
</Windows:DataWindow>

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