Click here to Skip to main content
15,891,473 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 49K   572   11  
This article explains how to write unit tests for MVVM using Catel.
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Catel.Test.Convert
{
    /// <summary>
    /// Summary description for ConvertTest
    /// </summary>
    [TestClass]
    public class ConvertTest
    {
		//[TestMethod]
		//public void ConvertAndReconvert()
		//{
		//    // Create a temp file
		//    string tempFile1 = Path.GetTempFileName();
		//    string tempFile2 = Path.GetTempFileName();

		//    // Create file contents
		//    string stringContents = "";
		//    for (int i = 0; i < 26; i++)
		//    {
		//        stringContents += ((char)i).ToString();
		//    }
		//    byte[] binaryContents = ASCIIEncoding.ASCII.GetBytes(stringContents);

		//    // Create file
		//    FileStream fileStream = new FileStream(tempFile1, FileMode.Create);
		//    fileStream.Write(binaryContents, 0, binaryContents.Length);
		//    fileStream.Close();

		//    // Encode and decode
		//    string encodedContent = Catel.Convert.FileToBase64(tempFile1);
		//    Assert.IsTrue(Catel.Convert.FileFromBase64(encodedContent, tempFile2));

		//    // Read file contents
		//    TextReader textReader1 = new StreamReader(tempFile1, Encoding.Default);
		//    string fileContents1 = textReader1.ReadToEnd();
		//    textReader1.Close();
		//    TextReader textReader2 = new StreamReader(tempFile2, Encoding.Default);
		//    string fileContents2 = textReader2.ReadToEnd();
		//    textReader2.Close();

		//    // Check if contents are the same
		//    Assert.AreEqual(fileContents1, fileContents2);

		//    // Delete the temporary files
		//    File.Delete(tempFile1);
		//    File.Delete(tempFile2);
		//}
    }
}

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