public async Task ThenCommandIsEnabled() { var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger); executionContext.Controller.AddCommand(new PrimeNumbersCommand(), true); Assert.IsTrue(await executionContext.Controller.EnabledAsync(typeof(PrimeNumbersCommand))); }
internal async Task <bool> ControllerCanIdentifyNonMainThread(ApplicationCommandControllerTestExecutionContext context) { var notMainThread = false; await Task.Run(() => { notMainThread = !context.Controller.IsMainThread(); }); return(notMainThread); }
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); }
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); }
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); }
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))); }
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)); }
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)); }
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)); }
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))); }
public void CanIdentifyMainThread() { var executionContext = new ApplicationCommandControllerTestExecutionContext(SimpleLogger); Assert.IsTrue(executionContext.Controller.IsMainThread()); }
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); }