コード例 #1
0
ファイル: TaskManagerTest.cs プロジェクト: galaktor/ngin
        public void TaskManager_ValidLogManagerValidSystemsManager_CreateInstance()
        {
            // arrange
            ILogManager lmMock = this.mocks.NewMock<ILogManager>();
            Stub.On( lmMock ).Method( "Trace" ).WithAnyArguments();
            ISystemsManager smMock = this.mocks.NewMock<ISystemsManager>();
            IMainLoopManager mlmMock = this.mocks.NewMock<IMainLoopManager>();
            Stub.On( mlmMock ).EventAdd( "HeartbeatStarted" );
            Stub.On( mlmMock ).EventAdd( "HeartbeatEnded" );
            IStateManager stmMock = this.mocks.NewMock<IStateManager>();
            ITaskManager tm;

            // act
            tm = new TaskManager( lmMock, smMock, mlmMock, stmMock );

            // assert
            Assert.IsNotNull( tm );
            Assert.IsInstanceOf<TaskManager>( tm );
        }
コード例 #2
0
ファイル: TaskManagerTest.cs プロジェクト: galaktor/ngin
        public void CallAllSystemTasksAsynchronous_10000SystemsExist_10000CallsCounted()
        {
            // arrange
            ILogManager lmMock = this.mocks.NewMock<ILogManager>();
            Stub.On( lmMock ).Method( "Trace" ).WithAnyArguments();
            int systemsCount = 10000;
            ISystem systemOne = new TestSystem( lmMock );
            //TestSystem.ResetUpdateCallsList();
            IList<ISystem> systems = new List<ISystem>( systemsCount );
            for ( int i = 0; i < systemsCount; i++ )
            {
                systems.Add( systemOne );
            }

            int taskCounter = 0;
            object taskCounterLock = new object();

            systemOne.TaskStarted += x => { lock ( taskCounterLock ) { taskCounter++; } };

            Assert.AreEqual( systemsCount, systems.Count );
            ISystemsManager smMock = this.mocks.NewMock<ISystemsManager>();
            Stub.On( smMock ).GetProperty( "RegisteredSystems" ).Will( Return.Value( systems ) );
            IMainLoopManager mlmMock = this.mocks.NewMock<IMainLoopManager>();
            Stub.On( mlmMock ).EventAdd( "HeartbeatStarted" );
            Stub.On( mlmMock ).EventAdd( "HeartbeatEnded" );
            IStateManager stmMock = this.mocks.NewMock<IStateManager>();
            ITaskManager tm = new TaskManager( lmMock, smMock, mlmMock, stmMock );

            // act
            tm.CallAllSystemTasksAsynchronous();

            // assert
            //Assert.AreEqual( systemsCount, TestSystem.UpdateCalls.Count );
            Assert.AreEqual( systemsCount, taskCounter );

            //SortedList<int, int> usedThreads = new SortedList<int, int>();
            //foreach ( int threadId in TestSystem.UpdateCalls )
            //{
            //    if ( !usedThreads.ContainsKey( threadId ) )
            //    {
            //        usedThreads.Add( threadId, threadId );
            //    }
            //}
            //if ( Environment.ProcessorCount == 1 )
            //{
            //    Assert.AreEqual( 1, usedThreads );
            //    Assert.Inconclusive( "This machine only has one CPU. Asynchronous behavious or the task manager can only work parallel on a machine with more than one CPU." );
            //}
            //if ( Environment.ProcessorCount > 1 && usedThreads.Count == 1 )
            //{
            //    Assert.Inconclusive( "The asynchronous method seems to have only used 1 thread even though this machine has more than one CPU. Run the test again to ensure it usually uses more threads." );
            //}
        }
コード例 #3
0
ファイル: TaskManagerTest.cs プロジェクト: galaktor/ngin
        public void TaskManager_SystemsManagerNull_ThrowArgumentNullException()
        {
            // arrange
            ILogManager lmMock = this.mocks.NewMock<ILogManager>();
            Stub.On( lmMock ).Method( "Trace" ).WithAnyArguments();
            ISystemsManager smMock = null;
            IMainLoopManager mlmMock = this.mocks.NewMock<IMainLoopManager>();
            Stub.On( mlmMock ).EventAdd( "HeartbeatStarted" );
            Stub.On( mlmMock ).EventAdd( "HeartbeatEnded" );
            IStateManager stmMock = this.mocks.NewMock<IStateManager>();
            ITaskManager tm;

            // act
            tm = new TaskManager( lmMock, smMock, mlmMock, stmMock );

            // assert
        }