Example #1
0
		public void Wait_Inlined ()
		{
			bool? previouslyQueued = null;

			var scheduler = new MockScheduler ();
			scheduler.TryExecuteTaskInlineHandler += (task, b) => {
				previouslyQueued = b;
			};

			var tf = new TaskFactory (scheduler);
			var t = tf.StartNew (() => { });
			t.Wait ();

			Assert.AreEqual (true, previouslyQueued);
		}
Example #2
0
        public void RunSynchronously_SchedulerException()
        {
            var scheduler = new MockScheduler();

            scheduler.TryExecuteTaskInlineHandler += (task, b) => {
                throw new ApplicationException();
            };

            Task t = new Task(() => { });

            try
            {
                t.RunSynchronously(scheduler);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(t.Exception.InnerException, e);
            }
        }
Example #3
0
		public void RunSynchronously ()
		{
			var val = 0;
			Task t = new Task (() => { Thread.Sleep (100); val = 1; });
			t.RunSynchronously ();

			Assert.AreEqual (1, val, "#1");

			t = new Task (() => { Thread.Sleep (0); val = 2; });

			bool? previouslyQueued = null;

			var scheduler = new MockScheduler ();
			scheduler.TryExecuteTaskInlineHandler += (task, b) => {
				previouslyQueued = b;
			};

			t.RunSynchronously (scheduler);

			Assert.AreEqual (2, val, "#2");
			Assert.AreEqual (false, previouslyQueued, "#2a");
		}
Example #4
0
		public void RunSynchronously ()
		{
			var val = 0;
			Task t = new Task (() => { Thread.Sleep (100); val = 1; });
			t.RunSynchronously ();

			Assert.AreEqual (1, val, "#1");

			t = new Task (() => { Thread.Sleep (0); val = 2; });

			bool? previouslyQueued = null;

			var scheduler = new MockScheduler ();
			scheduler.TryExecuteTaskInlineHandler += (task, b) => {
				previouslyQueued = b;
			};

			t.RunSynchronously (scheduler);

			Assert.AreEqual (2, val, "#2");
			Assert.AreEqual (false, previouslyQueued, "#2a");
		}
Example #5
0
		public void Wait_Inlined ()
		{
			bool? previouslyQueued = null;

			var scheduler = new MockScheduler ();
			scheduler.TryExecuteTaskInlineHandler += (task, b) => {
				previouslyQueued = b;
			};

			var tf = new TaskFactory (scheduler);
			var t = tf.StartNew (() => { });
			t.Wait ();

			Assert.AreEqual (true, previouslyQueued);
		}
Example #6
0
        public void RunSynchronously_SchedulerException()
        {
            var scheduler = new MockScheduler();
            scheduler.TryExecuteTaskInlineHandler += (task, b) => {
                throw new ApplicationException();
            };

            Task t = new Task(() => { });
            try
            {
                t.RunSynchronously(scheduler);
                Assert.Fail();
            }
            catch (Exception e)
            {
                Assert.AreEqual(t.Exception.InnerException, e);
            }
        }