/// <summary>
        /// Configure synchronous cancellation for the given command
        /// </summary>
        public static CommandBuilderContext <TArgument> WithCancellation <TArgument>(this CommandBuilderContext <TArgument> context)
        {
            ValdiateContextForNull(context);

            context.CancelCommand = new CancelCommand(context.CommandManager);
            return(context);
        }
예제 #2
0
        public void Build_ShouldThrowForNullBusyStack()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            Assert.Throws <ArgumentNullException>(() => context.WithBusyNotification(null));
        }
예제 #3
0
        public void Ctor_ShouldInitializeDependencyProperties()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            Assert.IsNotNull(context.CommandManager);
            Assert.AreEqual(commandManager, context.CommandManager);
        }
예제 #4
0
        public void Build_ShouldCreateValidCommandInstance()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            var command = context.Build();

            Assert.IsNotNull(command);
        }
예제 #5
0
        public void Ctor_ShouldNotInitializeAllProperties()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            // should not be initialized by default, since they represent optional features
            Assert.IsNull(context.BusyStack);
            Assert.IsNull(context.CancelCommand);
        }
예제 #6
0
        public void Build_ShouldAddSingleExecutionDecorator()
        {
            var commandManager = Utils.GetTestCommandManager();
            var command        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute)
                                 .WithSingleExecution()
                                 .Build();

            Assert.IsInstanceOf <SequentialAsyncCommandDecorator>(command);
        }
예제 #7
0
        public void Build_ShouldAddCancellationSupport()
        {
            var commandManager = Utils.GetTestCommandManager();
            var command        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute)
                                 .WithCancellation()
                                 .Build();

            Assert.IsNotNull(command.CancelCommand);
            Assert.IsInstanceOf <CancelCommand>(command.CancelCommand);
        }
예제 #8
0
        public void Build_ShouldAssignBusyStack()
        {
            var commandManager  = Utils.GetTestCommandManager();
            var customBusyStack = NSubstitute.Substitute.For <IBusyStack>();
            var context         = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            context.WithBusyNotification(customBusyStack);

            Assert.IsInstanceOf <IBusyStack>(context.BusyStack);
        }
예제 #9
0
        public void Build_ShouldCreateDefaultCommandInstance()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            var command = context.Build();

            Assert.IsNotNull(command.CancelCommand);
            Assert.IsInstanceOf <NoCancellationCommand>(command.CancelCommand);
            Assert.AreEqual(command.IsBusy, false);
            Assert.AreEqual(command.Completion, Task.CompletedTask);
        }
예제 #10
0
        public void Build_ShouldCallAllDecorators()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            var count          = 0;
            var decoratorCount = 20;

            for (var i = 0; i < decoratorCount; i++)
            {
                context.AddDecorator(DecoratorFactory);
            }

            var command = context.Build();

            Assert.AreEqual(decoratorCount, count);

            ConcurrentCommandBase DecoratorFactory(ConcurrentCommandBase command)
            {
                count++;
                return(command);
            }
        }
예제 #11
0
        public void Build_ShouldAddAllDecoratorsInCorrectOrder()
        {
            var commandManager = Utils.GetTestCommandManager();
            var context        = new CommandBuilderContext <object>(commandManager, Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);

            var count          = 0;
            var decoratorCount = 3;

            context.AddDecorator(DecoratorFactory1);
            context.AddDecorator(DecoratorFactory2);
            context.AddDecorator(DecoratorFactory3);

            var command = context.Build();

            Assert.AreEqual(decoratorCount, count);

            ConcurrentCommandBase DecoratorFactory1(ConcurrentCommandBase command)
            {
                Assert.AreEqual(0, count);
                count++;
                return(command);
            }

            ConcurrentCommandBase DecoratorFactory2(ConcurrentCommandBase command)
            {
                Assert.AreEqual(1, count);
                count++;
                return(command);
            }

            ConcurrentCommandBase DecoratorFactory3(ConcurrentCommandBase command)
            {
                Assert.AreEqual(2, count);
                count++;
                return(command);
            }
        }
 /// <summary>
 /// Provide a custom implementation of <see cref="ICancelCommand"/>
 /// </summary>
 /// <exception cref="ArgumentNullException"></exception>
 public static CommandBuilderContext <TArgument> WithCustomCancellation <TArgument>(this CommandBuilderContext <TArgument> context, in ICancelCommand cancelCommand)
        /// <summary>
        /// Configure task based cancellation for the given command
        /// </summary>
        public static CommandBuilderContext <TArgument> WithAsyncCancellation <TArgument>(this CommandBuilderContext <TArgument> context)
        {
            ValdiateContextForNull(context);

            context.CancelCommand = new ConcurrentCancelCommand(context.CommandManager, context.ExceptionHandler);
            return(context);
        }
예제 #14
0
 public void Ctor_DoesntThrow()
 {
     var _ = new CommandBuilderContext <object>(Utils.GetTestCommandManager(), Utils.GetTestExceptionHandler(), Utils.TestBusyStackFactory, Utils.TestExecute, Utils.TestCanExecute);
 }