Exemple #1
0
 private bool IsValidCardNumber(CardCostInput request)
 {
     return(request != null &&
            request.Card_Number != null &&
            !string.IsNullOrWhiteSpace(request.Card_Number) &&
            !string.IsNullOrEmpty(request.Card_Number) &&
            request.Card_Number.Length == CardNumberLength &&
            request.Card_Number.All(char.IsDigit));
 }
Exemple #2
0
        public async Task <BaseModel> GetCardData(CardCostInput request)
        {
            string iin;
            var    response = new BaseModel();
            var    isValid  = this.IsValidCardNumber(request);

            if (isValid)
            {
                // keep first-6 digits
                iin = this.ClearPanNumber(request.Card_Number);

                // Firstly check if there is the bin in Db and retrieve country
                var card = await _CardCostRepository.GetIINAsync(iin);

                if (card is null)
                {
                    try
                    {
                        // Retrieve CountryCode from CardCost api
                        var countryCode = await _CardCostClient.GetDataAsync(iin);

                        // Retrieve cost from Db based on country code
                        var cost = await _clearingCostRepository.GetByCountryCodeAsync(countryCode);

                        // create Bins entity to store it
                        var entity = this.ConvertToEntity(iin, countryCode);

                        // Store "search" to Db
                        await _CardCostRepository.AddIINAsync(entity);

                        response.Country = countryCode;
                        response.Cost    = (decimal)cost.Cost;

                        return(response);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception($"An error has occured. {ex}");
                    }
                }
                else
                {
                    // Retrieve cost from Db
                    var cost = await _clearingCostRepository.GetByCountryCodeAsync(card.Country);

                    response.Country = card.Country;
                    response.Cost    = (decimal)cost.Cost;
                    return(response);
                }
            }
            return(null);
        }
Exemple #3
0
        public async Task PostCardCost_EmptyCardNumber_ReturnsBadRequest()
        {
            // Arrange
            var model = new CardCostInput();

            // Act
            var response = await _cardCostController.GetCardDetails(model);

            // Assert
            var result = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Equal(400, result.StatusCode);
        }
Exemple #4
0
        public async Task PostCardCost_MockClient_ReturnsOkResult()
        {
            // Arrange
            var model = new CardCostInput
            {
                Card_Number = "4309895160019805"
            };

            // Act
            var response = await _cardCostController.GetCardDetails(model);

            // Assert
            var result = Assert.IsType <OkObjectResult>(response);

            Assert.IsAssignableFrom <BaseModel>(result.Value);
        }
Exemple #5
0
        public async Task PostCardCost_WrongLength_ReturnsBadRequest()
        {
            // Arrange
            var model = new CardCostInput
            {
                Card_Number = "43098951600"
            };

            // Act
            var response = await _cardCostController.GetCardDetails(model);

            // Assert
            var result = Assert.IsType <BadRequestObjectResult>(response);

            Assert.Equal(400, result.StatusCode);
        }