/// <summary> /// Return the list of PaymentMethods /// </summary> /// <returns>PaymentMethodList</returns> public async Task <IActionResult> GetPaymentMethod() { BaseResult <List <PaymentMethodViewModel> > paymentMethodResultFromCache = new BaseResult <List <PaymentMethodViewModel> > { Result = RedisCacheHelper.Instance.Get <List <PaymentMethodViewModel> >(Constants.CacheKeys.PaymentMethodList) }; if (paymentMethodResultFromCache.Result == null || paymentMethodResultFromCache.Result.Count == 0) { BaseResult <List <PaymentMethod> > paymentMethodResult = await iPayment.GetPaymentMethod().ConfigureAwait(false); if (paymentMethodResult.IsError && paymentMethodResult.ExceptionMessage != null) { return(new StatusCodeResult(500)); } else if (paymentMethodResult.Result == null || paymentMethodResult.Result.Count == 0) { return(NoContent()); //204 } else { var result = PaymentDataResponseMapper.MapPaymentMethod(paymentMethodResult); RedisCacheHelper.Instance.Set <List <PaymentMethodViewModel> >(Constants.CacheKeys.PaymentMethodList, result.Result); return(Ok(result)); //200 } } return(Ok(paymentMethodResultFromCache)); //200 }
public async Task TestGetPaymentMethod_Positive_Predicate() { //Arrange var paymentMethod = new PaymentMethod() { Id = 1, Name = "RS", IsActive = true, IsDeleted = false, NameItemId = 1 }; var baseResult = new BaseResult <List <PaymentMethod> >() { Result = new List <PaymentMethod>() { paymentMethod } }; var pred = new Func <PaymentMethod, bool>(x => x.IsActive && !x.IsDeleted); iPaymentMethodLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <PaymentMethod, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult)); //Act Task <BaseResult <List <PaymentMethod> > > result = paymentDataRepository.GetPaymentMethod(); //Assert Assert.IsTrue(result.Result != null); Assert.IsTrue(result.Result is BaseResult <List <PaymentMethod> >); }