Exemplo n.º 1
0
        public void GetHitCount_ShouldReturnNotFound_WhenCardInquiryRecordDoesNotExist()
        {
            //setup response
            int count     = 0;
            var hitCounts = ResponseMock.GetHitCountDTO(count);

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


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

            //setup repository
            _unitOfWorkMock.Setup(x =>
                                  x.CardInquiries.GetNoOfHits())
            .Returns(ResponseMock.GetListofCardInquiries(true));

            //test service method
            var response = _sut.GetHitCount();

            response.Code.Should().Be(ResponseCodes.NOT_FOUND);
            response.Data.As <GetHitCountDTO>().Should().Be(hitCounts);
            hitCounts.Success.Should().BeFalse();
            hitCounts.Size.Should().Be(count);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
0
        public async Task GetCardDetailsWithBIN_ShouldReturnInvalidParam_WhenCardIINIsNotValid()
        {
            var testCardIIN = TestCards.InvalidCardIIN;

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

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


            //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.INVALID_PARAM);
        }