public void DiscoverCommandFromAssemblyContainsCorrectTypes() { var cmdDiscovery = new CommandDiscoverer(); var resultTypes = cmdDiscovery.DiscoverCommandTypes(typeof(SomeBaseType), new[] { Assembly.GetExecutingAssembly() }); var invalidAbstractCommand = typeof(AbstractCommand); var wrongGenericTypeCommand = typeof(WrongGenericTypeCommand); var validCommand = typeof(ValidCommand); var validCommand2 = typeof(ValidCommand2); Assert.DoesNotContain(invalidAbstractCommand, resultTypes); Assert.DoesNotContain(wrongGenericTypeCommand, resultTypes); Assert.Contains(validCommand, resultTypes); Assert.Contains(validCommand2, resultTypes); }
static void Main(string[] args) { var context = new Context(); context.VariableManager = new VariableManager(); context.VariableManager.Set("now.date", () => DateTime.Now.Date.ToString("dd-MMM-yyyy")); context.VariableManager.Set("now.time", () => DateTime.Now.ToString("HH:mm")); context.CmdManager = new CommandManager(context); var commands = CommandDiscoverer.Discover(Directory.GetCurrentDirectory()); commands.ForEach(c => c.CommandManager = context.CmdManager); context.CmdManager.KnownCommands = new List <ICommand>(commands); context.AvailableCardServices = LoadCardServices("CardServicesConfig.json"); PrintIntro(); do { Console.Write((context.CardService != null ? context.CardService.Id : "(/!\\ no card source set /!\\)") + " :: "); var cmdLine = Console.ReadLine(); try { var result = context.CmdManager.ExecuteFromString(cmdLine); if (!result.IsSuccessful) { Console.WriteLine($"Command failed: {result.UserMessage}"); result.Errors.ForEach(e => Console.WriteLine($"error - {e.Message}")); } else { Console.WriteLine(result.UserMessage); } } catch (Exception ex) { Console.WriteLine($"Command crashed! {ex.Message} - {ex.GetType()}"); _logger.Warn("Command crashed", ex); } } while (true); }