Click here to Skip to main content
15,894,405 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.2K   572   11  
This article explains how to write unit tests for MVVM using Catel.
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Resources;
using System.Text;
using System.Windows;


namespace Ricciolo.StylesExplorer.MarkupReflection
{
    /// <summary>
    /// Rappresenta un singole file Baml all'interno di un assembly
    /// </summary>
    public class BamlFile : Component
    {
        private Uri _uri;
        private readonly Stream _stream;

        public BamlFile(Uri uri, Stream stream)
        {
            if (uri == null)
                new ArgumentNullException("uri");
            if (stream == null)
                throw new ArgumentNullException("stream");

            _uri = uri;
            _stream = stream;
        }

        /// <summary>
        /// Carica il Baml attraverso il motore di WPF con Application.LoadComponent
        /// </summary>
        /// <returns></returns>
        public object LoadContent()
        {
            try
            {
                return Application.LoadComponent(this.Uri);
            }
            catch (Exception e)
            {
                throw new InvalidOperationException("Invalid baml file.", e);
            }
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
                this.Stream.Dispose();
        }

        public override object InitializeLifetimeService()
        {
            return null;
        }

        /// <summary>
        /// Restituisce lo stream originale contenente il Baml
        /// </summary>
        public Stream Stream
        {
            get { return _stream; }
        }

        /// <summary>
        /// Restituisce l'indirizzo secondo lo schema pack://
        /// </summary>
        public Uri Uri
        {
            get { return _uri; }
        }

    }
}

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