public async void Send_routes_GetSentencesQuery_to_correct_service_and_gets_expected_response() { var mockedLogger = new Mock <ILogger <Mediator> >(); var mockedStoreAnalyzedSentenceService = new Mock <IStoreAnalyzedSentenceService>(); var mockedGetKeywordService = new Mock <IGetKeywordsService>(); var mockedGetYearMonthService = new Mock <IGetYearMonthsService>(); var mockedGetSentencesService = new Mock <IGetSentencesService>(); var sentences = new List <Sentence>(); sentences.Add(new Sentence() { Text = "example sentence" }); mockedGetSentencesService.Setup(s => s.GetAsync(It.IsAny <GetSentencesQuery>())) .ReturnsAsync(sentences); var mediator = new Mediator(mockedLogger.Object, mockedStoreAnalyzedSentenceService.Object, mockedGetKeywordService.Object, mockedGetYearMonthService.Object, mockedGetSentencesService.Object); var query = new GetSentencesQuery(); var listOfSentences = await mediator.SendAsync <List <Sentence> >(query); mockedGetSentencesService.Verify(s => s.GetAsync(It.IsAny <GetSentencesQuery>()), Times.Exactly(1)); Assert.True(listOfSentences.Count == 1); Assert.True(listOfSentences[0].Text == "example sentence"); }
public override async Task <GetSentencesResponse> GetSentences(GetSentencesRequest req, ServerCallContext context) { var query = new GetSentencesQuery(); query.Keyword = req.Keyword; query.YearMonth = req.YearMonth.ToDateTime(); var sentences = await _mediator.SendAsync <List <Sentence> >(query); var response = new GetSentencesResponse(); foreach (var sentence in sentences) { var s = new StorageEndpoint.GetSentencesResponse.Types.Sentence() { Keyword = new StorageEndpoint.GetSentencesResponse.Types.Sentence.Types.Keyword() { Text = sentence.Keyword.Text }, Source = new StorageEndpoint.GetSentencesResponse.Types.Sentence.Types.Source() { Url = sentence.Source.Url }, Positive = sentence.Positive, Received = Timestamp.FromDateTime(sentence.Received.ToUniversalTime()), Sourcearticleheader = sentence.SourceArticleHeader, Sourcearticleurl = sentence.SourceArticleUrl, Text = sentence.Text }; response.Sentences.Add(s); } return(response); }
public async Task <List <Sentence> > GetSentencesAsync(GetSentencesQuery query) { var sentences = await _storageDbContext.Sentences.Where(s => s.Keyword.Text == query.Keyword && s.Received.Year == query.YearMonth.Year && s.Received.Month == query.YearMonth.Month) .Include(s => s.Keyword) .Include(s => s.Source) .OrderByDescending(s => s.Received) .ToListAsync(); return(sentences); }
public async Task <List <Sentence> > GetAsync(GetSentencesQuery query) { _logger.LogInformation("fetching sentences by keyword and month"); return(await _databaseAccess.GetSentencesAsync(query)); }