public async Task ThenCommandIsEnabled()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), true);
            Assert.IsTrue(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand)));
        }
コード例 #2
0
        internal async Task <bool> ControllerCanIdentifyNonMainThread(ApplicationCommandControllerTestExecutionContext context)
        {
            var notMainThread = false;
            await Task.Run(() => { notMainThread = !context.Controller.IsMainThread(); });

            return(notMainThread);
        }
コード例 #3
0
        public void CanIdentifySecondaryThread()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);
            var controllerCanIdentifyNonMainThread = ControllerCanIdentifyNonMainThread(executionContext);

            Assert.IsTrue(controllerCanIdentifyNonMainThread.Result);
        }
        public void OnCommandEnabledOrDisabledNotCalledWhenAddingACommand()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), true);
            Assert.IsFalse(executionContext.CommandsEnabledOrDisabledWasReported);
        }
コード例 #5
0
        public async Task CanReportImportantMessage()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);
            var feedback         = await CreateFeedbackAndReportAsync(executionContext, FeedbackType.ImportantMessage, ImportantTestMessage);

            Assert.AreEqual(1, executionContext.FeedbacksToApplication.Count);
            Assert.IsTrue(IsFeedbackEqualToRecordedFeedback(executionContext, feedback, 0));
        }
        public async Task OnCommandEnabledOrDisabledIsCalledWhenDisablingACommand()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), true);
            await executionContext.Controller.DisableCommandAsync(typeof(PrimeNumbersCommand));

            Assert.IsTrue(executionContext.CommandsEnabledOrDisabledWasReported);
        }
コード例 #7
0
        internal async Task <FeedbackToApplication> CreateFeedbackAndReportAsync(ApplicationCommandControllerTestExecutionContext context, FeedbackType type, string message)
        {
            var feedback = new FeedbackToApplication()
            {
                Type = type, Message = message
            };
            await context.ExecutionContext.ReportAsync(feedback);

            return(feedback);
        }
コード例 #8
0
        public async Task WhenCommandCanBeReDisabled()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), false);
            await executionContext.Controller.EnableCommandAsync(typeof(PrimeNumbersCommand));

            await executionContext.Controller.DisableCommandAsync(typeof(PrimeNumbersCommand));

            Assert.IsFalse(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand)));
        }
コード例 #9
0
        public async Task CanReportTwoMessagesWithDifferentImportance()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);
            var feedback         = await CreateFeedbackAndReportAsync(executionContext, FeedbackType.ImportantMessage, ImportantTestMessage);

            var anotherFeedback = await CreateFeedbackAndReportAsync(executionContext, FeedbackType.MessageOfNoImportance, TestMessageOfNoImportance);

            Assert.AreEqual(2, executionContext.FeedbacksToApplication.Count);
            Assert.IsTrue(IsFeedbackEqualToRecordedFeedback(executionContext, feedback, 0));
            Assert.IsTrue(IsFeedbackEqualToRecordedFeedback(executionContext, anotherFeedback, 1));
        }
コード例 #10
0
        public async Task SomethingThatIsNotACommandCanBeExecutedButNotCompleted()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            Assert.IsFalse(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.CommandExecutionCompleted));
            Assert.IsFalse(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.UnknownCommand));
            await executionContext.Controller.ExecuteAsync(GetType());

            Assert.IsFalse(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.CommandExecutionCompleted));
            Assert.IsTrue(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.UnknownCommand));
        }
コード例 #11
0
        public async Task AddedDisabledCommandCanBeExecuted()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), false);
            Assert.IsFalse(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.CommandExecutionCompleted));
            Assert.IsFalse(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.CommandIsDisabled));
            await executionContext.Controller.ExecuteAsync(typeof(PrimeNumbersCommand));

            Assert.IsTrue(executionContext.FeedbacksToApplication.Any(x => x.Type == FeedbackType.CommandIsDisabled));
        }
コード例 #12
0
        public async Task DefaultEnabledCommandIsDisabledWhileExecuting()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);
            var command          = new FakeCommand(true, executionContext.Controller);

            Assert.IsFalse(command.WasExecuted);
            executionContext.Controller.AddCommand(command, true);
            Assert.IsTrue(await executionContext.Controller.EnabledAsync(typeof(FakeCommand)));
            await executionContext.Controller.ExecuteAsync(typeof(FakeCommand));

            Assert.IsTrue(command.WasExecuted);
            Assert.IsTrue(await executionContext.Controller.EnabledAsync(typeof(FakeCommand)));
        }
        public async Task ThenCommandCanBeDisabledViaFeedback()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            executionContext.Controller.AddCommand(new PrimeNumbersCommand(), true);
            Assert.IsTrue(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand)));
            var feedback = new FeedbackToApplication()
            {
                Type = FeedbackType.DisableCommand, CommandType = typeof(PrimeNumbersCommand)
            };
            await executionContext.ExecutionContext.ReportAsync(feedback);

            Assert.IsFalse(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand)));
        }
コード例 #14
0
        public void CanIdentifyMainThread()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            Assert.IsTrue(executionContext.Controller.IsMainThread());
        }
コード例 #15
0
 internal bool IsFeedbackEqualToRecordedFeedback(ApplicationCommandControllerTestExecutionContext context, IFeedbackToApplication feedback, int i)
 {
     return(feedback.Type == context.FeedbacksToApplication[i].Type &&
            feedback.Message == context.FeedbacksToApplication[i].Message &&
            feedback.CommandType == context.FeedbacksToApplication[i].CommandType);
 }
        public async Task CommandIsNotEnabledForNewController()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            Assert.IsFalse(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand)));
        }
        public void OnCommandEnabledOrDisabledNotCalledInitially()
        {
            var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger);

            Assert.IsFalse(executionContext.CommandsEnabledOrDisabledWasReported);
        }