Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi i have a public class inside this class i have a private function


C#
public class ClassName 
{
private void SetBillingContactEmail()
        {
            //Return if billing contact and its emails are null
            if (_companyview.BillingContact == null || _companyview.BillingContact.Emails == null)
                return;

            //Sets the primary email address of billing contact to the CustomerContactAREmail
            _customermodel.CustomerContactARemail = _companyview.BillingContact.Emails.Where(x => x.IsPrimary == true).Select(y => y.Address).FirstOrDefault();
        }
}



i want test this function

What I have tried:

am new to nunit i have no how to write test case
Posted
Updated 13-Dec-17 23:30pm
Comments
F-ES Sitecore 14-Dec-17 7:07am    
For a start you can't test this as it is private, you would need to write a test for a public function that calls this method. Secondly without knowing what _companyview etc is it's impossible to say how this could be tested, or if it can even be unit tested at all. You generally have to write things with unit testing in mind.
GregoryPres 19-Dec-17 7:19am    
You usually test your private methods via some public API(public methods). You can read this on writing tests with Nunit: Unit Test patterns.
If you're still having trouble, post more of your code (the public API that uses this private method) so we can help you.

1 solution

The function you want to test need to be public: you can't access any private function out of class itself!
Then take a look how to create a NUnit project; Unit Testing Using NUnit[^]
 
Share this answer
 
v2

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