0

In my project we have created action based method like below...which work as expected in our project.

    public async Task MyMethod(Action<bool> SuccessAction, Action<Exception> ErrorAction)
    {
        try
        {
            SuccessAction(false);
        }
        catch (Exception ex)
        {
            ErrorAction(ex);
        }
    }

Now, for testing the above method below is how i have written the test method using NUnit.

    [Test]
    public async Task MyFirstTest()
    {            
       var myClass = new MyClass();
       await myClass.MyMethod(
            Result =>
            {
                Assert.IsTrue(Result);//as all are aware that this will throw an exception.
            },
            Error =>
            {                    
                Assert.Fail();
            });
    }

Now, my question is when ever there is an exception occured at MyFirstTest then that exception get caught at the MyMethod.

I am not sure why this is happening.

Can any one please provide an solution to handle this.

Please let me know if more information is required or my question is not clear.

4

0 回答 0