lundi 11 janvier 2016

How do I "Unit Test" in C#? [on hold]

So I have this method in my project:

public static String MD5Hash(string TextToHash)
{
    if ((TextToHash == null) || (TextToHash.Length == 0))
    {
        return String.Empty;
    }

    MD5 md5 = new MD5CryptoServiceProvider();
    byte[] textToHash = Encoding.Default.GetBytes(TextToHash);
    byte[] result = md5.ComputeHash(textToHash);
    return System.BitConverter.ToString(result);

}

And I've tried testing like this:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using BugMon;

namespace BugMonTesting
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            string pwd = "Password";
            string expected = "DC-64-7E-B6-5E-67-11-E1-55-37-52-18-21-2B-39-64";
            frmLogIn.MD5Hash(pwd);
            Assert.AreEqual(pwd, expected);
        }
    }
}

But the string pwd does not seem to be passing through the Method when I run the test and stays as "Password".

What am I doing wrong?

Sorry if this is obvious but I've never had to use these tests before.

Aucun commentaire:

Enregistrer un commentaire