S.Chandra Sekhar
S.Chandra Sekhar

Reputation: 503

Microsoft Fakes Exception test case stopping solution at throw in catch block

Solution is stopping at throw Exception in Catch block.

I have used below code

//TestMethod
[TestMethod]
[ExpectedException(typeof(Exception), "Error occurred!")]    
public void Get_CatchException()
{
    using (ShimsContext.Create())
    {

        IT.Common.Fakes.ShimSampleClass.AllInstances.GetString = (x, y) =>
        {
            throw new Exception("Error occurred!");
        };
        this._iSampleClass.Get(string);

    }
}

//Class method

public void Get(string Name)
{
    try
    {
        GetString(Name);
    }
    catch (Exception ex)
    {
        throw ex; 
    }
}

My requirement is Solution should not stop at throw and Exception test case should pass.

I am getting below error in class file and solution stopped.

enter image description here

Upvotes: 0

Views: 252

Answers (0)

Related Questions