Esempio n. 1
0
        /// <summary>
        /// Create a ActiveContextManager and add total number of IActiveContexts to it.
        /// Expect to receive notification in the observer
        /// </summary>
        /// <returns></returns>
        private static ActiveContextManager InitializeActiveContextManager()
        {
            const int totalEvaluators      = 5;
            var       activeContextManager = new ActiveContextManager(totalEvaluators);
            var       contextObserver      = new TestContextObserver(totalEvaluators);

            activeContextManager.Subscribe(contextObserver);

            for (int i = 0; i < totalEvaluators; i++)
            {
                activeContextManager.Add(CreateMockActiveContext(i));
            }
            Assert.Equal(totalEvaluators, activeContextManager.NumberOfActiveContexts);
            Assert.Equal(totalEvaluators, contextObserver.NumberOfActiveContextsReceived());

            return(activeContextManager);
        }
Esempio n. 2
0
        /// <summary>
        /// Test invalid Add and Remove
        /// </summary>
        public void TestInvalidAddRemoveCases()
        {
            const int totalEvaluators      = 3;
            var       activeContextManager = new ActiveContextManager(totalEvaluators);

            activeContextManager.Add(CreateMockActiveContext(1));

            Action add = () => activeContextManager.Add(CreateMockActiveContext(1));

            Assert.Throws <IMRUSystemException>(add);

            Action remove = () => activeContextManager.Remove(ContextIdPrefix + 2);

            Assert.Throws <IMRUSystemException>(remove);

            activeContextManager.Add(CreateMockActiveContext(2));
            activeContextManager.Add(CreateMockActiveContext(3));

            add = () => activeContextManager.Add(CreateMockActiveContext(4));
            Assert.Throws <IMRUSystemException>(add);
        }