Click here to Skip to main content
15,886,046 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.
<Windows:DataWindow x:Class="Catel.Examples.PersonApplication.UI.Windows.MainWindow"
                    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:Catel.Windows.Controls;assembly=Catel.Windows"
                    xmlns:Windows="clr-namespace:Catel.Windows;assembly=Catel.Windows"
                    xmlns:ViewModels="clr-namespace:Catel.Examples.PersonApplication.UI.ViewModels"
                    xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
                    xmlns:Commands="clr-namespace:Catel.MVVM.Commands;assembly=Catel.Windows"
                    x:TypeArguments="ViewModels:MainWindowViewModel"
                    MinHeight="350" MinWidth="525" ShowInTaskbar="True">
    
    <!-- Resources -->
    <Window.Resources>
        <!-- Styles -->
        <Style x:Key="ImageDropDownButtonStyle" TargetType="{x:Type Controls:DropDownButton}" BasedOn="{StaticResource DefaultDropDownButtonStyle}">
            <Setter Property="Width" Value="{DynamicResource Size.Image.Medium}" />
            <Setter Property="Height" Value="{DynamicResource Size.Image.Medium}" />
        </Style>
    </Window.Resources>
    
    <!-- Content -->
    <DockPanel LastChildFill="True">
        <!-- Details and actions -->
        <StackPanel DockPanel.Dock="Right" Orientation="Vertical">
            <!-- Details -->
            <GroupBox Header="Details">
                
            </GroupBox>
            
            <!-- Buttons -->
            <WrapPanel>
                <!-- Added -->
                <Button Command="{Binding Add}" Style="{DynamicResource ImageButtonStyle}">
                    <Image Source="/Catel.Examples.PersonApplication;component/Resources/Images/add.png"/>
                </Button>

                <!-- Edit -->
                <Button Command="{Binding Edit}" Style="{DynamicResource ImageButtonStyle}">
                    <Image Source="/Catel.Examples.PersonApplication;component/Resources/Images/edit.png"/>
                </Button>

                <!-- Remove -->
                <Button Command="{Binding Remove}" Style="{DynamicResource ImageButtonStyle}">
                    <Image Source="/Catel.Examples.PersonApplication;component/Resources/Images/delete.png"/>
                </Button>

                <Controls:DropDownButton Style="{DynamicResource ImageDropDownButtonStyle}">
                    <Controls:DropDownButton.DropDownContent>
                        <ListBox ItemsSource="{Binding PersonCollection}" SelectedItem="{Binding SelectedPerson}" Margin="0">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <Label Content="{Binding FirstName}" />
                                        <Label Content="{Binding MiddleName}" />
                                        <Label Content="{Binding LastName}" />
                                    </StackPanel>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                        </ListBox>
                    </Controls:DropDownButton.DropDownContent>
                    <Image Source="/Catel.Examples.PersonApplication;component/Resources/Images/group.png"/>
                </Controls:DropDownButton>
                
            </WrapPanel>
        </StackPanel>

        <!-- List of persons -->
        <ListBox DockPanel.Dock="Left" ItemsSource="{Binding PersonCollection}" SelectedItem="{Binding SelectedPerson}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="MouseDoubleClick">
                    <Commands:EventToCommand Command="{Binding Edit}" DisableAssociatedObjectOnCannotExecute="False" />
                </i:EventTrigger>
            </i:Interaction.Triggers>
            
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal">
                        <Label Content="{Binding FirstName}" />
                        <Label Content="{Binding MiddleName}" />
                        <Label Content="{Binding LastName}" />
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>
    </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