I created a three layer windows based application. I'm trying to make a unit testing using NUINT, but the problem is that I don't know how to access the method.
I created my application in this manner :
I'll try to test the method Shto(Klasa obj)
Business Object namespace "BO"

namespace BO
{
    public class Klasa
    {
        private int k_ID_Klasa;
        private int k_KlasaViti;
        private int k_Paralelja;


        public Klasa()
        {
        }

        public int ID_Klasa
        {
            get { return k_ID_Klasa; }
            set { k_ID_Klasa = value; }
        }

        public int KlasaViti
        {
            get { return k_KlasaViti; }
            set { k_KlasaViti = value; }
        }

        public int Paralelja
        {
            get { return k_Paralelja; }
            set { k_Paralelja = value; }
        }
    }
}

Data Access Layer "DAL"

namespace DAL
{
    public class KlasaDB
    {      
        public KlasaDB()
        {

        }

        public static void Shto(Klasa obj)
        {
            SqlConnection sqlConn = new SqlConnection(StringKoneksioni.Stringu);
            SqlCommand sqlCmd = new SqlCommand("procShtoKlasa", sqlConn);
            sqlCmd.CommandType = CommandType.StoredProcedure;
            sqlCmd.Parameters.AddWithValue("@KlasaViti", obj.KlasaViti);
            sqlCmd.Parameters.AddWithValue("@Paralelja", obj.Paralelja);
            sqlConn.Open();
            sqlCmd.ExecuteNonQuery();
            sqlConn.Close();
        }
     }
}

Business Logic Layer "BLL"

namespace BLL
{
    public class KlasaIURD
     {
            public KlasaIURD()
            {

            }

            public static void Shto(Klasa obj)
            {
                KlasaDB.Shto(obj);
            }
    }
}

I created the references for the namespaces needed in the project and also I created a testing class but the problem is that I don't know how to access the class method, that means I'm stacked in the following class:

namespace ScoMan_TI.NUnit_Testing
{
    [TestFixture]
    class Klasa_Testuese
    {
        Klasa klasa;

        [SetUp]
        public void initKlasa()
        {

            //int ID_Klasa = 15;
            //int KlasaViti = 12;
            //int Paralelja = 5;
            //KlasaDB = new KlasaDB()
            //KlasaDB.Shto()
            //klasa = new Klasa(new Klasa{ID_Klasa, KlasaViti, Paralelja});

        }


    }
}

Thank you in advance for your reply.
Cheers

Because Shto method is marked as static, you don't need to create a new KlasaDB instance. You do however need an instance of Klasa to pass to the call since it takes it as a parameter.

Something like this:

[Test]
public void Test_Shto()
{
    // set some test data up
    Klasa klasa = new Klasa();
    klasa.ID_Klasa = 3;
    klasa.KlasaViti = 19301;
    klasa.Paralelja = -19;

    // call the static Shto method
    KlasaDB.Shto(klasa); // or KlasaUIRD.Shto(klasa);

    // review the result of the Shto method call
    // ...
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.