0

The following class has a method that calls the ReportProgress method of a 'BackgroundWorker`:

public class Project
{
    protected System.ComponentModel.BackgroundWorker worker;

    public void progress(int percentage)
    {
        if (worker != null)
             worker.ReportProgress(percentage);
    }
}

How to go about testing the progress method? The aim would be to test that the worker method has its ReportProgress method called with the correct argument. Correct me if this approach is wrong.

What has been tried is using FakeItEasy to create a fake of the BackgroundWorker, but that yields the error: "non virtual methods can not be intercepted".

Al2110
  • 566
  • 9
  • 25
  • https://blog.lextudio.com/how-to-replace-backgroundworker-with-async-await-and-tasks-80d7c8ed89dc Consider leaving it behind. – Lex Li Jun 16 '20 at 05:38
  • Yes, a `Task` should probably be used instead. However, the whole project uses `BackgroundWorker`, and I don't think it can be changed now. Is there any way to test the above method as is? – Al2110 Jun 16 '20 at 05:42
  • @Al2110 Is it an option for you to replace `BackgroundWorker` with `Task.Run` and `IProgress`? For further details please check [Stephen Cleary's excellent article](https://blog.stephencleary.com/2013/09/taskrun-vs-backgroundworker-round-5.html) – Peter Csala Jun 17 '20 at 12:07

0 Answers0