예제 #1
0
        public void CanCreateContextInstance()
        {
            var context = new TestContext();

            context.Set("test", "test");

            context.ShouldNotBeNull();
            context.Get <string>("test").ShouldBe("test");
            context.Get <int>("doesnotexist").ShouldBe(0);
        }
예제 #2
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));
        }
예제 #3
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());
        }
예제 #4
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");
        }
예제 #5
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));
        }
예제 #6
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");
        }
예제 #7
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");
        }
예제 #8
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));
        }
예제 #9
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");
        }
예제 #10
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");
        }
예제 #11
0
        public void Missing_context_key_raises_exception()
        {
            var context = new TestContext();

            Should.Throw <MissingExpectedContextDataException>(() => context.Get <string>("test", true));
        }