Source/Csla.test/Threading/BackgroundWorkerTests.cs
/// <summary>
///A test for BackgroundWorker when reporting progress
///</summary>
A test for BackgroundWorker when reporting progress
A test for BackgroundWorker when reporting progress
[TestMethod]
    [TestCategory("SkipWhenLiveUnitTesting")]
    public void BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue()
    {
      UnitTestContext context = GetContext();
      BackgroundWorker target = new BackgroundWorker();
      target.DoWork += (o, e) =>
      {
        for (int i = 1; i < 11; i++)
        {
          Thread.Sleep(100);
          if (target.CancellationPending)
          {
            e.Cancel = true;
            return;
          }
        }
      };
      target.WorkerSupportsCancellation = true;
      target.RunWorkerCompleted += (o, e) =>
      {
        context.Assert.IsNull(e.Error);
        context.Assert.IsTrue(e.Cancelled);
        context.Assert.Success();
      };
      target.RunWorkerAsync(null);
      target.CancelAsync();
      context.Complete();
    }
[ TestMethod ] [ TestCategory ( " " ) ] public void BackgroundWorker_CancelAsync_ReportsCancelledWhenWorkerSupportsCancellationIsTrue ( ) { UnitTestContext context = GetContext ( ) ; BackgroundWorker target = new BackgroundWorker ( ) ; target . DoWork += ( o , e ) => { for ( int i = 1 ; i < 11 ; i ++ ) { Thread . Sleep ( 100 ) ; if ( target . CancellationPending ) { e . Cancel = true ; return ; } } } ; target . WorkerSupportsCancellation = true ; target . RunWorkerCompleted += ( o , e ) => { context . Assert . IsNull ( e . Error ) ; context . Assert . IsTrue ( e . Cancelled ) ; context . Assert . Success ( ) ; } ; target . RunWorkerAsync ( null ) ; target . CancelAsync ( ) ; context . Complete ( ) ; }
A test for BackgroundWorker when reporting progress
A test for BackgroundWorker when reporting progress
// report progress changed 10 times //  target does not support ReportProgress we shold get a System.InvalidOperationException from DoWork