示例#1
0
        public async Task Command_can_cancel_sequential_execution()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", delay : 50));

            await conveyor.Register(new TestCancellingCommand(cts, runResult : "B", delay : 30));

            await conveyor.Register(new TestCommand(runResult : "C", delay : 10));

            Should.Throw <TaskCanceledException>(async() => await conveyor.Run(false));
        }
示例#2
0
        public async Task Command_can_cancel_sequential_execution()
        {
            var cts    = new CancellationTokenSource();
            var logger = _loggerFactory.CreateLogger(typeof(TestConveyor));

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, logger, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", delay : 50, logger : logger));

            await conveyor.Register(new TestCancellingCommand(cts, runResult : "B", delay : 30, logger : logger));

            await conveyor.Register(new TestCommand(runResult : "C", delay : 10, logger : logger));

            Should.Throw <TaskCanceledException>(async() => await conveyor.Run());
        }
示例#3
0
        public async Task Command_can_cancel_parallel_execution()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", delay : 200));

            await conveyor.Register(new TestCancellingCommand(cts, runResult : "B", delay : 150));

            await conveyor.Register(new TestCommand(runResult : "C", delay : 100));

            Should.Throw <TaskCanceledException>(async() => await conveyor.Run(true));
            conveyor.Context.TestResult.ToString().ShouldBe("C");
        }
示例#4
0
        public async Task Conveyor_can_be_cancelled_with_token()
        {
            var cts    = new CancellationTokenSource(20);
            var logger = _loggerFactory.CreateLogger(typeof(TestConveyor));

            var context = new TestContext {
                TestTimeout = 50
            };
            var command  = new TestCommand(150);
            var command2 = new TestCommand(150);
            var conveyor = new TestConveyor(context, logger, cts.Token);

            await conveyor.Register(command);

            await conveyor.Register(command2);

            Should.Throw <TaskCanceledException>(async() => await conveyor.Run(true));
        }
示例#5
0
        public async Task Can_Execute_InParallel()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", delay : 660));

            await conveyor.Register(new TestCommand(runResult : "B", delay : 435));

            await conveyor.Register(new TestCommand(runResult : "C", delay : 110));

            await conveyor.Run(true);

            //context.Get<Guid>("Identifier").ShouldBe(context.Identifier);
            context.TestResult.ToString().ShouldBe("CBA");
        }
示例#6
0
        public async Task Can_execute_conveyor_belt()
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A"));

            await conveyor.Register(new TestCommand(runResult : "B"));

            await conveyor.Register(new TestCommand(runResult : "C"));

            await conveyor.Run();

            context.Get <Guid>("Identifier").ShouldBe(context.Identifier);
            context.TestResult.ToString().ShouldBe("ABC");
        }
示例#7
0
        public async Task Conveyor_can_be_cancelled_with_token()
        {
            CancellationTokenSource cts = new CancellationTokenSource(20);

            var context = new TestContext()
            {
                TestTimeout = 50
            };
            var command  = new TestCommand(delay: 150);
            var command2 = new TestCommand(delay: 150);
            var conveyor = new TestConveyor(context, cts.Token);

            await conveyor.Register(command);

            await conveyor.Register(command2);

            Should.Throw <TaskCanceledException>(async() => await conveyor.Run(true));
        }
示例#8
0
        public async Task Can_Execute_InParallel()
        {
            var cts    = new CancellationTokenSource();
            var logger = _loggerFactory.CreateLogger(typeof(TestConveyor));

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, logger, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", delay : 660, logger : logger));

            await conveyor.Register(new TestCommand(runResult : "B", delay : 435, logger : logger));

            await conveyor.Register(new TestCommand(runResult : "C", delay : 110, logger : logger));

            await conveyor.Run(true);

            //context.Get<Guid>("Identifier").ShouldBe(context.Identifier);
            context.TestResult.ToString().ShouldBe("CBA");
        }
示例#9
0
        public async Task Can_execute_conveyor_belt()
        {
            var cts    = new CancellationTokenSource();
            var logger = _loggerFactory.CreateLogger(typeof(TestConveyor));

            var context  = new TestContext();
            var conveyor = new TestConveyor(context, logger, cts.Token);

            await conveyor.Register(new TestCommand(runResult : "A", logger : logger));

            await conveyor.Register(new TestCommand(runResult : "B", logger : logger));

            await conveyor.Register(new TestCommand(runResult : "C", logger : logger));

            await conveyor.Run();

            context.Get <Guid>("Identifier").ShouldBe(context.Identifier);
            context.TestResult.ToString().ShouldBe("ABC");
        }