Esempio n. 1
0
        public void ShouldExecuteAllTasksInOrder()
        {
            var commands = new Mock <IProgramCommand>[]
            {
                new Mock <IProgramCommand>(),
                new Mock <IProgramCommand>(),
                new Mock <IProgramCommand>()
            };

            int j = 0;

            for (int i = 0; i < commands.Length; ++i)
            {
                // I cannot reference 'i' inside Callback because it will have always value 3 inside callback.
                // It's always referencing the same thing inside callback. meh
                // I need to create local variable - oh gosh.
                int a = i;
                commands[i].Setup(x => x.Execute(robotMock.Object)).Callback(() => Assert.Equal(j++, a));
            }

            programMock.SetupGet(x => x.Commands).Returns(commands.Select(x => x.Object));

            var exec = new ProgramExecutor(programMock.Object, robotMock.Object);

            exec.Start();

            Thread.Sleep(1000);

            Assert.True(exec.IsCompleted);
        }
Esempio n. 2
0
        public void CannotStartSameExecutorTwice()
        {
            var commands = new Mock <IProgramCommand>[]
            {
                new Mock <IProgramCommand>(),
                new Mock <IProgramCommand>(),
                new Mock <IProgramCommand>()
            };

            programMock.SetupGet(x => x.Commands).Returns(commands.Select(x => x.Object));

            var exec = new ProgramExecutor(programMock.Object, robotMock.Object);

            exec.Start();

            Assert.Throws <RobotsException>(() => exec.Start());
        }