コード例 #1
0
        /// <summary>
        ///  Return the list of TaxTypes
        /// </summary>
        /// <returns>TaxTypeList</returns>
        public async Task <IActionResult> GetTaxType()
        {
            BaseResult <List <TaxTypeViewModel> > taxTypeResultFromCache = new BaseResult <List <TaxTypeViewModel> >()
            {
                Result = RedisCacheHelper.Instance.Get <List <TaxTypeViewModel> >(Constants.CacheKeys.TaxTypeList)
            };

            if (taxTypeResultFromCache.Result == null || taxTypeResultFromCache.Result.Count == 0)
            {
                BaseResult <List <TaxType> > taxTypeResult = await iPayment.GetTaxType().ConfigureAwait(false);

                if (taxTypeResult.IsError && taxTypeResult.ExceptionMessage != null)
                {
                    return(new StatusCodeResult(500));
                }
                else if (taxTypeResult.Result == null || taxTypeResult.Result.Count == 0)
                {
                    return(NoContent()); //204
                }
                else
                {
                    var result = PaymentDataResponseMapper.MapTaxType(taxTypeResult);
                    RedisCacheHelper.Instance.Set <List <TaxTypeViewModel> >(Constants.CacheKeys.TaxTypeList, result.Result);
                    return(Ok(result)); //200
                }
            }
            return(Ok(taxTypeResultFromCache)); //200
        }
コード例 #2
0
        public async Task TestGetTaxType_Positive_Predicate()
        {
            //Arrange
            var taxType = new TaxType()
            {
                Id = 1, Name = "VAT", IsDeleted = false, NameItemId = 1
            };
            var baseResult = new BaseResult <List <TaxType> >()
            {
                Result = new List <TaxType>()
                {
                    taxType
                }
            };
            var pred = new Func <TaxType, bool>(x => x.IsDeleted == false);

            iTaxTypeLibrary.Setup(x => x.GetListByPredicate(It.Is <Func <TaxType, bool> >(y => y.GetType() == pred.GetType()))).Returns(Task.FromResult(baseResult));
            //Act
            Task <BaseResult <List <TaxType> > > result = paymentDataRepository.GetTaxType();

            //Assert
            Assert.IsTrue(result.Result != null);
            Assert.IsTrue(result.Result is BaseResult <List <TaxType> >);
        }