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);
        }
Example #2
0
        public static void Setup(TestContext context)
        {
            Mock <IAdminRepository> _adminRepository = new AdminRepositoryMock()._adminRepository;
            Mock <IAppConfig>       _appConfig       = new AppConfigMock()._appConfig;

            _adminService = new AdminService(_adminRepository.Object, _appConfig.Object);
        }
        public async Task Get_ShouldReturn404_WhenCardDetailsDoesNotExistOnBinlistAPI()
        {
            //setup cache
            var baseUrl        = AppConfigMock.GetBaseUrls().BinListAPI;
            var cacheKey       = TestCards.ValidCardIIN.ToString().Substring(2);
            var binListAPIResp = string.Empty;

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

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

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

            //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 cached response is returned
            response.StatusCode.Should().Be(404);
            response.Content.As <string>().Should().Be(binListAPIResp);
        }