public static FulcrumException ToFulcrumException(FulcrumError error) { if (error == null) { return(null); } FulcrumException exception; switch (error.TypeId) { case BusinessRuleException.ExceptionTypeId: exception = new BusinessRuleException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case ConflictException.ExceptionTypeId: exception = new ConflictException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case ServerContractException.ExceptionTypeId: exception = new ServerContractException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case NotFoundException.ExceptionTypeId: exception = new NotFoundException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case UnauthorizedException.ExceptionTypeId: exception = new UnauthorizedException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case AssertionFailedException.ExceptionTypeId: exception = new AssertionFailedException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case NotImplementedException.ExceptionTypeId: exception = new NotImplementedException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; case TryAgainException.ExceptionTypeId: exception = new TryAgainException(error.TechnicalMessage, ToFulcrumException(error.InnerError)); break; default: exception = null; break; } if (exception == null) { var message = $"The TypeId ({error.TypeId}) was not recognized: {error.ToJsonString(Formatting.Indented)}"; return(new AssertionFailedException(message, ToFulcrumException(error.InnerError))); } exception.CopyFrom(error); return(exception); }
private Ticket GetTicketWithExceptions(string ticketId, ExpectedResultEnum expectedFacadeResult) { FulcrumException fulcrumException = null; switch (expectedFacadeResult) { case ExpectedResultEnum.Ok: return(new Ticket { Id = ticketId }); case ExpectedResultEnum.BusinessRuleException: fulcrumException = new BusinessRuleException("Business rule exception"); break; case ExpectedResultEnum.ConflictException: fulcrumException = new ConflictException("Conflict exception"); break; case ExpectedResultEnum.ServerContractException: fulcrumException = new ServerContractException("Contract exception"); break; case ExpectedResultEnum.NotFoundException: fulcrumException = new NotFoundException("Not found exception"); break; case ExpectedResultEnum.UnauthorizedException: fulcrumException = new UnauthorizedException("Unauthorized exception"); break; case ExpectedResultEnum.AssertionFailedException: fulcrumException = new AssertionFailedException("Assertion failed exception"); break; case ExpectedResultEnum.NotImplementedException: fulcrumException = new NotImplementedException("Not implemented exception"); break; case ExpectedResultEnum.TryAgainException: fulcrumException = new TryAgainException("Try again exception"); break; default: fulcrumException = new AssertionFailedException($"Unexpected switch value: {expectedFacadeResult}"); break; } // This is to be able to test that the properties are copied all the way back to the test case. fulcrumException.Code = fulcrumException.InstanceId; throw fulcrumException; }