public void Abort_WithTimeout_AbortsWithoutException() { using (var sut = new AbortableWorker(() => { Thread.Sleep(60000); return true; })) { sut.Start(); sut.ResumeWork(); sut.Abort(400); sut.ThreadInstance.Join(); Assert.True(sut.Aborted); } }
public void LastResult_ExternalWorkReturnedFalse_IsFalse() { using (var sut = new AbortableWorker(() => false)) { sut.Start(); sut.ResumeWork(); sut.WaitForWorkDone(); Assert.False(sut.LastRunResult); } }
public void LastResult_BeforeExternalWork_IsFalse() { using (var sut = new AbortableWorker(() => true)) { sut.Start(); Assert.False(sut.LastRunResult); } }
public void WorkDelegate_IsNotCalledBeforeDoWork() { var workMock = PrepareExternalWorkMock(); using (var sut = new AbortableWorker(workMock.Object.DoWork)) { sut.Start(); while (!sut.IsWaiting) Thread.Sleep(10); } workMock.Verify(x => x.DoWork(), Times.Never()); }
public void WorkDelegate_IsCalledOnceOnDoWork() { var workMock = PrepareExternalWorkMock(); using (var sut = new AbortableWorker(workMock.Object.DoWork)) { sut.Start(); sut.ResumeWork(); sut.WaitForWorkDone(Timeout.Infinite); } workMock.Verify(x => x.DoWork(), Times.Once()); }
public void OnDoWorkFalse_Aborts() { var workMock = PrepareExternalWorkMock(0); using (var sut = new AbortableWorker(workMock.Object.DoWork)) { sut.Start(); sut.ResumeWork(); sut.WaitForWorkDone(Timeout.Infinite); Assert.True(sut.ThreadInstance.Join(Timeout.Infinite)); } }