Click here to Skip to main content
15,892,537 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.1K   572   11  
This article explains how to write unit tests for MVVM using Catel.
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ObservableCollectionExtensions.cs" company="Catel development team">
//   Copyright (c) 2008 - 2011 Catel development team. All rights reserved.
// </copyright>
// <summary>
//   Extension methods for <see cref="System.Collections.ObjectModel.ObservableCollection{T}" />.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace Catel.Collections.ObjectModel
{
    /// <summary>
    /// Extension methods for <see cref="System.Collections.ObjectModel.ObservableCollection{T}"/>.
    /// </summary>
    public static class ObservableCollectionExtensions
    {
        #region Methods
        /// <summary>
        /// Add an range of items to the specified <see cref="System.Collections.ObjectModel.ObservableCollection{T}"/>.
        /// </summary>
        /// <typeparam name="T">Type of items within the observable collection.</typeparam>
        /// <param name="collection">The <see cref="System.Collections.ObjectModel.ObservableCollection{T}"/>.</param>
        /// <param name="range">An range of items.</param>
        /// <exception cref="ArgumentNullException">when <paramref name="collection"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentNullException">when <paramref name="range"/> is <c>null</c>.</exception>
        public static void AddRange<T>(this ObservableCollection<T> collection, IEnumerable<T> range)
        {
            if (collection == null)
            {
                throw new ArgumentNullException("collection");
            }

            if (range == null)
            {
                throw new ArgumentNullException("range");
            }

            foreach (T curItem in range)
            {
                collection.Add(curItem);
            }
        }
        #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