How can I test for this exception as returned from a WCF call?
I have this error class.
[Serializable]
public class PermissionDenied_Error : Exception
{
public PermissionDenied_Error() : base("You are not approved.") { }
}
In my Service, I am throwing it.
if (notApproved)
{
throw new FaultException<PermissionDenied_Error>(new PermissionDenied_Error()
, new FaultReason("Permissions Denied!"));
}
In my test, I am expecting it.
[Test]
[ExpectedException(typeof(FaultException<PermissionDenied_Error>))]
Current result is:
Expected: System.ServiceModel.FaultException`1[[PermissionDenied_Error
, Project.API, Version=1.0.4318.24332, Culture=neutral, PublicKeyToken=null]]
but was: System.ServiceModel.FaultException : Permissions Denied!
Your
PermissionDenied_Errorshould be a data contract. It should not be derived from Exception.Also,you need to place the
FaultContractAttributeon your operation contract so that the client knows to expect an exception.Added by Valamas