public async Task StartJob_RegularInvocation_ShouldGetAllIssuesUpdatedAtSameTime() { //arange var dateTime = DateTime.Now; var client = CreateRestClient("https://your_jira_address/"); var fields = new RemoteIssue { updated = dateTime, id = "id4", key = "key4", description = "description4", summary = "summary4" }; var myIssue = new Issue(client, fields); var firstIssues = new List <Issue> { myIssue, myIssue, myIssue }; var secondIssues = new List <Issue> { myIssue }; var firstResponse = new MockPagedQueryResult <Issue>(firstIssues) { TotalItems = 4 }; var secondResponse = new MockPagedQueryResult <Issue>(secondIssues) { TotalItems = 1 }; _applicationPropertyDaoMock .Setup(s => s.GetAsync()) .ReturnsAsync(new ApplicationProperty { JiraJobLastUpdate = dateTime }); _applicationPropertyDaoMock .Setup(s => s.UpsertPropertyAsync(It.IsAny <Expression <Func <ApplicationProperty, DateTime> > >(), It.IsAny <DateTime>())) .Returns(Task.CompletedTask); _jiraClientMock .SetupSequence(s => s.GetLatestIssuesAsync(It.IsAny <string[]>(), It.IsAny <DateTime>(), It.IsAny <int>(), It.IsAny <int>())) .ReturnsAsync(firstResponse) .ReturnsAsync(secondResponse); _elasticsearchClientMock .Setup(s => s.UpsertManyAsync(It.IsAny <JiraElasticUpsertRequest>())) .Returns(Task.CompletedTask); //act await _job.StartJob(); //assert _jiraClientMock.Verify(v => v .GetLatestIssuesAsync(It.IsAny <string[]>(), It.IsAny <DateTime>(), It.IsAny <int>(), 0), Times.Once); _jiraClientMock.Verify(v => v .GetLatestIssuesAsync(It.IsAny <string[]>(), It.IsAny <DateTime>(), It.IsAny <int>(), _settingsMock.Object.Value.BatchSize), Times.Once); _jiraClientMock.VerifyNoOtherCalls(); }
public JiraJobTests() { _applicationPropertyDaoMock = new Mock <IApplicationPropertyDao>(); _elasticsearchClientMock = new Mock <IElasticsearchClient>(); _jiraClientMock = new Mock <IJiraClient>(); var loggerMock = new Mock <ILogger <JiraJob> >(); _settingsMock = new Mock <IOptions <JiraSettings> >(); _settingsMock .SetupGet(m => m.Value) .Returns(() => new JiraSettings { User = "******", Password = "******", BaseAddress = "https://your_jira_address/", BatchSize = 3, ProjectNames = new[] { "test", "test1", "test2" } }); _job = new JiraJob(loggerMock.Object, _elasticsearchClientMock.Object, _applicationPropertyDaoMock.Object, _jiraClientMock.Object, _settingsMock.Object); var client = CreateRestClient("https://your_jira_address/"); var fields = new RemoteIssue { updated = DateTime.UtcNow, id = "id1", key = "key1", description = "description1", summary = "summary1" }; var myIssue1 = new Issue(client, fields); fields = new RemoteIssue { updated = DateTime.UtcNow, id = "id2", key = "key2", description = "description2", summary = "summary2" }; var myIssue2 = new Issue(client, fields); fields = new RemoteIssue { updated = DateTime.UtcNow, id = "id3", key = "key3", description = "description3", summary = "summary3" }; var myIssue3 = new Issue(client, fields); var issues = new List <Issue> { myIssue1, myIssue2, myIssue3 }; var orderedIssues = issues.OrderBy(i => i.Updated); _response = new MockPagedQueryResult <Issue>(orderedIssues) { TotalItems = 3 }; }