Source/Csla.test/Threading/BackgroundWorkerTests.cs
/// <summary>
///A test for BackgroundWorker normal run 
///</summary>
A test for BackgroundWorker normal run
A test for BackgroundWorker normal run
[TestMethod]
    public void BackgroundWorker_RunWorkerAsync_CallsDoWorkAndWorkerCompleted()
    {
      using (UnitTestContext context = GetContext())
      {
        BackgroundWorkerSyncContextHelper.DoTests(() =>
        {
          var UIThreadid = Thread.CurrentThread.ManagedThreadId;
          Csla.ApplicationContext.User = new ClaimsPrincipal();
          Csla.ApplicationContext.ClientContext["BWTEST"] = "TEST";
          Csla.ApplicationContext.GlobalContext["BWTEST"] = "TEST";
          Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("FR");
          Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("FR");
          BackgroundWorker target = new BackgroundWorker();
          bool doWorkCalled = false;
          target.DoWork += (o, e) =>
          {
            doWorkCalled = true;
            context.Assert.IsFalse(Thread.CurrentThread.ManagedThreadId == UIThreadid);
            context.Assert.IsTrue(Csla.ApplicationContext.User is ClaimsPrincipal);
            context.Assert.AreEqual("TEST", Csla.ApplicationContext.GlobalContext["BWTEST"]);
            context.Assert.AreEqual("TEST", Csla.ApplicationContext.ClientContext["BWTEST"]);
            context.Assert.AreEqual("FR", Thread.CurrentThread.CurrentCulture.Name.ToUpper());
            context.Assert.AreEqual("FR", Thread.CurrentThread.CurrentUICulture.Name.ToUpper());
          };
          target.RunWorkerCompleted += (o, e) =>
          {
            context.Assert.IsTrue(Thread.CurrentThread.ManagedThreadId == UIThreadid);
            context.Assert.IsNull(e.Error);
            context.Assert.IsTrue(doWorkCalled, "Do work has been called");
            context.Assert.Success();
          };
          target.RunWorkerAsync(null);
          while (target.IsBusy)
          {
            BackgroundWorkerSyncContextHelper.PumpDispatcher();
          }
          context.Complete();
        });
      }
    }
[ TestMethod ] public void BackgroundWorker_RunWorkerAsync_CallsDoWorkAndWorkerCompleted ( ) { using ( UnitTestContext context = GetContext ( ) ) { BackgroundWorkerSyncContextHelper . DoTests ( ( ) => { var UIThreadid = Thread . CurrentThread . ManagedThreadId ; Csla . ApplicationContext . User = new ClaimsPrincipal ( ) ; Csla . ApplicationContext . ClientContext [ " " ] = " " ; Csla . ApplicationContext . GlobalContext [ " " ] = " " ; Thread . CurrentThread . CurrentCulture = CultureInfo . GetCultureInfo ( " " ) ; Thread . CurrentThread . CurrentUICulture = CultureInfo . GetCultureInfo ( " " ) ; BackgroundWorker target = new BackgroundWorker ( ) ; bool doWorkCalled = false ; target . DoWork += ( o , e ) => { doWorkCalled = true ; context . Assert . IsFalse ( Thread . CurrentThread . ManagedThreadId == UIThreadid ) ; context . Assert . IsTrue ( Csla . ApplicationContext . User is ClaimsPrincipal ) ; context . Assert . AreEqual ( " " , Csla . ApplicationContext . GlobalContext [ " " ] ) ; context . Assert . AreEqual ( " " , Csla . ApplicationContext . ClientContext [ " " ] ) ; context . Assert . AreEqual ( " " , Thread . CurrentThread . CurrentCulture . Name . ToUpper ( ) ) ; context . Assert . AreEqual ( " " , Thread . CurrentThread . CurrentUICulture . Name . ToUpper ( ) ) ; } ; target . RunWorkerCompleted += ( o , e ) => { context . Assert . IsTrue ( Thread . CurrentThread . ManagedThreadId == UIThreadid ) ; context . Assert . IsNull ( e . Error ) ; context . Assert . IsTrue ( doWorkCalled , " " ) ; context . Assert . Success ( ) ; } ; target . RunWorkerAsync ( null ) ; while ( target . IsBusy ) { BackgroundWorkerSyncContextHelper . PumpDispatcher ( ) ; } context . Complete ( ) ; } ) ; } }
A test for BackgroundWorker normal run
A test for BackgroundWorker normal run
// make sure that user, clientcontext, globalcontext, currentCulture and currentUIculture are sent  // assert that this callback comes on the "UI" thread  // this is the equvalent to Application.DoEvents in Windows Forms 