Exemplo n.º 1
0
        public void Async_test_should_timeout()
        {
            using (UnitTestContext context = GetContext())
            {
                context.SetTimeout(TimeSpan.FromSeconds(2));

                BackgroundWorker worker = new BackgroundWorker();
                worker.DoWork += (o, e) =>
                {
                    Thread.Sleep(TimeSpan.FromSeconds(5));
                };
                worker.RunWorkerCompleted += (o, e) =>
                {
                    // The failed Assert will pass failed test information to the context.
                    context.Assert.Fail("This is not correct! It should have timed out.");
                };
                worker.RunWorkerAsync();

                // The disposed context will see the failed test and will pass it back
                // in Silverlight and throw an exception in .NET
            }
        }