Click here to Skip to main content
15,896,154 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 49.5K   572   11  
This article explains how to write unit tests for MVVM using Catel.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="BrowseForFile.xaml.cs" company="Catel development team">
//   Copyright (c) 2008 - 2011 Catel development team. All rights reserved.
// </copyright>
// <summary>
//   Interaction logic for BrowseForFile.xaml
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using Catel.Windows.Input;

namespace Catel.Windows.Controls
{
    /// <summary>
    /// Interaction logic for BrowseForFile.xaml
    /// </summary>
    public partial class BrowseForFile : UserControl
    {
        #region Variables
        #endregion

        #region Constructor & destructor
		/// <summary>
		/// Initializes a new instance of the <see cref="BrowseForFile"/> class.
		/// </summary>
        public BrowseForFile()
        {
            InitializeComponent();

            CommandBindings.Add(new CommandBinding(BrowseForFileCommands.Browse, Browse_Executed, Browse_CanExecute));

            FileName = string.Empty;
        }
        #endregion

        #region Properties
		/// <summary>
		/// Gets or sets FileName.
		/// </summary>
		/// <remarks>
		/// Wrapper for the FileName dependency property.
		/// </remarks>
		public string FileName
		{
			get { return (string)GetValue(FileNameProperty); }
			set { SetValue(FileNameProperty, value); }
		}

		/// <summary>
		/// DependencyProperty definition as the backing store for FileName.
		/// </summary>
		public static readonly DependencyProperty FileNameProperty =
			DependencyProperty.Register("FileName", typeof(string), typeof(BrowseForFile), new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault));
        #endregion

        #region Command bindings
        /// <summary>
        /// Determines whether the user can execute the Browse command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">The event data.</param>
        private void Browse_CanExecute(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }

        /// <summary>
        /// Handled when the user invokes the Browse command.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="e">Event Arguments.</param>
        private void Browse_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog openFileDialog = new Microsoft.Win32.OpenFileDialog();
            openFileDialog.Multiselect = false;
            if (openFileDialog.ShowDialog() ?? false)
            {
                FileName = openFileDialog.FileName;
            }
        }
        #endregion

        #region Methods
        #endregion
    }
}

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