Click here to Skip to main content
15,868,141 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I have one question. What is good testing way, Microsoft.VisualStudioTestToolsUnitTesting or by Nunit_framework testing.

If I have this`

C#
public Branch CreateOrEditBranch(Branch branch)
  {
       using (var scope = CreateTransactionScope())

      {
      }
       return branch;
  }
I have branch metod. and branch have properties(name,user,adress and so) , and positive test need be if all properties will be full, if not,then it will be negative test , after it will show msg , that something is wrong.

Now how can i wrote this test by good way. i wrote it like this `

C#
public void BranchTest()
    {
        try {

              Branch negative = new Branch()
             {


                  AccountantPost = "Post",


                  Accountant = "Accoutant"`,

                  Address = "Address",

                  BankCode = "Code",

                  Manager = "Manager",

                  ManagerPost = "Post",


                 OpenDate = DateTime.Now,


                 CloseDate = DateTime.Today,


                 User = "marin",

                 Modified = DateTime.Now,

                 };

  core.CreateOrEditBranch(negative);

}

catch (Exception ex)
{
   Assert.Fail(ex.Message);

}

Is it right ?
I hope someone can help me :(

Thank you.
Posted
Updated 4-Aug-14 4:08am
v4

1 solution

Hi You can check for null conditions of each of the variables using an AND condition as shown below:

C#
bool? isValid = null;
Branch positive = new Branch();
// Assign values to the instance here.
isValid = positive.BranchID != null && positive.Address != null && positive.BankCode != null;
Assert.AreEqual(true, isValid);
 
Share this answer
 
v2
Comments
Marine Azizyan 5-Aug-14 2:37am    
Thank you very much .
Vijendra(VJ) 5-Aug-14 3:50am    
Can you please accept this as answer if this works for you.
Thanks
Vijendra(VJ) 8-Aug-14 5:33am    
whats the problem Mr. Marine Azizyan?
Isnt this working ?
Marine Azizyan 8-Aug-14 7:11am    
No, already i finded solution for it. So your wrote code isn't working like a test, anytime thank you.

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



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