Click here to Skip to main content
15,891,136 members
Articles / Programming Languages / C#

NUnit Test Case Code Generator

Rate me:
Please Sign up or sign in to vote.
4.59/5 (17 votes)
13 Aug 2008CPOL6 min read 114.4K   3.5K   76  
Automatically generate NUnit test case code template starting from method to test
using System;
using System.Collections.Generic;
using System.Text;

namespace ExampleLibraryToTest
{

    public class Class1
    {
        //string Comment = "sdfasdfasdf";
        
        private int myPrivateVar1;
        public int PropertyInt1
        {
            get { return myPrivateVar1; }
            set { myPrivateVar1 = value; }
        }

        private int myPrivateVar2;
        public int PropertyInt2
        {
            get { return myPrivateVar2; }
            set { myPrivateVar2 = value; }
        }

        private void PrivateMethod()
        {
            System.Windows.Forms.MessageBox.Show("PrivateMethod");
        }

        protected void ProtectedMethod()
        {
            System.Windows.Forms.MessageBox.Show("ProtectedMethod");
        }

        public void Create()
        {
            System.Windows.Forms.MessageBox.Show("create");
        }

        public void M1_msgbox()
        {
            System.Windows.Forms.MessageBox.Show("I'm M1 on ClassLibrary1");
        }

        public string M2_Concat(string stringToConcat, int IntToConcat)
        {
            stringToConcat = stringToConcat + IntToConcat.ToString();

            return stringToConcat;
        }


        public bool M3_WithClass(int MyInt1, int MyInt2, Class1_2 cl1_2)
        {
            if (MyInt1 == cl1_2.IntProp2_1 && MyInt2 == cl1_2.IntProp2_2)
            {
                Class2 cl2 = new Class2();
                cl2.IntProp2_1 = cl1_2.IntProp2_1 + MyInt1;
                cl2.IntProp2_2 = cl1_2.IntProp2_2 + MyInt2;
                return true;
            }
            else
            {
                Class2 cl2 = new Class2();
                cl2.IntProp2_1 = cl1_2.IntProp2_1 + MyInt1;
                cl2.IntProp2_2 = cl1_2.IntProp2_2 + MyInt2;
                return false;
            }
        }

        public Class3 M4_WithClassComplex(int MyInt1, int MyInt2, ref Class2 cl2)
        {
            Class3 cl3 = new Class3();
            cl3.IntProp3_1 = cl2.IntProp2_1 + MyInt1;
            cl3.IntProp3_2 = cl2.IntProp2_2 + MyInt2;

            return cl3;
        }

    }

    public class Class1_2
    {
        private int myPrivateVar1;
        public int IntProp2_1
        {
            get { return myPrivateVar1; }
            set { myPrivateVar1 = value; }
        }

        private int myPrivateVar2;
        public int IntProp2_2
        {
            get { return myPrivateVar2; }
            set { myPrivateVar2 = value; }
        }

    }

    public class Class2
    {
        private int myPrivateVar1;
        public int IntProp2_1
        {
            get { return myPrivateVar1; }
            set { myPrivateVar1 = value; }
        }

        private int myPrivateVar2;
        public int IntProp2_2
        {
            get { return myPrivateVar2; }
            set { myPrivateVar2 = value; }
        }

        private Class3 complexProp;
        public Class3 ComplexProp
        {
            get { return complexProp; }
            set { complexProp = value; }
        }

        public void Method_ShowMyProp2_1()
        {
            System.Windows.Forms.MessageBox.Show(IntProp2_1.ToString());
        }

        public void Method_ShowMyProp2_2()
        {
            System.Windows.Forms.MessageBox.Show(IntProp2_2.ToString());
        }
    }

    public class Class3
    {
        private int myPrivateVar1;
        public int IntProp3_1
        {
            get { return myPrivateVar1; }
            set { myPrivateVar1 = value; }
        }

        private int myPrivateVar2;
        public int IntProp3_2
        {
            get { return myPrivateVar2; }
            set { myPrivateVar2 = value; }
        }

    }

}

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
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions