Beispiel #1
0
        public async Task PickNow_TransactionToActivateIsOnHold_Test()
        {
            //Arranage
            PickNow objPickNow = new PickNow()
            {
            };
            Dictionary <string, string> headers = new Dictionary <string, string>();
            List <int?> activeIsas = new List <int?>()
            {
                1
            };

            _transactionQueueRepository.Setup(x => x.GetActiveISA(It.IsAny <int>())).ReturnsAsync(activeIsas);

            List <ManageQueues.Business.Models.TransactionQueue> listTransactionQueue = new List <ManageQueues.Business.Models.TransactionQueue>()
            {
                new ManageQueues.Business.Models.TransactionQueue()
                {
                    Status = "Hold"
                }
            };


            _transactionQueueRepository.Setup(x => x.GetPendingTransactions(It.IsAny <List <int?> >())).ReturnsAsync(listTransactionQueue);

            //Act
            BusinessResponse objBusinessResponse = await _transactionQueueBussiness.PickNow("transactionKeyToActivate", 1, objPickNow, headers);

            //Assert
            Assert.Equal(false, objBusinessResponse.IsSuccess);
        }
Beispiel #2
0
        public async Task PickNow_NoIsaFound_Test()
        {
            //Arranage
            PickNow objPickNow = new PickNow();
            Dictionary <string, string> headers = new Dictionary <string, string>();
            List <int?> activeIsas = null;

            _transactionQueueRepository.Setup(x => x.GetActiveISA(It.IsAny <int>())).ReturnsAsync(activeIsas);

            //Act
            BusinessResponse objBusinessResponse = await _transactionQueueBussiness.PickNow("transactionKeyToActivate", 1, objPickNow, headers);

            //Assert
            Assert.Equal(false, objBusinessResponse.IsSuccess);
        }
        public async Task <ActionResult> PickNow(string activeTransactionQueueKey, int actorKey, PickNow pickNow)
        {
            try
            {
                if (string.IsNullOrEmpty(activeTransactionQueueKey) || !Regex.IsMatch(activeTransactionQueueKey, @"^[0-9a-fA-F]{24}$"))
                {
                    BusinessResponse objBadRequest = new BusinessResponse()
                    {
                        IsSuccess = false, Message = "ActiveTransactionQueueKey is not valid.", StatusCode = 400
                    };
                    _logger.LogError(objBadRequest.Message);
                    return(BadRequest(objBadRequest));
                }
                var headers = Request.Headers.ToDictionary <KeyValuePair <string, StringValues>, string, string>(item => item.Key, item => item.Value);
                BusinessResponse objBusinessResponse = await _transactionQueueBussiness.PickNow(activeTransactionQueueKey, actorKey, pickNow, headers);

                if (!objBusinessResponse.IsSuccess && objBusinessResponse.StatusCode == 400)
                {
                    return(BadRequest(new ErrorResponse(objBusinessResponse.Message, objBusinessResponse.StatusCode, ResponsePayloadType.BusinessException)));
                }
                else if (!objBusinessResponse.IsSuccess && objBusinessResponse.StatusCode == 404)
                {
                    return(NotFound(new ErrorResponse(objBusinessResponse.Message, objBusinessResponse.StatusCode, ResponsePayloadType.BusinessException)));
                }

                return(Ok(pickNow.TransactionQueueKeyToActivate));
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(StatusCode(500));
            }
        }
Beispiel #4
0
        public async Task <BusinessResponse> PickNow(string activeTransactionQueueKey, int actorKey, PickNow pickNow, Dictionary <string, string> headers)
        {
            List <int?> isaIds = await GetIsaIds(actorKey);

            if (isaIds == null || !isaIds.Any())
            {
                return(new BusinessResponse()
                {
                    IsSuccess = false, Message = "No active Isa found.", StatusCode = 404
                });
            }
            var tqStatus = await _transactionQueueRepository.GetTransactionStatus(activeTransactionQueueKey);

            if (tqStatus == TransactionQueueStatus.Pending.ToString())
            {
                return new BusinessResponse()
                       {
                           IsSuccess = false, Message = "Transaction is no longer active.", StatusCode = 400
                       }
            }
            ;

            BusinessResponse objBusinessResponse = await CheckForExistingTransaction(actorKey, pickNow, isaIds);

            if (objBusinessResponse.IsSuccess)
            {
                long updateResult = await UpdateTransactionQueueStatus(activeTransactionQueueKey, pickNow.TransactionQueueKeyToActivate, isaIds);

                return(updateResult > 0 ? new BusinessResponse()
                {
                    IsSuccess = true, Message = "Transaction is activated.", StatusCode = 200
                } : new BusinessResponse()
                {
                    IsSuccess = false, Message = "Transaction is not activated.", StatusCode = 404
                });
            }
            return(objBusinessResponse);
        }
Beispiel #5
0
        /// <summary>
        /// Check transaction is exist or not
        /// </summary>
        /// <param name="actorKey">actorKey</param>
        /// <param name="pickNow">pickNow object </param>
        /// <param name="isaIds">ISA Ids</param>
        /// <returns></returns>
        private async Task <BusinessResponse> CheckForExistingTransaction(int actorKey, PickNow pickNow, List <int?> isaIds)
        {
            var pendingTransactions = await _transactionQueueRepository.GetPendingTransactions(isaIds);

            var selectedItem = pendingTransactions?.FirstOrDefault(item => item.Id == pickNow.TransactionQueueKeyToActivate);

            if (selectedItem == null)
            {
                return(new BusinessResponse {
                    IsSuccess = false, Message = "This item has been deleted by another device", StatusCode = 404
                });
            }

            return(new BusinessResponse {
                IsSuccess = true
            });
        }