Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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"
C#
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"
C#
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"
C#
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:
C#
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
Posted

1 solution

Hi,

Instantiate an object for BLL and using that you can call KlasaDB.Shto() like this
C#
BLL.KlasaIURD BussObj = new BLL.KlasaIURD();
BussObj.Shto(obj);

Now it will move to BLL from there it will move to KlasaDB.Shto()

Hope this helps you a bit.

Regards,
RK
 
Share this answer
 
Comments
dr_iton 18-Dec-13 5:33am    
I had no positive result with that, all I want is to call class Klasa with its parameters and iniciate that so I can give values to it,
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});

}


The problem is here in this test class, how to call or iniciate the parameters of Klasa
how to call this
klasa = new Klasa (ID_Klasa, KlasaViti, Paralelja)
it tells me the no such of method exists.
Al I want is to test this method:
public static void Shto(Klasa obj)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900