Click here to Skip to main content
15,884,472 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.Articles._04___Unit_testing.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.Articles._04___Unit_testing.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>
    </Window.Resources>

    <!-- Content -->
    <DockPanel LastChildFill="True">
        <!-- Details and actions -->
        <StackPanel DockPanel.Dock="Right" Orientation="Vertical">
            <!-- Buttons -->
            <WrapPanel>
                <!-- Added -->
                <Button Command="{Binding Add}" Style="{DynamicResource ImageButtonStyle}">
                    <Image Source="/Catel.Articles.04 - Unit testing;component/Resources/Images/add.png"/>
                </Button>

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

                <!-- Remove -->
                <Button Command="{Binding Remove}" Style="{DynamicResource ImageButtonStyle}">
                    <Image Source="/Catel.Articles.04 - Unit testing;component/Resources/Images/delete.png"/>
                </Button>
            </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 FullName}" />
                    </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