Click here to Skip to main content
15,867,771 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have got the below set of code

C#
if (entity.InterpreterCostAuthorised && entity.InterpreterCostAuthorisedDate == null)
          {
              entity.InterpreterCostAuthorisedDate = DateTime.UtcNow;
          }
          else if (!entity.InterpreterCostAuthorised)
          {
              entity.InterpreterCostAuthorisedDate = null;
          }

          if (entity.ClientChargeAuthorised && entity.ClientChargeAuthorisedDate == null)
          {
              entity.ClientChargeAuthorisedDate = DateTime.UtcNow;
          }
          else if (!entity.ClientChargeAuthorised)
          {
              entity.ClientChargeAuthorisedDate = null;
          }


Can any on help me to write unit test for these set of statements

What I have tried:

i tried by using different test case and also two more list
Posted
Updated 2-Aug-18 15:50pm

Pick one scenario at a time, set the entity properties up such that that scenario is satisfied, then check the entity properties that match the scenario have been set up.

eg you'll first want to check when InterpreterCostAuthorised is true and InterpreterCostAuthorisedDate is null, so set those properties on the entity, then check that InterpreterCostAuthorisedDate has a date, and maybe check the date is within 1 minute of the current date. This is all straight forward stuff so I'm not sure exactly what the issue is?
 
Share this answer
 
There will be two unit test methods

1. first will check whether InterpreterCostAuthorisedDate is set with current time or not / you can check whether date field is null or not
Assert.IsNotNull(InterpreterCostAuthorisedDate)


2. second will check whether InterpreterCostAuthorisedDate is set null or not
you can assert it using
Assert.Isnull()


Hope this will help you.
 
Share this answer
 
v2
Comments
Richard Deeming 3-Aug-18 13:31pm    
TWO YEARS too late, and with a mangled version of what solution 1 already said.

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