예제 #1
0
        public async Task ExecuteCommandAsync_When_Always_Then_ExecuteCorrectCommand(
            string argsC,
            bool hasCatchAll,
            string invokedCmd,

            ICommandDefinition catchAllCmd,
            IList <ICommandDefinition> defs,
            IServiceProvider sp)
        {
            // -- arrange
            string executedAction = null;
            var    args           = argsC?.Split(" ");

            catchAllCmd.Name.Returns("catch");
            defs.First().Name.Returns("child");
            var sut = new CompositeCommandDefinition("sut", defs, hasCatchAll ? catchAllCmd : null);

            defs.ToList().ForEach(c => c.WhenForAnyArgs(async a => await a.ExecuteCommandAsync(null, null)).Do(a => executedAction = c.Name));
            catchAllCmd.WhenForAnyArgs(async a => await a.ExecuteCommandAsync(null, null)).Do(a => executedAction = catchAllCmd.Name);


            // -- act
            await sut.ExecuteCommandAsync(sp, args);


            // -- assert
            Assert.Equal(invokedCmd, executedAction);
        }
예제 #2
0
        public async Task ExecuteCommandAsync_When_NoArgsAndCatchAll_Then_ThrowInvalidCommand(string argsC)
        {
            // -- arrange
            var args     = argsC?.Split(" ");
            var defs     = new ICommandDefinition[] { };
            var catchAll = (ICommandDefinition)null;
            var sut      = new CompositeCommandDefinition("sut", defs, catchAll);

            // -- act
            Func <Task> action = () => sut.ExecuteCommandAsync(null, args);


            // -- assert
            await Assert.ThrowsAsync <InvalidCommandException>(action);
        }