示例#1
0
        public async Task TestCommandExceptions_SwallowExceptionsAsync()
        {
            var taskCommand = new TaskCommand(TestExecuteWithExceptionAsync)
            {
                SwallowExceptions = true
            };

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            try
            {
                taskCommand.Execute();

                Assert.IsTrue(taskCommand.IsExecuting);

                await taskCommand.Task;
            }
            catch (Exception ex)
            {
                Assert.Fail($"No exception expected, should be swallowed, but got '{ex}'");
            }

            Assert.IsFalse(taskCommand.IsExecuting);
        }
示例#2
0
        public void Task_Execute_ReturnsEmpty()
        {
            var command       = new TaskCommand(_console, LoggerMock.GetLogger <TaskCommand>().Object);
            var resultMessage = command.Execute();

            Assert.Equal("", resultMessage);
        }
        /*********** FONCTION EFFECTUE ¨PAR LES THREADS ASYNCRONE *******/
        public async void Work()
        {
            /// Console.WriteLine(queue.Count + "= TAILLE INITIALE" );
            while (true)
            {
                while (queue.Count >= 1)
                {
                    if (this.threads.First().Equals(Thread.CurrentThread))
                    {
                        TaskCommand taskTemplate = (TaskCommand)queue.First();

                        try
                        {
                            this.RemoveTask(taskTemplate);
                            Console.WriteLine(String.Concat(" ********* Executed by ", Thread.CurrentThread.Name));
                            taskTemplate.Execute();
                            await _semaphoreSlim.WaitAsync();
                        }

                        finally
                        {
                            _semaphoreSlim.Release();
                            Thread currentThread = threads.First();
                            threads.Remove(currentThread);

                            Thread.Sleep(500);
                            threads.Add(currentThread);
                        }
                    }
                }
            }
        }
示例#4
0
        public async Task TestCommandExceptions_DontSwallowExceptionsAsync()
        {
            var taskCommand = new TaskCommand(TestExecuteWithExceptionAsync)
            {
                SwallowExceptions = false
            };

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            try
            {
                taskCommand.Execute();

                Assert.IsTrue(taskCommand.IsExecuting);

                await taskCommand.Task;

                Assert.Fail("Expected exception");
            }
            catch (Exception)
            {
            }

            Assert.IsFalse(taskCommand.IsExecuting);
        }
示例#5
0
        public async Task TestCommandCancellation()
        {
            var taskCommand = new TaskCommand(TestExecute);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            taskCommand.Execute();

            Assert.IsTrue(taskCommand.IsExecuting);
            await Task.Delay(TimeSpan.FromSeconds(1));

            taskCommand.Cancel();

            await Task.Delay(TimeSpan.FromSeconds(1));
            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);
        }
示例#6
0
        public async Task TestCommandCancellation()
        {
            var taskCommand = new TaskCommand(TestExecute);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            taskCommand.Execute();

            Assert.IsTrue(taskCommand.IsExecuting);
            await Task.Delay(TimeSpan.FromSeconds(1));

            taskCommand.Cancel();

            await Task.Delay(TimeSpan.FromSeconds(1));

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);
        }
示例#7
0
        public void TestCommandCancellation()
        {
            var taskCommand = new TaskCommand(TestExecuteAsync);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            taskCommand.Execute();

            Assert.IsTrue(taskCommand.IsExecuting);

            ThreadHelper.Sleep(1000);

            taskCommand.Cancel();

            ThreadHelper.Sleep(1000);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);
        }
示例#8
0
        public void TestCommandCancellation()
        {
            var taskCommand = new TaskCommand(TestExecuteAsync);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);

            taskCommand.Execute();

            Assert.IsTrue(taskCommand.IsExecuting);

            ThreadHelper.Sleep(1000);

            taskCommand.Cancel();

            ThreadHelper.Sleep(1000);

            Assert.IsFalse(taskCommand.IsExecuting);
            Assert.IsFalse(taskCommand.IsCancellationRequested);
        }
示例#9
0
 public void setTask(TaskCommand task)
 {
     this.task = task;
     task.Execute();
 }