public void AddOrUpdateTest2() { var target = new TweetLogService(); var actual = target.AddOrUpdate(new TweetLog() { Id = Guid.NewGuid(), StatusId = "3", }); Assert.AreEqual(actual, true); using (var dbContext = new DefaultConnectionContext()) { foreach (var item in dbContext.TweetLogs) { Debug.WriteLine(item); } } }
/// <summary> /// 新しいツイートのログを取得してデータベースに保存します。 /// </summary> public void InsertTweetLog() { using (var searchService = new SearchService()) using (var tweetLogService = new TweetLogService()) { var maxId = default(ulong); var sinceId = tweetLogService.GetMaxId().GetValueOrDefault(); while (sinceId == 0 || maxId == 0 || maxId >= sinceId) { var tweetLogs = searchService.SearchByMaxId(maxId); if (tweetLogs.Length <= 1) { break; } foreach (var tweetLog in tweetLogs) { tweetLogService.AddOrUpdate(tweetLog); } maxId = ulong.Parse(tweetLogs.Min(x => x.StatusId)); } } }