Esempio n. 1
0
        public async void GetNextQuestion_should_not_call_restClient_if_present_in_cache()
        {
            //Arrange

            var id               = "idQ1";
            var nodeLabel        = "Question";
            var answer           = "no";
            var expectedCacheKey = new QuestionWithAnswersCacheKey(id, nodeLabel, answer);

            ArrageDomainRequestMock(_mockQuestionRestResponse);
            _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(JsonConvert.SerializeObject(_mockQuestionRestResponse.Data));
            var sut = new QuestionService(_configuration.Object, _restClient.Object, _answersForNodeBuilder.Object,
                                          _modZeroJourneyStepsBuilder.Object, _keywordCollector.Object, _careAdviceService.Object, _careAdviceTransformer.Object, _cacheStoreMock);


            //Act
            var result = await sut.GetNextQuestion(id, nodeLabel, answer);

            //Assert
            _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Never);
            _cacheManagerMock.Verify(x => x.Read(expectedCacheKey.CacheKey), Times.Once);
            _configuration.Verify(x => x.GetDomainApiNextQuestionUrl(id, nodeLabel), Times.Never);
            _restClient.Verify(x => x.ExecuteAsync <QuestionWithAnswers>(It.IsAny <IRestRequest>()), Times.Never);
            Assert.That(result.Question.Title, Is.EqualTo(_mockQuestionRestResponse.Data.Question.Title));
        }
Esempio n. 2
0
        public async void GetNextQuestion_should_not_add_to_cache_for_Empty_restclient_response()
        {
            //Arrange

            var id               = "idQ1";
            var nodeLabel        = "Question";
            var answer           = "no";
            var expectedCacheKey = new QuestionWithAnswersCacheKey(id, nodeLabel, answer);

            ArrageDomainRequestMock(new RestResponse <QuestionWithAnswers>()
            {
                Data = new QuestionWithAnswersBuilder().Build()
            });
            _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty);

            var sut = new QuestionService(_configuration.Object, _restClient.Object, _answersForNodeBuilder.Object,
                                          _modZeroJourneyStepsBuilder.Object, _keywordCollector.Object, _careAdviceService.Object, _careAdviceTransformer.Object, _cacheStoreMock);


            //Act
            var result = await sut.GetNextQuestion(id, nodeLabel, answer);

            //Assert
            _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Never);
            _configuration.Verify(x => x.GetDomainApiNextQuestionUrl(id, nodeLabel), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <QuestionWithAnswers>(It.IsAny <IRestRequest>()), Times.Once);
        }
 public async Task <QuestionWithAnswers> GetFirstQuestion(string pathwayId)
 {
     return(await _cacheStore.GetOrAdd(QuestionWithAnswersCacheKey.WithPathwayId(pathwayId), async() =>
     {
         var questions = await _restClient.ExecuteAsync <QuestionWithAnswers>(new JsonRestRequest(_configuration.GetDomainApiFirstQuestionUrl(pathwayId), Method.GET));
         return questions.Data;
     }));
 }
Esempio n. 4
0
        public async void GetFirstQuestion_should_return_a_question_by_pathway_id_before_adding_to_cache()
        {
            //Arrange
            var pathwayId = "idPW1";

            ArrageDomainRequestMock(_mockQuestionRestResponse);
            var expectedCacheKey = QuestionWithAnswersCacheKey.WithPathwayId(pathwayId);

            _cacheManagerMock.Setup(x => x.Read(It.IsAny <string>())).ReturnsAsync(string.Empty);

            var sut = new QuestionService(_configuration.Object, _restClient.Object, _answersForNodeBuilder.Object,
                                          _modZeroJourneyStepsBuilder.Object, _keywordCollector.Object, _careAdviceService.Object, _careAdviceTransformer.Object, _cacheStoreMock);
            //Act
            var result = await sut.GetFirstQuestion(pathwayId);

            //Assert
            _cacheManagerMock.Verify(x => x.Set(expectedCacheKey.CacheKey, It.IsAny <string>()), Times.Once);
            _configuration.Verify(x => x.GetDomainApiFirstQuestionUrl(pathwayId), Times.Once);
            _restClient.Verify(x => x.ExecuteAsync <QuestionWithAnswers>(It.IsAny <IRestRequest>()), Times.Once);
            Assert.That(result.Question.Title, Is.EqualTo(_mockQuestionRestResponse.Data.Question.Title));
        }