public async Task Opens_existing_database(CachedIssue issue) { var databaseFile = "file2.db"; if (File.Exists(databaseFile)) { File.Delete(databaseFile); } using (var repo = new SqliteJiraLocalCacheRepository(databaseFile)) { await repo.Initialize(); await repo.AddOrReplaceCachedIssue(issue); } using (var repo = new SqliteJiraLocalCacheRepository(databaseFile)) { await repo.Initialize(); var retrievedIssue = (await repo.GetIssues()).SingleOrDefault(); issue.ShouldCompare(retrievedIssue); } }
public async Task Repository_saves_whole_issue(CachedIssue issue) { await Repository.Initialize(); await Repository.AddOrReplaceCachedIssue(issue); var retrievedIssue = (await Repository.GetIssues()).SingleOrDefault(); issue.ShouldCompare(retrievedIssue); }
public Task AddOrReplaceCachedIssue(CachedIssue flatIssue) { var cachedIssue = _issues.FirstOrDefault(x => x.Key == flatIssue.Key); if (cachedIssue != null) { _issues.Remove(cachedIssue); } _issues.Insert(Math.Max(0, _issues.Count - 2), flatIssue); // inserting things out-of-order, to simulate sql's behavior of not keeping order return(Task.CompletedTask); }
public Task <CachedIssue> RetrieveDetails(IJiraIssue issue) { var fake = (FakeJiraIssue)issue; var changes = fake.StatusChanges.Select(x => new CachedIssueStatusChange(new DateTime(), x)).ToArray(); CachedIssue cachedIssue = new CachedIssue() { Project = fake.Project, Key = fake.Key, Created = fake.Created, Updated = fake.Updated, Status = fake.Status, StatusChanges = new Collection <CachedIssueStatusChange>(changes) }; return(Task.FromResult(cachedIssue)); }
public async Task Update(IJiraClient client, DateTime startUpdateDate, string projectKey, ICacheUpdateProgress progress = null) { await EnsureInitialized(); progress = progress ?? new NullCacheUpdateProgres(); if (client == null) { throw new ArgumentNullException(nameof(client)); } if (string.IsNullOrWhiteSpace(projectKey)) { throw new ArgumentNullException(nameof(projectKey)); } DateTime lastUpdateDate = await GetLastUpdateDateTime(projectKey, startUpdateDate); int itemPaging = 0; while (true) { const int queryLimit = 50; IJiraIssue[] updatedIssues = await client.GetIssues(projectKey, lastUpdateDate, queryLimit, itemPaging); foreach (var issue in updatedIssues) { CachedIssue flatIssue = await client.RetrieveDetails(issue); await _repository.AddOrReplaceCachedIssue(flatIssue); progress.UpdatedIssue(flatIssue.Key, flatIssue.Updated.Value); } itemPaging += queryLimit; if (updatedIssues.Length != queryLimit) { break; } } }