jeudi 1 septembre 2016

Unit testing a catch exception without triggering it

Is it possible to trigger a catch clause from outside of a method?

public class SomeClass
{
    public ApiReEntity GetLeadsByPotentialDogAccount(Guid? accountGuid)
    {
        try
        {
            if (accountGuid == null)
                throw new IdentifierIsEmptyExxception("The AccountId not provided!");
        }
        catch (IdentifierIsEmptyExxception exception)
        {
            _validationDictionary.AddError(Exxception.Message);
            return new ApiReEntity()
            {
                ValidationDictionary = _validationDictionary,
                StatusCode = HttpStatusCode.BadRequest,
                Entities = leadsExpanded
            };
        }
    }
}

without passing a null accountGuid, how can I assert that when_identifierisemptyexcception_is_caught_then_adderror_isinvoked ?

Please note that the system under test is the actual class SomeClass

If this is not possible, how do you unit test the innards of a catch clause?

Aucun commentaire:

Enregistrer un commentaire