Hi,
I'm working on a test and I'm trying to find the best way to refactor the code below. Each case is an Enum and returns a boolean
I was thinking of putting the following codeblock in a separate method? and then calling that in each of the cases
Any help would be appreciated!
I'm working on a test and I'm trying to find the best way to refactor the code below. Each case is an Enum and returns a boolean
C#:
switch (request.PaymentScheme)
{
case PaymentScheme.Bacs:
if (accountRetrieved == null ||
!accountRetrieved.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Bacs)) // using an Enum here
{
paymentResult.Success = false;
}
break;
case PaymentScheme.FasterPayments:
if (accountRetrieved == null ||
!accountRetrieved.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.FasterPayments) ||
accountRetrieved.Balance < request.Amount)
{
paymentResult.Success = false;
}
break;
case PaymentScheme.Chaps:
if (accountRetrieved == null ||
!accountRetrieved.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.Chaps) ||
accountRetrieved.Status != AccountStatus.Live)
{
paymentResult.Success = false;
}
break;
}
I was thinking of putting the following codeblock in a separate method? and then calling that in each of the cases
C#:
if (accountRetrieved == null ||
!accountRetrieved.AllowedPaymentSchemes.HasFlag(AllowedPaymentSchemes.FasterPayments) ||
Any help would be appreciated!