Esempio n. 1
0
        public void OnlyAllowsOneCommand()
        {
            m_coreLinkMock.Setup(link => link.Request(It.IsAny <CommandConversation>(), It.IsAny <int>()))
            .Returns(() =>
            {
                var task = new Task <StateResponse>(() =>
                {
                    Thread.Sleep(100);
                    return(new StateResponse());
                });
                task.Start();
                return(task);
            });

            var conversation = new CommandConversation(CommandType.Run);

            var firstTask = m_controller.Command(conversation, () => TimeoutAction.Wait);

            var exception = Assert.Throws <AggregateException>(() => m_controller.Command(conversation, () => TimeoutAction.Wait).Wait());

            Assert.Contains(exception.InnerExceptions, ex => ex is InvalidOperationException);

            Assert.NotNull(firstTask.Result);
        }