Beispiel #1
0
		public void Setup()
		{
			_customer = new Customer {Preferred = true};

			_actionNode = new ActionNode<Customer>(x => Trace.WriteLine("Called for " + x.Element.Object.Preferred));

			_constantNode = new ConstantNode<Customer>();

			_agenda = new PriorityQueueAgenda();

			_context = MockRepository.GenerateMock<RuleContext<Customer>>();
			var element = MockRepository.GenerateMock<SessionElement<Customer>>();
			element.Stub(x => x.Object).Return(_customer);
			_context.Stub(x => x.Element).Return(element);

			_context.Expect(x => x.EnqueueAgendaAction(0, null))
				.IgnoreArguments()
				.Repeat.AtLeastOnce()
				.WhenCalled(invocation =>
					{
						var priority = (int) invocation.Arguments[0];
						var action = invocation.Arguments[1] as Action;

						_agenda.Add(priority, action);
					});
		}
Beispiel #2
0
		public void The_agenda_should_be_invoked_in_priority_order_lowest_to_highest()
		{
			Action<int> action = null;
			action = MockRepository.GenerateMock<Action<int>>();
			using (action.GetMockRepository().Ordered())
			{
				action.Expect(x => x(42));
				action.Expect(x => x(27));

				Agenda a = new PriorityQueueAgenda();

				a.Add(1000, () => action(27));
				a.Add(() => action(42));

				a.Execute();

				action.VerifyAllExpectations();
			}
		}