public static IEnumerable <object[]> CreateTestData()
        {
            var moduleIdentity = new Mock <IModuleIdentity>();
            var testModule     = new ModuleWithIdentity(TestModule, moduleIdentity.Object);
            var updateModule   = new ModuleWithIdentity(UpdateModule, moduleIdentity.Object);
            var runtimeInfo    = Mock.Of <IRuntimeInfo>();

            // CommandMethodBeingTested - factory command under test
            // Command - command object to be mocked.
            // TestExpr - the expression to execute test.
            (CommandMethodExpr CommandMethodBeingTested, Task <ICommand> Command, TestExecutionExpr TestExpr)[] testInputRecords =
Example #2
0
        async Task <IEnumerable <ICommand> > ProcessAddedUpdatedModules(
            IList <IModule> modules,
            IImmutableDictionary <string, IModuleIdentity> moduleIdentities,
            Func <IModuleWithIdentity, Task <ICommand> > createUpdateCommandMaker
            )
        {
            // new modules become a command group containing:
            //   create followed by a start command if the desired
            //   status is "running"
            var addedTasks = new List <Task <ICommand[]> >();

            foreach (IModule module in modules)
            {
                if (moduleIdentities.TryGetValue(module.Name, out IModuleIdentity moduleIdentity))
                {
                    var tasks = new List <Task <ICommand> >();
                    var moduleWithIdentity = new ModuleWithIdentity(module, moduleIdentity);
                    tasks.Add(createUpdateCommandMaker(moduleWithIdentity));
                    if (module.DesiredStatus == ModuleStatus.Running)
                    {
                        tasks.Add(this.commandFactory.StartAsync(module));
                    }

                    addedTasks.Add(Task.WhenAll(tasks));
                }
                else
                {
                    Events.UnableToProcessModule(module);
                }
            }

            // build GroupCommands from each command set
            IEnumerable <Task <ICommand> > commands = (await Task.WhenAll(addedTasks))
                                                      .Select(cmds => this.commandFactory.WrapAsync(new GroupCommand(cmds)));

            return(await Task.WhenAll(commands));
        }