Ejemplo n.º 1
0
        public async Task LogHitCountToDb_ShouldReturnNoOfRowsAffected_WhenInquiryRecordIsSaved()
        {
            //setup response
            int rowsAffected   = 1;
            var testCardIIN    = TestCards.ValidCardIIN;
            var binListAPiResp = ResponseMock.GetCardIINResp(200);
            var cardDetails    = JsonConvert.DeserializeObject <GetCardDetailsDTO>(binListAPiResp?.Content);

            var newCardInquiry = new CardInquiryLog()
            {
                IIN         = testCardIIN.ToString(),
                InquiryDate = DateTime.Now,
                NoOfHit     = 1,
                Status      = "success"
            };

            //setup File logging
            _loggerMock.Setup(x =>
                              x.LogError(It.IsAny <string>()));

            //setup repository
            _unitOfWorkMock.Setup(x =>
                                  x.CardInquiries.AddCardInquiry(newCardInquiry));

            _unitOfWorkMock.Setup(x =>
                                  x.SaveChanges())
            .Returns(rowsAffected);

            //test service method
            var rowCount = await _sut.LogHitCountToDb(It.IsAny <string>(), testCardIIN.ToString(), cardDetails);

            rowCount.Should().Be(rowsAffected);
        }
Ejemplo n.º 2
0
        public async Task GetCardDetailsWithBIN_ShouldReturnNotFound_WhenCardIINDoesNotExist()
        {
            var testCardIIN = TestCards.RandomCardIIN;

            _responseHandlerMock.Setup(x => x.CommitResponse(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>()))
            .Returns(ResponseMock.GetAppResponse(ResponseCodes.NOT_FOUND));

            //setup File logging
            _loggerMock.Setup(x =>
                              x.LogInfo(It.IsAny <string>()));

            //setup httpClient
            _httpClientMock.Setup(x =>
                                  x.Get($"{_baseUrlMock.Value.BinListAPI}/{testCardIIN}", It.IsAny <string>(), testCardIIN.ToString()))
            .ReturnsAsync(ResponseMock.GetCardIINResp(404));


            //sevice method test
            var response = await _sut.GetCardDetailsWithBIN(testCardIIN);

            //Verify response was logged to file
            _loggerMock.Verify(x =>
                               x.LogInfo(It.IsAny <string>()), Times.AtLeastOnce);

            response.Code.Should().Be(ResponseCodes.NOT_FOUND);
        }
Ejemplo n.º 3
0
        public async Task GetCardDetailsWithBIN_ShouldReturnResourceUnavailable_WhenBinListApiIsNotReachable()
        {
            var testCardIIN = TestCards.RandomCardIIN;

            _responseHandlerMock.Setup(x => x.CommitResponse(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <object>()))
            .Returns(ResponseMock.GetAppResponse(ResponseCodes.RESOURCE_UNAVAILABLE));

            //setup File logging
            _loggerMock.Setup(x =>
                              x.LogInfo(It.IsAny <string>()));

            //setup httpClient
            _httpClientMock.Setup(x =>
                                  x.Get($"{_baseUrlMock.Value.BinListAPI}/{testCardIIN}", It.IsAny <string>(), testCardIIN.ToString()))
            .ReturnsAsync(ResponseMock.GetCardIINResp(500));


            //sevice method test
            var response = await _sut.GetCardDetailsWithBIN(testCardIIN);

            //Verify response was logged to file
            _loggerMock.Verify(x =>
                               x.LogInfo(It.IsAny <string>()), Times.AtLeastOnce);

            response.Code.Should().Be(ResponseCodes.RESOURCE_UNAVAILABLE);
        }
Ejemplo n.º 4
0
        public async Task Get_ShouldReturnDataFromBinListAPI_WhenNoDataInCacheForPassedKey()
        {
            //setup cache
            var baseUrl        = AppConfigMock.GetBaseUrls().BinListAPI;
            var cacheKey       = TestCards.ValidCardIIN.ToString().Substring(2);
            var binListAPIResp = (object)ResponseMock.GetCardIINResp().Content;

            _httpCacheMock.Setup(x =>
                                 x.LoadFromCache <object>(cacheKey))
            .Returns(string.Empty);

            //setup restclient
            _restResponseMock.Setup(x => x.StatusCode)
            .Returns(HttpStatusCode.OK);

            _restResponseMock.Setup(x => x.Content)
            .Returns(binListAPIResp.ToString());

            //setup logger
            _loggerMock.Setup(x =>
                              x.LogInfo(It.IsAny <string>()));

            //test service method
            var response = await _sut.Get($"{baseUrl}/{TestCards.ValidCardIIN}", It.IsAny <string>(), cacheKey);

            //Verify http response was logged
            _loggerMock.Verify(x =>
                               x.LogInfo(It.IsAny <string>()), Times.Once);

            //Verify response is returned from BinlistAPI
            response.StatusCode.Should().Be(200);
            response.Content.As <object>().Should().Be(binListAPIResp);
        }
Ejemplo n.º 5
0
        public async Task GetCardDetailsWithBIN_ShouldReturnCardDetails_WhenCardIINIsValid()
        {
            var testCardIIN = TestCards.ValidCardIIN;

            //setup response handler
            var binListAPIResp = ResponseMock.GetCardIINResp();
            var cardDetails    = JsonConvert.DeserializeObject <GetCardDetailsDTO>(binListAPIResp.Content);

            _responseHandlerMock.Setup(x =>
                                       x.CommitResponse(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <GetCardDetailsDTO>()))
            .Returns(ResponseMock.GetAppResponse(ResponseCodes.SUCCESS, null, cardDetails));

            //setup File logging
            _loggerMock.Setup(x =>
                              x.LogInfo(It.IsAny <string>()));

            //setup httpClient
            _httpClientMock.Setup(x =>
                                  x.Get($"{_baseUrlMock.Value.BinListAPI}/{testCardIIN}", It.IsAny <string>(), testCardIIN.ToString()))
            .ReturnsAsync(binListAPIResp);

            //setup queue
            var queueMessage = ResponseMock.GetQueueMessage(testCardIIN.ToString());
            var eventId      = "client.notify";

            _eventPublisherMock.Setup(x =>
                                      x.PublishPayload(queueMessage, eventId));

            //setup database logging
            _inquiryCountSvcMock.Setup(x =>
                                       x.LogHitCountToDb(It.IsAny <string>(), testCardIIN.ToString(), It.IsAny <GetCardDetailsDTO>()))
            .ReturnsAsync(1);

            //sevice method test
            var response = await _sut.GetCardDetailsWithBIN(testCardIIN);

            //verify event was published to the queue once
            _eventPublisherMock.Verify(x =>
                                       x.PublishPayload(queueMessage, eventId), Times.Once);

            //Verify database log was made
            _inquiryCountSvcMock.Verify(x =>
                                        x.LogHitCountToDb(It.IsAny <string>(), testCardIIN.ToString(), It.IsAny <GetCardDetailsDTO>()), Times.Once);

            //Verify response was logged to file
            _loggerMock.Verify(x =>
                               x.LogInfo(It.IsAny <string>()), Times.AtLeastOnce);

            response.Code.Should().Be(ResponseCodes.SUCCESS);
            response.Data.As <GetCardDetailsDTO>().Should().Be(cardDetails);
        }