Пример #1
0
 /// <summary>
 /// Get parsed markdown object asynchronously with a day and a year.
 /// </summary>
 /// <param name="year">The target year to get data.</param>
 /// <param name="day">The target day to get data.</param>
 /// <returns>Parsed <see cref="DayInfoData"/></returns>
 public async Task <DayInfoData> GetContent(int year, int day)
 {
     if (!dataList.ContainsKey((year, day)))
     {
         if (await _receiver.CheckDayData(year, day).ConfigureAwait(true))
         {
             dataList.Add((year, day), Parse(day, await _receiver.ReceiveDayData(year, day).ConfigureAwait(true)));
         }
         else
         {
             dataList.Add((year, day), DayInfoData.CreateEmpty(day));
         }
     }
     return(dataList[(year, day)]);
Пример #2
0
        public async Task DataParserTest(string input, string title, string summary, string content)
        {
            var receiverMock = new Mock <IDataReceiver>();

            receiverMock.Setup(receiver => receiver.CheckDayData(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(true);
            receiverMock.Setup(receiver => receiver.ReceiveDayData(It.IsAny <int>(), It.IsAny <int>())).ReturnsAsync(input);
            var setting = Mock.Of <IAppSettings>(set => set.SummaryLength == 80);

            var dateTime = new DefaultDateTime();

            DayReader   reader      = new DayReader(receiverMock.Object, dateTime, setting);
            DayInfoData data        = (await reader.GetContent(1).ConfigureAwait(false));
            string      parseResult = (await reader.GetContent(1).ConfigureAwait(false))?.Title;

            Assert.Equal(title, data.Title);
            Assert.Equal(summary, data.Summary);
            Assert.Equal(content, data.Content);
        }