Пример #1
0
		public void DontOfferTwiceTest()
		{
			var scheduler = new TestScheduler ();
			var block = new BroadcastBlock<int> (null,
				new DataflowBlockOptions { TaskScheduler = scheduler });
			var target =
				new TestTargetBlock<int> { Postpone = true };
			block.LinkTo (target);

			Assert.IsFalse (target.HasPostponed);

			Assert.IsTrue (block.Post (1));

			scheduler.ExecuteAll();

			Assert.IsTrue (target.HasPostponed);

			target.Postpone = false;

			int value;
			Assert.IsTrue(target.RetryPostponed(out value));
			Assert.AreEqual(1, value);

			block.LinkTo(new BufferBlock<int>());

			scheduler.ExecuteAll();

			Assert.AreEqual(default(int), target.DirectlyAccepted);
		}
Пример #2
0
		public void ReserveChangedTest ()
		{
			var scheduler = new TestScheduler ();
			var broadcast = new BroadcastBlock<int> (null,
				new DataflowBlockOptions { TaskScheduler = scheduler });
			var target = new TestTargetBlock<int> { Postpone = true };

			broadcast.LinkTo (target);

			Assert.IsFalse (target.HasPostponed);

			Assert.IsTrue (broadcast.Post (1));

			scheduler.ExecuteAll ();

			Assert.IsTrue (target.HasPostponed);

			Assert.IsTrue(broadcast.Post(2));

			scheduler.ExecuteAll ();

			Assert.IsTrue (target.ReservePostponed ());

			int value;
			Assert.IsTrue (target.RetryPostponed (out value));
			Assert.AreEqual (2, value);
		}