public void ReturnsLastInactiveWorkItemWhenAllWorkItemsHaveCompletedDate() { var job = new Mock <IJob>(); job.Setup(j => j.Name).Returns("docoolstuff"); var workItems = new InMemoryDbSet <WorkItem> { new WorkItem { Id = 1, JobName = job.Object.Name, Started = DateTime.UtcNow.AddMinutes(-1), Completed = DateTime.UtcNow.AddMinutes(-1) }, new WorkItem { Id = 2, JobName = job.Object.Name, Started = DateTime.UtcNow, Completed = DateTime.UtcNow } }; var context = new Mock <WorkItemsContext>(); context.Object.WorkItems = workItems; var repository = new EntityWorkItemRepository(() => context.Object); var activeWorker = repository.GetLastWorkItem(job.Object); Assert.Equal(2, activeWorker.Id); Assert.False(activeWorker.IsActive()); }
public void ReturnsNullWhenNoWorkItemsReturnedForGivenJob() { var job = new Mock <IJob>(); job.Setup(j => j.Name).Returns("docoolstuff"); var workItems = new InMemoryDbSet <WorkItem> { new WorkItem { JobName = "DoNotDoAnyCoolStuff", Started = DateTime.UtcNow, Completed = DateTime.UtcNow } }; var context = new Mock <WorkItemsContext>(); context.Object.WorkItems = workItems; var repository = new EntityWorkItemRepository(() => context.Object); var activeWorkItem = repository.GetLastWorkItem(job.Object); Assert.Null(activeWorkItem); }
public void ReturnsActiveWorkItemWhenAWorkerHasNoCompletedDate() { var job = new Mock <IJob>(); job.Setup(j => j.Name).Returns("docoolstuffjobname"); var workItems = new InMemoryDbSet <WorkItem> { new WorkItem { JobName = job.Object.Name, Started = DateTime.UtcNow, Completed = null } }; var context = new Mock <WorkItemsContext>(); context.Object.WorkItems = workItems; var repository = new EntityWorkItemRepository(() => context.Object); var activeWorkItem = repository.GetLastWorkItem(job.Object); Assert.True(activeWorkItem.IsActive()); }