Click here to Skip to main content
15,886,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a method that i need to test all of its branches. I can't find a way to assert the or verify the test is correct because both branches have almost the same behavior. btw - I can't change the given code

I have tried verifying End and Write are called but they are being called in both scenarios.

if (m_FailedOnInitialize)

{

    if (!ctx.Request.IsLocal)

    {

        ctx.Response.Write("Failed on initialization");

        ctx.Response.End();


    }

 else

    {      

            ctx.Response.Write(m_FirstError.ToString());
      ctx.Response.End();
    }
 }


What I have tried:

*m_FailedOnInitialize Is Static field, i set it to be "true" ctx.Request.IsLocal is set to be true\false in each test

To assert the behavior i use Typemock's verification Isolate.Verify.WasCalled(() => ctx.Response.write("")); Isolate.Verify.WasNotCalled(() => ctx.Response.End());
Posted
Updated 23-May-19 20:06pm

1 solution

It is unclear what you mean. Assert is used in C# in various ways as a method that can be invoked to empower code to use higher permissions than it would normally have or to test a variable and throw an exception if it contains an unexpected value. It may be that you are confusing people by using that word.

You cannot force someone else's code to work the way you want it to. You can however test it's output to see if it seems valid, or not. You can also extend someone else's code to add the functionality you need, if you want to implement internal testing code for instance.
 
Share this answer
 

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